jasper-context-compactor 0.3.4 → 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 -45
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -48,57 +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., "ollama/qwen2.5")
|
|
55
|
-
const [providerName, ...modelParts] = modelId.split('/');
|
|
56
|
-
const modelName = modelParts.join('/'); // e.g., "qwen2.5"
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
// Find model by ID in this provider's models array
|
|
72
|
+
const found = provider.models.find(m => m.id === modelName);
|
|
73
|
+
|
|
74
|
+
if (found?.contextWindow) {
|
|
75
|
+
return {
|
|
76
|
+
model: modelId,
|
|
77
|
+
tokens: found.contextWindow,
|
|
75
78
|
source: 'config',
|
|
76
|
-
maxTokens:
|
|
79
|
+
maxTokens: found.maxTokens
|
|
77
80
|
};
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
if (pConfig?.models) {
|
|
84
|
-
for (const m of pConfig.models) {
|
|
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
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Final fallback: known defaults for common model families
|
|
84
|
+
// No contextWindow found in config - try known defaults
|
|
85
|
+
const primaryId = modelConfig.primary || '';
|
|
102
86
|
const knownContexts = {
|
|
103
87
|
'anthropic/claude': 200000,
|
|
104
88
|
'openai/gpt-4': 128000,
|
|
@@ -106,12 +90,12 @@ async function detectModelContextWindow(config) {
|
|
|
106
90
|
};
|
|
107
91
|
|
|
108
92
|
for (const [pattern, tokens] of Object.entries(knownContexts)) {
|
|
109
|
-
if (
|
|
110
|
-
return { model:
|
|
93
|
+
if (primaryId.toLowerCase().includes(pattern.toLowerCase())) {
|
|
94
|
+
return { model: primaryId, tokens, source: 'fallback' };
|
|
111
95
|
}
|
|
112
96
|
}
|
|
113
97
|
|
|
114
|
-
return { model:
|
|
98
|
+
return { model: primaryId, tokens: null, source: 'unknown' };
|
|
115
99
|
}
|
|
116
100
|
|
|
117
101
|
async function setup() {
|
package/package.json
CHANGED