@blockrun/franklin 3.29.1 → 3.29.2
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/llm.js +12 -2
- package/dist/agent/loop.js +9 -1
- package/dist/agent/repair/scavenge.js +42 -9
- package/package.json +1 -1
package/dist/agent/llm.js
CHANGED
|
@@ -949,9 +949,16 @@ export class ModelClient {
|
|
|
949
949
|
}
|
|
950
950
|
if (currentText) {
|
|
951
951
|
if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText)) {
|
|
952
|
+
// A roleplayed JSON tool call. Do NOT stream it to the UI,
|
|
953
|
+
// but DO keep it in `collected` so the loop's scavenge pass
|
|
954
|
+
// (src/agent/repair/scavenge.ts) can turn it into a real
|
|
955
|
+
// tool_use and execute it. If scavenge can't recover a valid
|
|
956
|
+
// call, the loop strips this text, restoring the old
|
|
957
|
+
// "non-productive → switch model" recovery.
|
|
958
|
+
collected.push({ type: 'text', text: currentText });
|
|
952
959
|
if (this.debug) {
|
|
953
960
|
console.error(`[franklin] Model ${request.model} emitted a raw JSON function-call object as text. ` +
|
|
954
|
-
'
|
|
961
|
+
'Held from display; loop will scavenge it into a tool_use or strip it.');
|
|
955
962
|
}
|
|
956
963
|
}
|
|
957
964
|
else if (textEmission.mode === 'hold' && isNemotronProse) {
|
|
@@ -1038,9 +1045,12 @@ export class ModelClient {
|
|
|
1038
1045
|
}
|
|
1039
1046
|
if (currentText) {
|
|
1040
1047
|
if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText)) {
|
|
1048
|
+
// See the matching branch in content_block_stop: keep it for the
|
|
1049
|
+
// loop's scavenge pass instead of dropping it.
|
|
1050
|
+
collected.push({ type: 'text', text: currentText });
|
|
1041
1051
|
if (this.debug) {
|
|
1042
1052
|
console.error(`[franklin] Model ${request.model} emitted a raw JSON function-call object as text. ` +
|
|
1043
|
-
'
|
|
1053
|
+
'Held from display; loop will scavenge it into a tool_use or strip it.');
|
|
1044
1054
|
}
|
|
1045
1055
|
}
|
|
1046
1056
|
else if (textEmission.mode === 'hold' && isNemotronProse) {
|
package/dist/agent/loop.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Franklin Agent Loop
|
|
3
3
|
* The core reasoning-action cycle: prompt → model → extract capabilities → execute → repeat.
|
|
4
4
|
*/
|
|
5
|
-
import { ModelClient } from './llm.js';
|
|
5
|
+
import { ModelClient, isRoleplayedJsonToolCallText } from './llm.js';
|
|
6
6
|
import { autoCompactIfNeeded, forceCompact, microCompact, projectCompactionSavings } from './compact.js';
|
|
7
7
|
import { estimateHistoryTokens, updateActualTokens, resetTokenAnchor, getAnchoredTokenCount, getContextWindow, setEstimationModel } from './tokens.js';
|
|
8
8
|
import { handleSlashCommand } from './commands.js';
|
|
@@ -1368,6 +1368,14 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
|
|
|
1368
1368
|
responseParts = [...responseParts, ...novelCalls];
|
|
1369
1369
|
logger.warn(`[franklin] scavenged ${repaired.report.scavenged} leaked tool call(s) from ${config.model}: ${repaired.report.notes.join('; ')}`);
|
|
1370
1370
|
}
|
|
1371
|
+
// Strip pure roleplayed-JSON tool-call text parts. The LLM client
|
|
1372
|
+
// holds these out of the live stream (never shown) but keeps them
|
|
1373
|
+
// in `content` so the scavenge above can recover the call. Whether
|
|
1374
|
+
// or not a call was recovered, the raw JSON must not linger as the
|
|
1375
|
+
// assistant's "answer" — drop it. When nothing was scavenged this
|
|
1376
|
+
// also empties the turn, so the empty-response recovery below can
|
|
1377
|
+
// switch models, preserving the prior behavior.
|
|
1378
|
+
responseParts = responseParts.filter(p => !(p.type === 'text' && isRoleplayedJsonToolCallText(p.text)));
|
|
1371
1379
|
}
|
|
1372
1380
|
// ── Empty response recovery ──
|
|
1373
1381
|
// If the model returns nothing, DON'T just retry the same model with the same input.
|
|
@@ -50,8 +50,9 @@ export function scavengeToolCalls(text, opts) {
|
|
|
50
50
|
for (const candidate of iterateJsonObjects(nonDsml)) {
|
|
51
51
|
if (out.length >= max)
|
|
52
52
|
break;
|
|
53
|
-
const call
|
|
54
|
-
|
|
53
|
+
for (const call of coerceToInvocations(candidate, opts.allowedNames)) {
|
|
54
|
+
if (out.length >= max)
|
|
55
|
+
break;
|
|
55
56
|
out.push(call);
|
|
56
57
|
notes.push(`scavenged call: ${call.name}`);
|
|
57
58
|
}
|
|
@@ -134,17 +135,41 @@ function* iterateJsonObjects(text) {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
function
|
|
138
|
+
function coerceToInvocations(candidateJson, allowedNames) {
|
|
138
139
|
let parsed;
|
|
139
140
|
try {
|
|
140
141
|
parsed = JSON.parse(candidateJson);
|
|
141
142
|
}
|
|
142
143
|
catch {
|
|
143
|
-
return
|
|
144
|
+
return [];
|
|
144
145
|
}
|
|
145
146
|
if (!parsed || typeof parsed !== 'object')
|
|
146
|
-
return
|
|
147
|
+
return [];
|
|
147
148
|
const obj = parsed;
|
|
149
|
+
// Envelope A — OpenAI assistant message { tool_calls: [ {...}, ... ] }.
|
|
150
|
+
// Gateway models that lack native tool-calling sometimes dump the whole
|
|
151
|
+
// assistant-message JSON into the text channel.
|
|
152
|
+
if (Array.isArray(obj.tool_calls)) {
|
|
153
|
+
const calls = [];
|
|
154
|
+
for (const tc of obj.tool_calls) {
|
|
155
|
+
const c = coerceObj(tc, allowedNames);
|
|
156
|
+
if (c)
|
|
157
|
+
calls.push(c);
|
|
158
|
+
}
|
|
159
|
+
return calls;
|
|
160
|
+
}
|
|
161
|
+
// Envelope B — legacy single { function_call: { name, arguments } }.
|
|
162
|
+
if (obj.function_call && typeof obj.function_call === 'object') {
|
|
163
|
+
const c = coerceObj({ type: 'function', function: obj.function_call }, allowedNames);
|
|
164
|
+
return c ? [c] : [];
|
|
165
|
+
}
|
|
166
|
+
const c = coerceObj(obj, allowedNames);
|
|
167
|
+
return c ? [c] : [];
|
|
168
|
+
}
|
|
169
|
+
function coerceObj(value, allowedNames) {
|
|
170
|
+
if (!value || typeof value !== 'object')
|
|
171
|
+
return null;
|
|
172
|
+
const obj = value;
|
|
148
173
|
// Pattern 1 — { name, arguments } (Anthropic-ish flat form) AND the flat
|
|
149
174
|
// OpenAI leak { type: "function", name, parameters } emitted by the free
|
|
150
175
|
// DeepSeek model — both carry the name at the top level. Args land under
|
|
@@ -188,10 +213,18 @@ function resolveAllowedName(name, allowedNames) {
|
|
|
188
213
|
return null;
|
|
189
214
|
if (allowedNames.has(name))
|
|
190
215
|
return name;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
216
|
+
// Try the name as-is, then with any provider namespace stripped
|
|
217
|
+
// (`functions.web_search` / `tools.web_search` → `web_search`), which
|
|
218
|
+
// Gemini- and OpenAI-style function declarations sometimes prepend.
|
|
219
|
+
const candidates = [name];
|
|
220
|
+
if (name.includes('.'))
|
|
221
|
+
candidates.push(name.slice(name.lastIndexOf('.') + 1));
|
|
222
|
+
for (const candidate of candidates) {
|
|
223
|
+
const target = normalizeName(candidate);
|
|
224
|
+
for (const allowed of allowedNames) {
|
|
225
|
+
if (normalizeName(allowed) === target)
|
|
226
|
+
return allowed;
|
|
227
|
+
}
|
|
195
228
|
}
|
|
196
229
|
return null;
|
|
197
230
|
}
|
package/package.json
CHANGED