Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Map near-miss tool names + duration alias (gemma4 live: "video_generation")

purple23969f63f8bd
diff --git a/src/api/vram-handoff.ts b/src/api/vram-handoff.ts
index 791ec500..46085ed7 100644
--- a/src/api/vram-handoff.ts
+++ b/src/api/vram-handoff.ts
@@ -397,6 +397,13 @@ async function runHandoff(kind: 'image' | 'video', args: VramHandoffArgs): Promi
const alt = (args as Record<string, unknown>).input_image ?? (args as Record<string, unknown>).image
if (typeof alt === 'string' && alt) args.inputImage = alt
}
+ // Duration alias: models say duration / length / durationSeconds for `seconds`
+ // (gemma4 live passed {"duration": 4}). Normalize so resolveClip honors it.
+ if (args.seconds == null) {
+ const d = (args as Record<string, unknown>).duration ?? (args as Record<string, unknown>).length ?? (args as Record<string, unknown>).durationSeconds
+ const n = typeof d === 'number' ? d : Number(d)
+ if (Number.isFinite(n) && n > 0) args.seconds = n
+ }
let prompt = String(args.prompt ?? args.description ?? '').trim()
if (!prompt) {
// A video call (esp. image-to-video / SVD) can animate without an explicit
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index afce259c..f45b8d5a 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -22,7 +22,7 @@ import { getToolPermission, executeAgentTool, AGENT_TOOL_DEFS } from '../api/too
import { getToolCallingStrategy, type ToolCallingStrategy } from '../lib/model-compatibility'
import { log } from '../lib/logger'
import { buildHermesToolPrompt, buildHermesToolResult, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'
-import { parseLooseToolCalls, stripMatchedCalls } from '../lib/loose-tool-parse'
+import { parseLooseToolCalls, stripMatchedCalls, canonicalToolName } from '../lib/loose-tool-parse'
import { buildVisionFeedback } from '../api/vision-feedback'
import { compactMessages, getModelMaxTokens } from '../lib/context-compaction'
import { useMemoryStore } from '../stores/memoryStore'
@@ -670,6 +670,18 @@ export function useAgentChat() {
// preserved as a `reflection` block so it renders above the tool
// calls in chronological order. Only the final-turn content (no
// tool_calls) becomes the message body.
+ const knownToolNames = toolRegistry.getAll().map((t) => t.name)
+
+ // Canonicalize near-miss tool names (David 2026-06-03): gemma4 emitted a
+ // NATIVE call to `video_generation` (not `video_generate`) → "Unknown
+ // tool" → it gave up. Map such close misses to the registered name.
+ if (toolCalls.length > 0) {
+ toolCalls = toolCalls.map((tc) => ({
+ ...tc,
+ function: { ...tc.function, name: canonicalToolName(tc.function.name, knownToolNames) },
+ }))
+ }
+
// Loose tool-call fallback (David 2026-06-03): weak local models often
// WRITE the call into their answer text instead of using the structured
// tool_calls channel — gemma4:e4b answers in prose; qwen2.5-coder:14b
@@ -678,8 +690,7 @@ export function useAgentChat() {
// channel produced nothing, lift any recognizable call out of the
// content (known tool names only) and strip it from the visible prose.
if (toolCalls.length === 0 && turnContent.trim()) {
- const knownNames = toolRegistry.getAll().map((t) => t.name)
- const loose = parseLooseToolCalls(turnContent, knownNames)
+ const loose = parseLooseToolCalls(turnContent, knownToolNames)
if (loose.calls.length > 0) {
toolCalls = loose.calls.map((c) => ({ function: { name: c.name, arguments: c.arguments } }))
turnContent = stripMatchedCalls(turnContent, loose.matched)
diff --git a/src/lib/__tests__/loose-tool-parse.test.ts b/src/lib/__tests__/loose-tool-parse.test.ts
index a60a8710..e293d08f 100644
--- a/src/lib/__tests__/loose-tool-parse.test.ts
+++ b/src/lib/__tests__/loose-tool-parse.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { parseLooseToolCalls, stripMatchedCalls } from '../loose-tool-parse'
+import { parseLooseToolCalls, stripMatchedCalls, canonicalToolName } from '../loose-tool-parse'
const KNOWN = ['image_generate', 'video_generate', 'web_search', 'file_write']
@@ -89,6 +89,37 @@ describe('parseLooseToolCalls — safety (no false positives)', () => {
})
})
+describe('canonicalToolName — map near-miss tool names', () => {
+ const KN = ['image_generate', 'video_generate', 'web_search', 'web_fetch', 'file_read']
+
+ it('maps the exact miss gemma4 emitted live (video_generation → video_generate)', () => {
+ expect(canonicalToolName('video_generation', KN)).toBe('video_generate')
+ })
+
+ it('maps common generate_* / *_generation aliases', () => {
+ expect(canonicalToolName('image_generation', KN)).toBe('image_generate')
+ expect(canonicalToolName('generate_video', KN)).toBe('video_generate')
+ expect(canonicalToolName('generate_image', KN)).toBe('image_generate')
+ })
+
+ it('is punctuation/casing-insensitive (video-generate, VideoGenerate)', () => {
+ expect(canonicalToolName('video-generate', KN)).toBe('video_generate')
+ expect(canonicalToolName('VideoGenerate', KN)).toBe('video_generate')
+ })
+
+ it('passes exact names through unchanged', () => {
+ expect(canonicalToolName('image_generate', KN)).toBe('image_generate')
+ })
+
+ it('leaves a genuinely unknown tool unchanged (still errors downstream)', () => {
+ expect(canonicalToolName('teleport', KN)).toBe('teleport')
+ })
+
+ it('never maps an alias to a tool that is not registered', () => {
+ expect(canonicalToolName('video_generation', ['image_generate'])).toBe('video_generation')
+ })
+})
+
describe('stripMatchedCalls', () => {
it('removes the recognized call snippet from the prose', () => {
const txt = 'Okay, generating now: image_generate(prompt="a red cube")'
diff --git a/src/lib/loose-tool-parse.ts b/src/lib/loose-tool-parse.ts
index 7775f5a7..655c2941 100644
--- a/src/lib/loose-tool-parse.ts
+++ b/src/lib/loose-tool-parse.ts
@@ -159,6 +159,40 @@ export function parseLooseToolCalls(text: string, known: string[]): LooseParseRe
return { calls, matched }
}
+// Common near-miss tool names small models emit instead of the registered ones
+// (gemma4 live: called `video_generation` → "Unknown tool" → gave up). Maps to
+// the canonical builtin names. Only applied when the alias target is actually a
+// known/registered tool, so this never invents capabilities.
+const TOOL_NAME_ALIASES: Record<string, string> = {
+ image_generation: 'image_generate', generate_image: 'image_generate', imagegen: 'image_generate',
+ create_image: 'image_generate', make_image: 'image_generate', draw_image: 'image_generate', text_to_image: 'image_generate',
+ video_generation: 'video_generate', generate_video: 'video_generate', videogen: 'video_generate',
+ create_video: 'video_generate', make_video: 'video_generate', animate: 'video_generate', animate_image: 'video_generate',
+ text_to_video: 'video_generate', image_to_video: 'video_generate',
+ web: 'web_search', search: 'web_search', fetch: 'web_fetch', read_file: 'file_read', write_file: 'file_write',
+ list_files: 'file_list', search_files: 'file_search', run_shell: 'shell_execute', run_code: 'code_execute',
+}
+
+/**
+ * Map a model-emitted tool name to a registered one. Tries exact, lowercase,
+ * an explicit alias table, then a punctuation-insensitive equality. Returns the
+ * original name unchanged when no confident match exists (so genuinely unknown
+ * tools still error rather than being silently rerouted).
+ */
+export function canonicalToolName(name: string, known: string[]): string {
+ if (!name) return name
+ if (known.includes(name)) return name
+ const lc = name.toLowerCase()
+ if (known.includes(lc)) return lc
+ const alias = TOOL_NAME_ALIASES[lc]
+ if (alias && known.includes(alias)) return alias
+ // Punctuation/casing-insensitive equality (videoGenerate, video-generate…).
+ const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]/g, '')
+ const target = norm(name)
+ for (const k of known) if (norm(k) === target) return k
+ return name
+}
+
/** Remove the matched call snippets from a prose answer (best-effort). */
export function stripMatchedCalls(text: string, matched: string[]): string {
let out = text