@compilr-dev/sdk 0.7.27 → 0.7.29
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/dist/agent.js +15 -11
- package/dist/config.d.ts +27 -2
- package/dist/models/model-registry.d.ts +4 -2
- package/dist/models/model-registry.js +13 -5
- package/dist/models.d.ts +1 -1
- package/dist/models.js +7 -4
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +9 -2
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -97,6 +97,7 @@ class CompilrAgentImpl {
|
|
|
97
97
|
provider: config?.provider,
|
|
98
98
|
model: config?.model,
|
|
99
99
|
apiKey: config?.apiKey,
|
|
100
|
+
extendedContext: config?.context?.extendedContext,
|
|
100
101
|
});
|
|
101
102
|
// Resolve preset — non-software projects get 'general' by default
|
|
102
103
|
const defaultPreset = config?.projectCategory && config.projectCategory !== 'software' ? 'general' : 'coding';
|
|
@@ -121,9 +122,10 @@ class CompilrAgentImpl {
|
|
|
121
122
|
}
|
|
122
123
|
// Build context manager if configured
|
|
123
124
|
let contextManager;
|
|
125
|
+
const extendedContext = config?.context?.extendedContext ?? false;
|
|
124
126
|
const contextLimit = config?.context
|
|
125
|
-
? (config.context.contextLimit ?? getContextWindow(config.model))
|
|
126
|
-
: getContextWindow(config?.model);
|
|
127
|
+
? (config.context.contextLimit ?? getContextWindow(config.model, extendedContext))
|
|
128
|
+
: getContextWindow(config?.model, extendedContext);
|
|
127
129
|
if (config?.context) {
|
|
128
130
|
contextManager = new ContextManager({
|
|
129
131
|
provider,
|
|
@@ -298,15 +300,17 @@ class CompilrAgentImpl {
|
|
|
298
300
|
observationMask: contextManager ? observationMask : undefined,
|
|
299
301
|
windowing: contextManager
|
|
300
302
|
? config?.context?.windowing !== false
|
|
301
|
-
? {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
303
|
+
? (() => {
|
|
304
|
+
const wCfg = typeof config?.context?.windowing === 'object' ? config.context.windowing : {};
|
|
305
|
+
const historyRatio = wCfg.targetHistoryRatio ?? 0.1;
|
|
306
|
+
const recentRatio = wCfg.recentWindowRatio ?? 0.025;
|
|
307
|
+
return {
|
|
308
|
+
// Derive from model context window, overridable with explicit values
|
|
309
|
+
targetHistoryTokens: wCfg.targetHistoryTokens ?? Math.round(contextLimit * historyRatio),
|
|
310
|
+
recentWindowTokens: wCfg.recentWindowTokens ?? Math.round(contextLimit * recentRatio),
|
|
311
|
+
enabled: wCfg.enabled,
|
|
312
|
+
};
|
|
313
|
+
})()
|
|
310
314
|
: false
|
|
311
315
|
: undefined,
|
|
312
316
|
hooks: mergedHooks,
|
package/dist/config.d.ts
CHANGED
|
@@ -96,6 +96,21 @@ export interface GuardrailConfig {
|
|
|
96
96
|
export interface ContextConfig {
|
|
97
97
|
/** Context window limit in tokens. Auto-detected from model if omitted. */
|
|
98
98
|
contextLimit?: number;
|
|
99
|
+
/**
|
|
100
|
+
* Enable extended context window when available for the model.
|
|
101
|
+
*
|
|
102
|
+
* - **Claude Opus 4.6 / Sonnet 4.5**: activates 1M context (default: 200K)
|
|
103
|
+
* via `context-1m-2025-08-07` beta header.
|
|
104
|
+
* Long-context pricing applies above 200K tokens per request.
|
|
105
|
+
*
|
|
106
|
+
* - Other providers: no effect (context window is fixed).
|
|
107
|
+
*
|
|
108
|
+
* When enabled, `contextLimit` auto-detects to the extended window (1M for Claude).
|
|
109
|
+
* When disabled, `contextLimit` auto-detects to the standard window (200K for Claude).
|
|
110
|
+
*
|
|
111
|
+
* Default: false
|
|
112
|
+
*/
|
|
113
|
+
extendedContext?: boolean;
|
|
99
114
|
/** Threshold (0-1) to trigger compaction. Default: 0.5 */
|
|
100
115
|
compactionThreshold?: number;
|
|
101
116
|
/** Threshold (0-1) to trigger emergency summarization. Default: 0.9 */
|
|
@@ -110,10 +125,20 @@ export interface ContextConfig {
|
|
|
110
125
|
* Smart windowing — programmatic context compaction.
|
|
111
126
|
* Compacts old messages when history exceeds token budget.
|
|
112
127
|
* Three zones: recent (intact), middle (truncated), old (event log).
|
|
113
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* When omitted, targets are derived from the model's context window:
|
|
130
|
+
* targetHistoryTokens = contextLimit * targetHistoryRatio (default 0.10)
|
|
131
|
+
* recentWindowTokens = contextLimit * recentWindowRatio (default 0.025)
|
|
132
|
+
*
|
|
114
133
|
* Set to false to disable windowing entirely.
|
|
134
|
+
* Set explicit targetHistoryTokens/recentWindowTokens to override proportional defaults.
|
|
115
135
|
*/
|
|
116
|
-
windowing?: Partial<WindowingConfig>
|
|
136
|
+
windowing?: (Partial<WindowingConfig> & {
|
|
137
|
+
/** Fraction of context window for target history. Default: 0.10 (10%) */
|
|
138
|
+
targetHistoryRatio?: number;
|
|
139
|
+
/** Fraction of context window for recent window. Default: 0.025 (2.5%) */
|
|
140
|
+
recentWindowRatio?: number;
|
|
141
|
+
}) | false;
|
|
117
142
|
}
|
|
118
143
|
/**
|
|
119
144
|
* Usage information for the agent
|
|
@@ -39,8 +39,10 @@ export interface ModelInfo {
|
|
|
39
39
|
status: ModelStatus;
|
|
40
40
|
/** Notes shown in UI (e.g., why unsupported) */
|
|
41
41
|
notes?: string;
|
|
42
|
-
/**
|
|
42
|
+
/** Standard context window size in tokens */
|
|
43
43
|
contextWindow?: number;
|
|
44
|
+
/** Extended context window (requires opt-in, e.g., beta header). Undefined = no extended option */
|
|
45
|
+
extendedContextWindow?: number;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Registry of known models with their metadata.
|
|
@@ -105,7 +107,7 @@ export declare function shouldClearHistoryOnModelChange(_fromModelId: string | u
|
|
|
105
107
|
* Get context window size for a model ID.
|
|
106
108
|
* Falls back to provider default if model not found or contextWindow not set.
|
|
107
109
|
*/
|
|
108
|
-
export declare function getModelContextWindow(modelId: string, provider?: ProviderType): number;
|
|
110
|
+
export declare function getModelContextWindow(modelId: string, provider?: ProviderType, extendedContext?: boolean): number;
|
|
109
111
|
/**
|
|
110
112
|
* Get model display name by ID.
|
|
111
113
|
* Returns the model ID if not found in registry.
|
|
@@ -37,7 +37,8 @@ export const MODEL_REGISTRY = [
|
|
|
37
37
|
defaultTier: 'balanced',
|
|
38
38
|
thinkingFormat: 'claude',
|
|
39
39
|
status: 'supported',
|
|
40
|
-
contextWindow:
|
|
40
|
+
contextWindow: 200000,
|
|
41
|
+
extendedContextWindow: 1000000,
|
|
41
42
|
},
|
|
42
43
|
{
|
|
43
44
|
id: 'claude-opus-4-6',
|
|
@@ -47,7 +48,8 @@ export const MODEL_REGISTRY = [
|
|
|
47
48
|
defaultTier: 'powerful',
|
|
48
49
|
thinkingFormat: 'claude',
|
|
49
50
|
status: 'supported',
|
|
50
|
-
contextWindow:
|
|
51
|
+
contextWindow: 200000,
|
|
52
|
+
extendedContextWindow: 1000000,
|
|
51
53
|
},
|
|
52
54
|
// Legacy Claude models (still supported)
|
|
53
55
|
{
|
|
@@ -78,6 +80,7 @@ export const MODEL_REGISTRY = [
|
|
|
78
80
|
thinkingFormat: 'claude',
|
|
79
81
|
status: 'supported',
|
|
80
82
|
contextWindow: 200000,
|
|
83
|
+
extendedContextWindow: 1000000,
|
|
81
84
|
notes: 'Legacy',
|
|
82
85
|
},
|
|
83
86
|
// ---------------------------------------------------------------------------
|
|
@@ -606,10 +609,15 @@ function getProviderContextLimitFallback(provider) {
|
|
|
606
609
|
* Get context window size for a model ID.
|
|
607
610
|
* Falls back to provider default if model not found or contextWindow not set.
|
|
608
611
|
*/
|
|
609
|
-
export function getModelContextWindow(modelId, provider) {
|
|
612
|
+
export function getModelContextWindow(modelId, provider, extendedContext) {
|
|
610
613
|
const info = getModelInfo(modelId);
|
|
611
|
-
if (info
|
|
612
|
-
|
|
614
|
+
if (info) {
|
|
615
|
+
if (extendedContext && info.extendedContextWindow) {
|
|
616
|
+
return info.extendedContextWindow;
|
|
617
|
+
}
|
|
618
|
+
if (info.contextWindow) {
|
|
619
|
+
return info.contextWindow;
|
|
620
|
+
}
|
|
613
621
|
}
|
|
614
622
|
return getProviderContextLimitFallback(provider);
|
|
615
623
|
}
|
package/dist/models.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export declare const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
|
18
18
|
* Get the context window size for a model.
|
|
19
19
|
* Delegates to the full registry with prefix-matching fallback.
|
|
20
20
|
*/
|
|
21
|
-
export declare function getContextWindow(model?: string): number;
|
|
21
|
+
export declare function getContextWindow(model?: string, extendedContext?: boolean): number;
|
package/dist/models.js
CHANGED
|
@@ -44,12 +44,12 @@ export const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
|
44
44
|
* Get the context window size for a model.
|
|
45
45
|
* Delegates to the full registry with prefix-matching fallback.
|
|
46
46
|
*/
|
|
47
|
-
export function getContextWindow(model) {
|
|
47
|
+
export function getContextWindow(model, extendedContext) {
|
|
48
48
|
if (!model) {
|
|
49
49
|
return DEFAULT_CONTEXT_WINDOW;
|
|
50
50
|
}
|
|
51
51
|
// Use the registry-backed implementation
|
|
52
|
-
const result = getModelContextWindow(model);
|
|
52
|
+
const result = getModelContextWindow(model, undefined, extendedContext);
|
|
53
53
|
// getModelContextWindow returns the provider fallback (200000) for unknown models,
|
|
54
54
|
// but the original getContextWindow returned DEFAULT_CONTEXT_WINDOW (128000).
|
|
55
55
|
// Check if the model was actually found in the registry.
|
|
@@ -59,14 +59,17 @@ export function getContextWindow(model) {
|
|
|
59
59
|
}
|
|
60
60
|
// Prefix match against registry entries (e.g., new dated variant of known model)
|
|
61
61
|
for (const entry of MODEL_REGISTRY) {
|
|
62
|
-
|
|
62
|
+
const cw = extendedContext
|
|
63
|
+
? (entry.extendedContextWindow ?? entry.contextWindow)
|
|
64
|
+
: entry.contextWindow;
|
|
65
|
+
if (!cw)
|
|
63
66
|
continue;
|
|
64
67
|
const parts = entry.id.split('-');
|
|
65
68
|
if (parts.length < 2)
|
|
66
69
|
continue;
|
|
67
70
|
const prefix = parts.slice(0, -1).join('-');
|
|
68
71
|
if (prefix && model.startsWith(prefix)) {
|
|
69
|
-
return
|
|
72
|
+
return cw;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
return DEFAULT_CONTEXT_WINDOW;
|
package/dist/provider.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function createProviderFromType(type: ProviderType, options?: {
|
|
|
17
17
|
baseUrl?: string;
|
|
18
18
|
siteName?: string;
|
|
19
19
|
estimateTokens?: (text: string) => number;
|
|
20
|
+
extendedContext?: boolean;
|
|
20
21
|
}): LLMProvider;
|
|
21
22
|
/**
|
|
22
23
|
* Resolve a provider from config.
|
|
@@ -26,4 +27,5 @@ export declare function resolveProvider(config?: {
|
|
|
26
27
|
provider?: ProviderType | LLMProvider;
|
|
27
28
|
model?: string;
|
|
28
29
|
apiKey?: string;
|
|
30
|
+
extendedContext?: boolean;
|
|
29
31
|
}): LLMProvider;
|
package/dist/provider.js
CHANGED
|
@@ -32,10 +32,15 @@ export function detectProviderFromEnv() {
|
|
|
32
32
|
* Create an LLM provider from a provider type string.
|
|
33
33
|
*/
|
|
34
34
|
export function createProviderFromType(type, options) {
|
|
35
|
-
const { model, apiKey, baseUrl, siteName, estimateTokens } = options ?? {};
|
|
35
|
+
const { model, apiKey, baseUrl, siteName, estimateTokens, extendedContext } = options ?? {};
|
|
36
36
|
switch (type) {
|
|
37
37
|
case 'claude':
|
|
38
|
-
return createClaudeProvider({
|
|
38
|
+
return createClaudeProvider({
|
|
39
|
+
model,
|
|
40
|
+
apiKey,
|
|
41
|
+
estimateTokens,
|
|
42
|
+
enableExtendedContext: extendedContext,
|
|
43
|
+
});
|
|
39
44
|
case 'openai':
|
|
40
45
|
return createOpenAIProvider({ model, apiKey, estimateTokens });
|
|
41
46
|
case 'gemini':
|
|
@@ -71,6 +76,7 @@ export function resolveProvider(config) {
|
|
|
71
76
|
return createProviderFromType(config.provider, {
|
|
72
77
|
model: config.model,
|
|
73
78
|
apiKey: config.apiKey,
|
|
79
|
+
extendedContext: config.extendedContext,
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
82
|
// Auto-detect from env
|
|
@@ -79,6 +85,7 @@ export function resolveProvider(config) {
|
|
|
79
85
|
return createProviderFromType(detected, {
|
|
80
86
|
model: config?.model,
|
|
81
87
|
apiKey: config?.apiKey,
|
|
88
|
+
extendedContext: config?.extendedContext,
|
|
82
89
|
});
|
|
83
90
|
}
|
|
84
91
|
throw new Error('No LLM provider configured. Either:\n' +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.29",
|
|
4
4
|
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"node": ">=18.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@compilr-dev/agents": "^0.4.
|
|
56
|
+
"@compilr-dev/agents": "^0.4.1",
|
|
57
57
|
"@compilr-dev/sdk": "^0.5.4",
|
|
58
58
|
"ajv": "^6.14.0"
|
|
59
59
|
},
|