jasper-context-compactor 0.3.2 → 0.3.4
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/cli.js +28 -16
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -51,19 +51,22 @@ async function detectModelContextWindow(config) {
|
|
|
51
51
|
const modelId = config?.agents?.defaults?.model?.primary;
|
|
52
52
|
if (!modelId) return null;
|
|
53
53
|
|
|
54
|
-
// Parse provider/model from the model ID (e.g., "
|
|
54
|
+
// Parse provider/model from the model ID (e.g., "ollama/qwen2.5")
|
|
55
55
|
const [providerName, ...modelParts] = modelId.split('/');
|
|
56
|
-
const modelName = modelParts.join('/');
|
|
56
|
+
const modelName = modelParts.join('/'); // e.g., "qwen2.5"
|
|
57
57
|
|
|
58
58
|
// Look up in config's models.providers
|
|
59
59
|
const providers = config?.models?.providers || {};
|
|
60
60
|
const provider = providers[providerName];
|
|
61
61
|
|
|
62
62
|
if (provider?.models) {
|
|
63
|
-
// Find the model
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
// Find the model - compare against just the model name (without provider prefix)
|
|
64
|
+
// e.g., config has id:"qwen2.5", we're looking for "ollama/qwen2.5"
|
|
65
|
+
const modelConfig = provider.models.find(m => {
|
|
66
|
+
if (!m.id) return false;
|
|
67
|
+
// Match: exact ID, or model name matches, or ID matches without provider prefix
|
|
68
|
+
return m.id === modelId || m.id === modelName || modelName.includes(m.id) || m.id.includes(modelName);
|
|
69
|
+
});
|
|
67
70
|
|
|
68
71
|
if (modelConfig?.contextWindow) {
|
|
69
72
|
return {
|
|
@@ -75,17 +78,21 @@ async function detectModelContextWindow(config) {
|
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
// Fallback: check
|
|
81
|
+
// Fallback: check ALL providers for a matching model ID
|
|
79
82
|
for (const [pName, pConfig] of Object.entries(providers)) {
|
|
80
83
|
if (pConfig?.models) {
|
|
81
84
|
for (const m of pConfig.models) {
|
|
82
|
-
if (m.id
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (!m.id) continue;
|
|
86
|
+
// Flexible matching: model ID contains or is contained by what we're looking for
|
|
87
|
+
if (m.id === modelName || modelName.includes(m.id) || m.id.includes(modelName)) {
|
|
88
|
+
if (m.contextWindow) {
|
|
89
|
+
return {
|
|
90
|
+
model: modelId,
|
|
91
|
+
tokens: m.contextWindow,
|
|
92
|
+
source: 'config',
|
|
93
|
+
maxTokens: m.maxTokens
|
|
94
|
+
};
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
}
|
|
@@ -204,6 +211,11 @@ async function setup() {
|
|
|
204
211
|
if (checkConfig.toLowerCase() === 'y' || checkConfig.toLowerCase() === 'yes') {
|
|
205
212
|
detectedInfo = await detectModelContextWindow(config);
|
|
206
213
|
|
|
214
|
+
// Debug: show what we found
|
|
215
|
+
if (process.env.DEBUG) {
|
|
216
|
+
console.log(' [DEBUG] detectedInfo:', JSON.stringify(detectedInfo, null, 2));
|
|
217
|
+
}
|
|
218
|
+
|
|
207
219
|
if (detectedInfo && detectedInfo.tokens) {
|
|
208
220
|
console.log('');
|
|
209
221
|
console.log(` ✓ Detected model: ${detectedInfo.model}`);
|
|
@@ -235,8 +247,8 @@ async function setup() {
|
|
|
235
247
|
}
|
|
236
248
|
}
|
|
237
249
|
|
|
238
|
-
// Manual entry if
|
|
239
|
-
if (!detectedInfo?.tokens
|
|
250
|
+
// Manual entry only if we couldn't detect context window at all
|
|
251
|
+
if (!detectedInfo?.tokens) {
|
|
240
252
|
console.log('');
|
|
241
253
|
console.log(' Could not auto-detect context window from your config.');
|
|
242
254
|
console.log('');
|
package/package.json
CHANGED