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.
Files changed (2) hide show
  1. package/cli.js +29 -38
  2. 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 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., "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
- if (provider?.models) {
63
- // Find the model in the provider's models array
64
- const modelConfig = provider.models.find(m =>
65
- m.id === modelName || m.id === modelId
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 (modelConfig?.contextWindow) {
69
- return {
70
- model: modelId,
71
- tokens: modelConfig.contextWindow,
74
+ if (found?.contextWindow) {
75
+ return {
76
+ model: modelId,
77
+ tokens: found.contextWindow,
72
78
  source: 'config',
73
- maxTokens: modelConfig.maxTokens
79
+ maxTokens: found.maxTokens
74
80
  };
75
81
  }
76
82
  }
77
83
 
78
- // Fallback: check for ollama models with contextWindow in the config
79
- for (const [pName, pConfig] of Object.entries(providers)) {
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 (modelId.toLowerCase().includes(pattern.toLowerCase())) {
103
- return { model: modelId, tokens, source: 'fallback' };
93
+ if (primaryId.toLowerCase().includes(pattern.toLowerCase())) {
94
+ return { model: primaryId, tokens, source: 'fallback' };
104
95
  }
105
96
  }
106
97
 
107
- return { model: modelId, tokens: null, source: 'unknown' };
98
+ return { model: primaryId, tokens: null, source: 'unknown' };
108
99
  }
109
100
 
110
101
  async function setup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jasper-context-compactor",
3
- "version": "0.3.3",
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": {