@tjamescouch/gro 1.3.13 → 1.3.15
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/drivers/anthropic.js +21 -3
- package/dist/main.js +3 -3
- package/dist/memory/advanced-memory.js +35 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -128,6 +128,23 @@ function parseResponseContent(data, onToken) {
|
|
|
128
128
|
} : undefined;
|
|
129
129
|
return { text, toolCalls, usage };
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Determine if a model supports Anthropic adaptive/extended thinking.
|
|
133
|
+
* Conservative allowlist approach: if we don't recognize the model,
|
|
134
|
+
* we omit thinking (safe default — API works fine without it).
|
|
135
|
+
*/
|
|
136
|
+
function supportsAdaptiveThinking(model) {
|
|
137
|
+
const m = model.toLowerCase();
|
|
138
|
+
if (/claude-opus-4/.test(m))
|
|
139
|
+
return true;
|
|
140
|
+
if (/claude-sonnet-4/.test(m))
|
|
141
|
+
return true;
|
|
142
|
+
if (/claude-3[.-]7/.test(m))
|
|
143
|
+
return true;
|
|
144
|
+
if (/claude-3[.-]5-sonnet.*20241022/.test(m))
|
|
145
|
+
return true;
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
131
148
|
export function makeAnthropicDriver(cfg) {
|
|
132
149
|
const base = (cfg.baseUrl ?? "https://api.anthropic.com").replace(/\/+$/, "");
|
|
133
150
|
const endpoint = `${base}/v1/messages`;
|
|
@@ -141,12 +158,13 @@ export function makeAnthropicDriver(cfg) {
|
|
|
141
158
|
const { system: systemPrompt, apiMessages } = convertMessages(messages);
|
|
142
159
|
const body = {
|
|
143
160
|
model: resolvedModel,
|
|
144
|
-
thinking: {
|
|
145
|
-
type: "adaptive"
|
|
146
|
-
},
|
|
147
161
|
max_tokens: maxTokens,
|
|
148
162
|
messages: apiMessages,
|
|
149
163
|
};
|
|
164
|
+
// Only include adaptive thinking for models that support it
|
|
165
|
+
if (supportsAdaptiveThinking(resolvedModel)) {
|
|
166
|
+
body.thinking = { type: "adaptive" };
|
|
167
|
+
}
|
|
150
168
|
if (systemPrompt)
|
|
151
169
|
body.system = systemPrompt;
|
|
152
170
|
// Tools support — convert from OpenAI format to Anthropic format
|
package/dist/main.js
CHANGED
|
@@ -487,9 +487,9 @@ function formatOutput(text, format) {
|
|
|
487
487
|
* the model needing to know the full versioned name.
|
|
488
488
|
*/
|
|
489
489
|
const MODEL_ALIASES = {
|
|
490
|
-
"haiku": "claude-haiku-4-
|
|
491
|
-
"sonnet": "claude-sonnet-4-
|
|
492
|
-
"opus": "claude-opus-4-
|
|
490
|
+
"haiku": "claude-haiku-4-5",
|
|
491
|
+
"sonnet": "claude-sonnet-4-5",
|
|
492
|
+
"opus": "claude-opus-4-6",
|
|
493
493
|
"gpt4": "gpt-4o",
|
|
494
494
|
"gpt4o": "gpt-4o",
|
|
495
495
|
"gpt4o-mini": "gpt-4o-mini",
|
|
@@ -20,7 +20,7 @@ export class AdvancedMemory extends AgentMemory {
|
|
|
20
20
|
this.highRatio = Math.min(0.95, Math.max(0.55, args.highRatio ?? 0.70));
|
|
21
21
|
this.lowRatio = Math.min(this.highRatio - 0.05, Math.max(0.35, args.lowRatio ?? 0.50));
|
|
22
22
|
this.summaryRatio = Math.min(0.50, Math.max(0.15, args.summaryRatio ?? 0.35));
|
|
23
|
-
this.avgCharsPerToken = Math.max(1.5, Number(args.avgCharsPerToken ??
|
|
23
|
+
this.avgCharsPerToken = Math.max(1.5, Number(args.avgCharsPerToken ?? 2.8));
|
|
24
24
|
this.keepRecentPerLane = Math.max(1, Math.floor(args.keepRecentPerLane ?? 4));
|
|
25
25
|
this.keepRecentTools = Math.max(0, Math.floor(args.keepRecentTools ?? 3));
|
|
26
26
|
}
|
|
@@ -42,6 +42,40 @@ export class AdvancedMemory extends AgentMemory {
|
|
|
42
42
|
createdAt: new Date().toISOString(),
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Return messages for the API, with hard truncation as a safety net.
|
|
47
|
+
* Even if background summarization hasn't caught up, this ensures we never
|
|
48
|
+
* send more than the configured context budget to the driver.
|
|
49
|
+
*/
|
|
50
|
+
messages() {
|
|
51
|
+
const budget = this.budgetTokens();
|
|
52
|
+
const all = [...this.messagesBuffer];
|
|
53
|
+
const estTok = this.estimateTokens(all);
|
|
54
|
+
// If under budget, return everything (common case)
|
|
55
|
+
if (estTok <= budget)
|
|
56
|
+
return all;
|
|
57
|
+
// Hard truncation: keep system prompt + most recent messages that fit
|
|
58
|
+
const result = [];
|
|
59
|
+
let usedTok = 0;
|
|
60
|
+
// Always keep the system prompt (first message if system role)
|
|
61
|
+
if (all.length > 0 && all[0].role === "system") {
|
|
62
|
+
result.push(all[0]);
|
|
63
|
+
usedTok = this.estimateTokens(result);
|
|
64
|
+
}
|
|
65
|
+
// Walk backwards from the end, adding messages until we hit budget
|
|
66
|
+
const toAdd = [];
|
|
67
|
+
for (let i = all.length - 1; i >= (result.length > 0 ? 1 : 0); i--) {
|
|
68
|
+
const candidate = [all[i], ...toAdd];
|
|
69
|
+
const candidateTok = this.estimateTokens(candidate);
|
|
70
|
+
if (usedTok + candidateTok <= budget) {
|
|
71
|
+
toAdd.unshift(all[i]);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
break; // No more room
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [...result, ...toAdd];
|
|
78
|
+
}
|
|
45
79
|
async onAfterAdd() {
|
|
46
80
|
const budget = this.budgetTokens();
|
|
47
81
|
const estTok = this.estimateTokens(this.messagesBuffer);
|
package/dist/package.json
CHANGED