@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.
@@ -0,0 +1,427 @@
1
+ import { E as ExtractorOptions, a as Extractor, b as ExtractOptions, c as ExtractResult, C as CacheStats, d as CacheOptions, e as ContentPriority, P as PackageInfo, f as PackageMetadata } from './kernel-I4Zn2uXv.cjs';
2
+ export { u as AIProvider, A as AIProviderName, k as AIProviderOptions, l as AITask, o as APIEntry, m as APIEntryKind, q as ChangelogEntry, t as CompletionOptions, j as EventHandler, s as ExtractorContext, J as JSDocParsed, K as Kernel, O as OutputFormat, n as ParamDoc, r as ParsedChangelog, p as ParsedReadme, g as Plugin, h as PluginCategory, i as PluginInfo, R as ReturnDoc, T as TarEntry, v as TarHeader, y as composePlugins, w as createKernel, x as definePlugin } from './kernel-I4Zn2uXv.cjs';
3
+
4
+ /**
5
+ * Custom error classes for @oxog/npm-llms
6
+ * @module errors
7
+ */
8
+ /**
9
+ * Base error class for npm-llms
10
+ * @example
11
+ * ```typescript
12
+ * try {
13
+ * await extractor.extract('nonexistent-package');
14
+ * } catch (error) {
15
+ * if (error instanceof NpmLlmsError) {
16
+ * console.log(error.code); // 'PACKAGE_NOT_FOUND'
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ declare class NpmLlmsError extends Error {
22
+ readonly code: string;
23
+ readonly details?: Record<string, unknown> | undefined;
24
+ /**
25
+ * Create a new NpmLlmsError
26
+ * @param message - Error message
27
+ * @param code - Error code
28
+ * @param details - Additional error details
29
+ */
30
+ constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
31
+ /**
32
+ * Convert error to JSON
33
+ */
34
+ toJSON(): Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Error thrown when a package is not found on npm
38
+ * @example
39
+ * ```typescript
40
+ * throw new PackageNotFoundError('nonexistent-package');
41
+ * // Error: Package "nonexistent-package" not found on npm
42
+ * ```
43
+ */
44
+ declare class PackageNotFoundError extends NpmLlmsError {
45
+ constructor(packageName: string);
46
+ }
47
+ /**
48
+ * Error thrown when a specific version is not found
49
+ * @example
50
+ * ```typescript
51
+ * throw new VersionNotFoundError('lodash', '99.99.99');
52
+ * // Error: Version "99.99.99" not found for package "lodash"
53
+ * ```
54
+ */
55
+ declare class VersionNotFoundError extends NpmLlmsError {
56
+ constructor(packageName: string, version: string);
57
+ }
58
+ /**
59
+ * Error thrown when a download fails
60
+ * @example
61
+ * ```typescript
62
+ * throw new DownloadError('Network timeout', 'https://registry.npmjs.org/...');
63
+ * ```
64
+ */
65
+ declare class DownloadError extends NpmLlmsError {
66
+ constructor(message: string, url?: string);
67
+ }
68
+ /**
69
+ * Error thrown when parsing fails
70
+ * @example
71
+ * ```typescript
72
+ * throw new ParseError('Invalid TypeScript syntax', 'index.d.ts');
73
+ * ```
74
+ */
75
+ declare class ParseError extends NpmLlmsError {
76
+ constructor(message: string, file?: string, position?: {
77
+ line: number;
78
+ column: number;
79
+ });
80
+ }
81
+ /**
82
+ * Error thrown when AI provider fails
83
+ * @example
84
+ * ```typescript
85
+ * throw new AIError('Rate limit exceeded', 'claude');
86
+ * ```
87
+ */
88
+ declare class AIError extends NpmLlmsError {
89
+ constructor(message: string, provider?: string);
90
+ }
91
+ /**
92
+ * Error thrown when a plugin fails
93
+ * @example
94
+ * ```typescript
95
+ * throw new PluginError('Plugin "custom-parser" failed to initialize', 'custom-parser');
96
+ * ```
97
+ */
98
+ declare class PluginError extends NpmLlmsError {
99
+ constructor(message: string, pluginName?: string);
100
+ }
101
+ /**
102
+ * Error thrown when cache operation fails
103
+ * @example
104
+ * ```typescript
105
+ * throw new CacheError('Failed to write to cache directory');
106
+ * ```
107
+ */
108
+ declare class CacheError extends NpmLlmsError {
109
+ constructor(message: string);
110
+ }
111
+ /**
112
+ * Error thrown when configuration is invalid
113
+ * @example
114
+ * ```typescript
115
+ * throw new ConfigError('Invalid AI provider: "invalid"');
116
+ * ```
117
+ */
118
+ declare class ConfigError extends NpmLlmsError {
119
+ constructor(message: string);
120
+ }
121
+ /**
122
+ * Error thrown when tar extraction fails
123
+ * @example
124
+ * ```typescript
125
+ * throw new TarError('Invalid tar header at offset 512');
126
+ * ```
127
+ */
128
+ declare class TarError extends NpmLlmsError {
129
+ constructor(message: string, offset?: number);
130
+ }
131
+ /**
132
+ * Error thrown when a network request times out
133
+ * @example
134
+ * ```typescript
135
+ * throw new TimeoutError('Request timed out after 30000ms', 30000);
136
+ * ```
137
+ */
138
+ declare class TimeoutError extends NpmLlmsError {
139
+ constructor(message: string, timeout?: number);
140
+ }
141
+ /**
142
+ * Error thrown when validation fails
143
+ * @example
144
+ * ```typescript
145
+ * throw new ValidationError('Package name cannot be empty');
146
+ * ```
147
+ */
148
+ declare class ValidationError extends NpmLlmsError {
149
+ constructor(message: string, field?: string);
150
+ }
151
+ /**
152
+ * Check if an error is a NpmLlmsError
153
+ * @param error - Error to check
154
+ * @returns True if error is a NpmLlmsError
155
+ * @example
156
+ * ```typescript
157
+ * if (isNpmLlmsError(error)) {
158
+ * console.log(error.code);
159
+ * }
160
+ * ```
161
+ */
162
+ declare function isNpmLlmsError(error: unknown): error is NpmLlmsError;
163
+ /**
164
+ * Get error code from any error
165
+ * @param error - Error to get code from
166
+ * @returns Error code or 'UNKNOWN_ERROR'
167
+ * @example
168
+ * ```typescript
169
+ * const code = getErrorCode(error); // 'PACKAGE_NOT_FOUND' or 'UNKNOWN_ERROR'
170
+ * ```
171
+ */
172
+ declare function getErrorCode(error: unknown): string;
173
+ /**
174
+ * Wrap any error as NpmLlmsError
175
+ * @param error - Error to wrap
176
+ * @param code - Error code to use
177
+ * @returns NpmLlmsError
178
+ * @example
179
+ * ```typescript
180
+ * try {
181
+ * await someOperation();
182
+ * } catch (error) {
183
+ * throw wrapError(error, 'OPERATION_FAILED');
184
+ * }
185
+ * ```
186
+ */
187
+ declare function wrapError(error: unknown, code?: string): NpmLlmsError;
188
+
189
+ /**
190
+ * Main extractor implementation
191
+ * Ties together fetching, parsing, and output generation
192
+ * @module core/extractor
193
+ */
194
+
195
+ /**
196
+ * Create a new extractor instance
197
+ * @param options - Extractor configuration options
198
+ * @returns Extractor instance
199
+ * @example
200
+ * ```typescript
201
+ * const extractor = createExtractor();
202
+ * const result = await extractor.extract('lodash@4.17.21');
203
+ * console.log(result.outputs.llms);
204
+ * ```
205
+ */
206
+ declare function createExtractor(options?: ExtractorOptions): Extractor;
207
+ /**
208
+ * Quick extract function for simple use cases
209
+ * @param packageSpec - Package specifier
210
+ * @param options - Extract options
211
+ * @returns Extract result
212
+ * @example
213
+ * ```typescript
214
+ * const result = await extract('lodash');
215
+ * console.log(result.outputs.llms);
216
+ * ```
217
+ */
218
+ declare function extract(packageSpec: string, options?: ExtractOptions): Promise<ExtractResult>;
219
+
220
+ /**
221
+ * File-based cache with TTL support
222
+ * Caches package data and AI responses to reduce API calls
223
+ * @module core/cache
224
+ */
225
+
226
+ /**
227
+ * File-based cache implementation
228
+ * @example
229
+ * ```typescript
230
+ * const cache = new FileCache('.cache', 3600000); // 1 hour TTL
231
+ *
232
+ * // Get cached data
233
+ * const data = await cache.get<MyData>('my-key');
234
+ *
235
+ * // Set cached data
236
+ * await cache.set('my-key', myData);
237
+ *
238
+ * // Clear cache
239
+ * await cache.clear();
240
+ * ```
241
+ */
242
+ declare class FileCache {
243
+ private readonly dir;
244
+ private readonly defaultTtl;
245
+ /**
246
+ * Create a new FileCache
247
+ * @param dir - Cache directory path
248
+ * @param defaultTtl - Default TTL in milliseconds
249
+ */
250
+ constructor(dir?: string, defaultTtl?: number);
251
+ /**
252
+ * Generate a cache key hash
253
+ * @param input - Input string
254
+ * @returns Hashed key
255
+ */
256
+ private getKey;
257
+ /**
258
+ * Get file path for a cache key
259
+ * @param key - Cache key
260
+ * @returns File path
261
+ */
262
+ private getPath;
263
+ /**
264
+ * Get cached data
265
+ * @param key - Cache key
266
+ * @returns Cached data or null if not found/expired
267
+ */
268
+ get<T>(key: string): Promise<T | null>;
269
+ /**
270
+ * Set cached data
271
+ * @param key - Cache key
272
+ * @param data - Data to cache
273
+ * @param ttl - Optional TTL override
274
+ */
275
+ set<T>(key: string, data: T, ttl?: number): Promise<void>;
276
+ /**
277
+ * Delete a cached entry
278
+ * @param key - Cache key
279
+ * @returns True if deleted, false if not found
280
+ */
281
+ delete(key: string): Promise<boolean>;
282
+ /**
283
+ * Check if a key is cached and not expired
284
+ * @param key - Cache key
285
+ * @returns True if cached and valid
286
+ */
287
+ has(key: string): Promise<boolean>;
288
+ /**
289
+ * Clear all cached data
290
+ */
291
+ clear(): Promise<void>;
292
+ /**
293
+ * Remove expired entries
294
+ * @returns Number of entries removed
295
+ */
296
+ prune(): Promise<number>;
297
+ /**
298
+ * Get cache statistics
299
+ * @returns Cache stats
300
+ */
301
+ getStats(): Promise<CacheStats>;
302
+ /**
303
+ * Get cache directory path
304
+ */
305
+ getDir(): string;
306
+ /**
307
+ * Get default TTL
308
+ */
309
+ getDefaultTtl(): number;
310
+ }
311
+ /**
312
+ * Create a file cache from options
313
+ * @param options - Cache options
314
+ * @returns FileCache instance or null if disabled
315
+ */
316
+ declare function createCache(options?: CacheOptions): FileCache | null;
317
+ /**
318
+ * Format bytes for display
319
+ * @param bytes - Byte count
320
+ * @returns Formatted string
321
+ */
322
+ declare function formatBytes(bytes: number): string;
323
+
324
+ /**
325
+ * Token counting and truncation utilities
326
+ * Approximates GPT-4/Claude tokenization for content budgeting
327
+ * @module core/tokens
328
+ */
329
+
330
+ /**
331
+ * Count approximate tokens in text
332
+ * Uses character-based heuristic optimized for LLM tokenization
333
+ * @param text - Text to count tokens in
334
+ * @returns Approximate token count
335
+ * @example
336
+ * ```typescript
337
+ * const tokens = countTokens("Hello, world!");
338
+ * console.log(tokens); // ~4
339
+ * ```
340
+ */
341
+ declare function countTokens(text: string): number;
342
+ /**
343
+ * Truncation result
344
+ */
345
+ interface TruncateResult {
346
+ /** Truncated text */
347
+ text: string;
348
+ /** Whether truncation occurred */
349
+ truncated: boolean;
350
+ /** Actual token count */
351
+ tokenCount: number;
352
+ /** Sections included */
353
+ includedSections: string[];
354
+ /** Sections removed */
355
+ removedSections: string[];
356
+ }
357
+ /**
358
+ * Truncate text to fit within token limit while preserving structure
359
+ * @param text - Text to truncate
360
+ * @param limit - Token limit
361
+ * @param priorities - Priority order for content
362
+ * @returns Truncated text and metadata
363
+ * @example
364
+ * ```typescript
365
+ * const result = truncateToTokenLimit(content, 2000);
366
+ * if (result.truncated) {
367
+ * console.log(`Removed: ${result.removedSections.join(', ')}`);
368
+ * }
369
+ * ```
370
+ */
371
+ declare function truncateToTokenLimit(text: string, limit: number, priorities?: ContentPriority[]): TruncateResult;
372
+ /**
373
+ * Format token count for display
374
+ * @param tokens - Token count
375
+ * @returns Formatted string
376
+ */
377
+ declare function formatTokenCount(tokens: number): string;
378
+
379
+ /**
380
+ * NPM package fetcher
381
+ * Downloads and extracts packages from the NPM registry
382
+ * @module core/fetcher
383
+ */
384
+
385
+ /**
386
+ * Validate package name format
387
+ * @param name - Package name to validate
388
+ * @throws ValidationError if invalid
389
+ */
390
+ declare function validatePackageName(name: string): void;
391
+ /**
392
+ * Parse package specifier (name@version)
393
+ * @param spec - Package specifier (e.g., "lodash", "lodash@4.17.21", "@scope/pkg@1.0.0")
394
+ * @returns Parsed name and version
395
+ */
396
+ declare function parsePackageSpec(spec: string): {
397
+ name: string;
398
+ version?: string;
399
+ };
400
+ /**
401
+ * Fetcher options
402
+ */
403
+ interface FetcherOptions {
404
+ /** NPM registry URL */
405
+ registry?: string;
406
+ /** Request timeout in milliseconds */
407
+ timeout?: number;
408
+ }
409
+ /**
410
+ * Fetch package metadata from NPM registry
411
+ * @param name - Package name
412
+ * @param version - Optional version
413
+ * @param options - Fetcher options
414
+ * @returns Package metadata
415
+ * @throws PackageNotFoundError if package not found
416
+ * @throws VersionNotFoundError if version not found
417
+ */
418
+ declare function fetchPackageMetadata(name: string, version?: string, options?: FetcherOptions): Promise<PackageMetadata>;
419
+ /**
420
+ * Fetch complete package with files
421
+ * @param spec - Package specifier (e.g., "lodash@4.17.21")
422
+ * @param options - Fetcher options
423
+ * @returns Package info with files
424
+ */
425
+ declare function fetchPackage(spec: string, options?: FetcherOptions): Promise<PackageInfo>;
426
+
427
+ export { AIError, CacheError, CacheOptions, CacheStats, ConfigError, ContentPriority, DownloadError, ExtractOptions, ExtractResult, Extractor, ExtractorOptions, FileCache, NpmLlmsError, PackageInfo, PackageMetadata, PackageNotFoundError, ParseError, PluginError, TarError, TimeoutError, ValidationError, VersionNotFoundError, countTokens, createCache, createExtractor, extract, fetchPackage, fetchPackageMetadata, formatBytes, formatTokenCount, getErrorCode, isNpmLlmsError, parsePackageSpec, truncateToTokenLimit, validatePackageName, wrapError };