-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
130 lines (120 loc) · 3.22 KB
/
index.js
File metadata and controls
130 lines (120 loc) · 3.22 KB
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
/**
* ctxstuff - LLM Context Packing Tool
*
* Programmatic API for packing codebases into LLM-ready context.
*
* @example
* const { pack, count, format } = require('ctxstuff');
*
* // Pack a directory
* const result = await pack('./my-project');
*
* // Count tokens
* const tokens = count(result.files);
*
* // Format output
* const markdown = format(result, 'markdown');
*/
const { packDirectory, getFileTree, collectFiles } = require('./src/core/packer');
const {
estimateTokens,
countTokens,
countFilesTokens,
calculateCost,
getModelInfo,
listModels,
} = require('./src/core/tokenizer');
const { optimizeContext, getSuggestions } = require('./src/core/optimizer');
const { splitContext, suggestSplit } = require('./src/core/splitter');
const { format, formatMarkdown, formatXML, formatPlain, formatJSON, FORMATS } = require('./src/core/formatter');
const { isPro, activateLicense, getLicenseStatus } = require('./src/license/checker');
const { checkFileLimit, checkSizeLimit, getLimitStatus } = require('./src/license/limits');
const { MODEL_PRICING, DEFAULT_MODEL, FREE_LIMITS } = require('./src/license/constants');
/**
* Pack a directory into LLM-ready context
* @param {string} directory - Directory to pack
* @param {Object} options - Packing options
* @returns {Promise<Object>} Packed result
*/
async function pack(directory, options = {}) {
return packDirectory(directory, options);
}
/**
* Count tokens in text or files
* @param {string|Object[]} input - Text string or array of file objects
* @param {string} model - Model name
* @returns {Object} Token count result
*/
function count(input, model = DEFAULT_MODEL) {
if (typeof input === 'string') {
return countTokens(input, model);
}
return countFilesTokens(input, model);
}
/**
* Optimize packed content to fit token limit (PRO only)
* @param {Object} packed - Packed directory result
* @param {Object} options - Optimization options
* @returns {Object} Optimized result
*/
function optimize(packed, options = {}) {
return optimizeContext(packed, options);
}
/**
* Split packed content into chunks (PRO only)
* @param {Object} packed - Packed directory result
* @param {Object} options - Split options
* @returns {Object} Split result with chunks
*/
function split(packed, options = {}) {
return splitContext(packed, options);
}
/**
* Calculate API cost for tokens
* @param {number} inputTokens - Input token count
* @param {number} outputTokens - Output token count
* @param {string} model - Model name
* @returns {Object} Cost breakdown
*/
function cost(inputTokens, outputTokens = 0, model = DEFAULT_MODEL) {
return calculateCost(inputTokens, outputTokens, model);
}
module.exports = {
// Main functions
pack,
count,
format,
optimize,
split,
cost,
// Core modules
packDirectory,
getFileTree,
collectFiles,
estimateTokens,
countTokens,
countFilesTokens,
calculateCost,
getModelInfo,
listModels,
optimizeContext,
getSuggestions,
splitContext,
suggestSplit,
formatMarkdown,
formatXML,
formatPlain,
formatJSON,
// License
isPro,
activateLicense,
getLicenseStatus,
checkFileLimit,
checkSizeLimit,
getLimitStatus,
// Constants
MODEL_PRICING,
DEFAULT_MODEL,
FREE_LIMITS,
FORMATS,
};