@blockrun/franklin 3.29.0 → 3.29.1

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.
@@ -37,10 +37,11 @@ export function scavengeToolCalls(text, opts) {
37
37
  for (const invoke of iterateDsmlInvokes(text)) {
38
38
  if (out.length >= max)
39
39
  break;
40
- if (!opts.allowedNames.has(invoke.name))
40
+ const resolved = resolveAllowedName(invoke.name, opts.allowedNames);
41
+ if (!resolved)
41
42
  continue;
42
- out.push(makeInvocation(invoke.name, invoke.args));
43
- notes.push(`scavenged DSML call: ${invoke.name}`);
43
+ out.push(makeInvocation(resolved, invoke.args));
44
+ notes.push(`scavenged DSML call: ${resolved}`);
44
45
  }
45
46
  // Pattern B — raw JSON objects in the three canonical shapes. Strip
46
47
  // DSML blocks first so their parameter payloads don't get re-scavenged
@@ -144,22 +145,53 @@ function coerceToInvocation(candidateJson, allowedNames) {
144
145
  if (!parsed || typeof parsed !== 'object')
145
146
  return null;
146
147
  const obj = parsed;
147
- // Pattern 1 — { name, arguments } (Anthropic-ish flat form).
148
- if (typeof obj.name === 'string' && allowedNames.has(obj.name)) {
149
- return makeInvocation(obj.name, normalizeArgs(obj.arguments));
148
+ // Pattern 1 — { name, arguments } (Anthropic-ish flat form) AND the flat
149
+ // OpenAI leak { type: "function", name, parameters } emitted by the free
150
+ // DeepSeek model — both carry the name at the top level. Args land under
151
+ // `arguments` or `parameters` depending on the model's chat template.
152
+ if (typeof obj.name === 'string') {
153
+ const resolved = resolveAllowedName(obj.name, allowedNames);
154
+ if (resolved) {
155
+ return makeInvocation(resolved, normalizeArgs(obj.arguments ?? obj.parameters));
156
+ }
150
157
  }
151
158
  // Pattern 2 — OpenAI-style { type: "function", function: { name, arguments } }.
152
159
  if (obj.type === 'function' &&
153
160
  obj.function &&
154
161
  typeof obj.function === 'object') {
155
162
  const fn = obj.function;
156
- if (typeof fn.name === 'string' && allowedNames.has(fn.name)) {
157
- return makeInvocation(fn.name, normalizeArgs(fn.arguments));
163
+ const resolved = typeof fn.name === 'string' ? resolveAllowedName(fn.name, allowedNames) : null;
164
+ if (resolved) {
165
+ return makeInvocation(resolved, normalizeArgs(fn.arguments ?? fn.parameters));
158
166
  }
159
167
  }
160
168
  // Pattern 3 — { tool_name, tool_args } (R1 free-form variant).
161
- if (typeof obj.tool_name === 'string' && allowedNames.has(obj.tool_name)) {
162
- return makeInvocation(obj.tool_name, normalizeArgs(obj.tool_args));
169
+ if (typeof obj.tool_name === 'string') {
170
+ const resolved = resolveAllowedName(obj.tool_name, allowedNames);
171
+ if (resolved) {
172
+ return makeInvocation(resolved, normalizeArgs(obj.tool_args ?? obj.tool_parameters));
173
+ }
174
+ }
175
+ return null;
176
+ }
177
+ /** Collapse a tool name to a comparison key: lowercase, drop separators.
178
+ * `activate_tool` / `web_search` → `activatetool` / `websearch`. */
179
+ function normalizeName(name) {
180
+ return name.toLowerCase().replace(/[_\-\s]/g, '');
181
+ }
182
+ /** Resolve a leaked tool name to its canonical registry spelling. Exact
183
+ * match wins; otherwise a separator/case-insensitive match lets models
184
+ * that rewrite names to OpenAI snake_case (`web_search` → `WebSearch`)
185
+ * still be recovered. Returns null if no allowed tool matches. */
186
+ function resolveAllowedName(name, allowedNames) {
187
+ if (!name || typeof name !== 'string')
188
+ return null;
189
+ if (allowedNames.has(name))
190
+ return name;
191
+ const target = normalizeName(name);
192
+ for (const allowed of allowedNames) {
193
+ if (normalizeName(allowed) === target)
194
+ return allowed;
163
195
  }
164
196
  return null;
165
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.29.0",
3
+ "version": "3.29.1",
4
4
  "description": "Franklin Agent — The AI agent with a wallet. Spends USDC autonomously to get real work done. Pay per action, no subscriptions.",
5
5
  "type": "module",
6
6
  "exports": {