jasper-context-compactor 0.3.3 → 0.3.5
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 +29 -38
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -48,50 +48,41 @@ function backupConfig() {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async function detectModelContextWindow(config) {
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
51
|
+
const modelConfig = config?.agents?.defaults?.model;
|
|
52
|
+
if (!modelConfig) return null;
|
|
53
53
|
|
|
54
|
-
// Parse provider/model from the model ID (e.g., "anthropic/claude-opus-4-5")
|
|
55
|
-
const [providerName, ...modelParts] = modelId.split('/');
|
|
56
|
-
const modelName = modelParts.join('/');
|
|
57
|
-
|
|
58
|
-
// Look up in config's models.providers
|
|
59
54
|
const providers = config?.models?.providers || {};
|
|
60
|
-
const provider = providers[providerName];
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
// Collect all model candidates: primary first, then fallbacks
|
|
57
|
+
const candidates = [];
|
|
58
|
+
if (modelConfig.primary) candidates.push(modelConfig.primary);
|
|
59
|
+
if (modelConfig.fallbacks) candidates.push(...modelConfig.fallbacks);
|
|
60
|
+
|
|
61
|
+
// Find the first candidate that has a contextWindow defined in its provider
|
|
62
|
+
for (const modelId of candidates) {
|
|
63
|
+
if (!modelId.includes('/')) continue; // Skip if no provider prefix
|
|
64
|
+
|
|
65
|
+
const [providerName, ...modelParts] = modelId.split('/');
|
|
66
|
+
const modelName = modelParts.join('/'); // e.g., "qwen2.5"
|
|
67
|
+
|
|
68
|
+
const provider = providers[providerName];
|
|
69
|
+
if (!provider?.models) continue;
|
|
70
|
+
|
|
71
|
+
// Find model by ID in this provider's models array
|
|
72
|
+
const found = provider.models.find(m => m.id === modelName);
|
|
67
73
|
|
|
68
|
-
if (
|
|
69
|
-
return {
|
|
70
|
-
model: modelId,
|
|
71
|
-
tokens:
|
|
74
|
+
if (found?.contextWindow) {
|
|
75
|
+
return {
|
|
76
|
+
model: modelId,
|
|
77
|
+
tokens: found.contextWindow,
|
|
72
78
|
source: 'config',
|
|
73
|
-
maxTokens:
|
|
79
|
+
maxTokens: found.maxTokens
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
if (pConfig?.models) {
|
|
81
|
-
for (const m of pConfig.models) {
|
|
82
|
-
if (m.id && modelId.includes(m.id) && m.contextWindow) {
|
|
83
|
-
return {
|
|
84
|
-
model: modelId,
|
|
85
|
-
tokens: m.contextWindow,
|
|
86
|
-
source: 'config',
|
|
87
|
-
maxTokens: m.maxTokens
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Final fallback: known defaults for common model families
|
|
84
|
+
// No contextWindow found in config - try known defaults
|
|
85
|
+
const primaryId = modelConfig.primary || '';
|
|
95
86
|
const knownContexts = {
|
|
96
87
|
'anthropic/claude': 200000,
|
|
97
88
|
'openai/gpt-4': 128000,
|
|
@@ -99,12 +90,12 @@ async function detectModelContextWindow(config) {
|
|
|
99
90
|
};
|
|
100
91
|
|
|
101
92
|
for (const [pattern, tokens] of Object.entries(knownContexts)) {
|
|
102
|
-
if (
|
|
103
|
-
return { model:
|
|
93
|
+
if (primaryId.toLowerCase().includes(pattern.toLowerCase())) {
|
|
94
|
+
return { model: primaryId, tokens, source: 'fallback' };
|
|
104
95
|
}
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
return { model:
|
|
98
|
+
return { model: primaryId, tokens: null, source: 'unknown' };
|
|
108
99
|
}
|
|
109
100
|
|
|
110
101
|
async function setup() {
|
package/package.json
CHANGED