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.
Files changed (2) hide show
  1. package/cli.js +29 -45
  2. 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 modelId = config?.agents?.defaults?.model?.primary;
52
- if (!modelId) return null;
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
- if (provider?.models) {
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
- });
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
- if (modelConfig?.contextWindow) {
72
- return {
73
- model: modelId,
74
- tokens: modelConfig.contextWindow,
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: modelConfig.maxTokens
79
+ maxTokens: found.maxTokens
77
80
  };
78
81
  }
79
82
  }
80
83
 
81
- // Fallback: check ALL providers for a matching model ID
82
- for (const [pName, pConfig] of Object.entries(providers)) {
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 (modelId.toLowerCase().includes(pattern.toLowerCase())) {
110
- return { model: modelId, tokens, source: 'fallback' };
93
+ if (primaryId.toLowerCase().includes(pattern.toLowerCase())) {
94
+ return { model: primaryId, tokens, source: 'fallback' };
111
95
  }
112
96
  }
113
97
 
114
- return { model: modelId, tokens: null, source: 'unknown' };
98
+ return { model: primaryId, tokens: null, source: 'unknown' };
115
99
  }
116
100
 
117
101
  async function setup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jasper-context-compactor",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Context compaction plugin for OpenClaw - works with local models (MLX, llama.cpp) that don't report token limits",
5
5
  "main": "index.ts",
6
6
  "bin": {