@@ -25,6 +25,11 @@ document.addEventListener('DOMContentLoaded', async function() {
2525 let detections = [ ] ;
2626 let detectionResults = { } ;
2727
28+ // VLM-aware client helper: routes through toggle when available
29+ function getVLMClient ( ) {
30+ if ( window . vlmToggle ) return window . vlmToggle . getClient ( ) ;
31+ return client ;
32+ }
2833 const detectionCanvas = document . getElementById ( 'detectionCanvas' ) ;
2934 const detectionCtx = detectionCanvas . getContext ( '2d' ) ;
3035 const detectionList = document . getElementById ( 'detectionList' ) ;
@@ -78,7 +83,7 @@ document.addEventListener('DOMContentLoaded', async function() {
7883
7984 // Initialize VLM Toggle
8085 window . vlmToggle = new VLMToggle ( {
81- containerSelector : '.control-panel h2 ' ,
86+ containerSelector : '.app-header h1 ' ,
8287 toolId : 'scene-describer' ,
8388 onChange : ( engine ) => {
8489 window . reasoningConsole . logInfo ( 'Switched to ' + engine + ' VLM' ) ;
@@ -169,9 +174,10 @@ document.addEventListener('DOMContentLoaded', async function() {
169174 }
170175
171176 async function describeScene ( ) {
172- if ( ! client ) {
177+ const activeClient = getVLMClient ( ) ;
178+ if ( ! activeClient ) {
173179 window . reasoningConsole . logError ( 'No API key configured' ) ;
174- updateStatus ( 'Please configure your Moondream API key' , 'error' ) ;
180+ updateStatus ( 'Please configure an API key' , 'error' ) ;
175181 window . apiKeyManager . showModal ( ) ;
176182 return ;
177183 }
@@ -187,7 +193,7 @@ document.addEventListener('DOMContentLoaded', async function() {
187193
188194 window . reasoningConsole . logApiCall ( '/describe' , 0 ) ;
189195
190- const result = await client . describeVideo ( video , { maxTokens } ) ;
196+ const result = await activeClient . describeVideo ( video , { maxTokens } ) ;
191197 const elapsed = Date . now ( ) - startTime ;
192198
193199 window . reasoningConsole . logSceneDescription ( result . description , elapsed ) ;
@@ -210,6 +216,7 @@ document.addEventListener('DOMContentLoaded', async function() {
210216 } ) ;
211217
212218 updateStatus ( `Described in ${ elapsed } ms` , 'success' ) ;
219+ VLMResultBadge . showCurrent ( elapsed ) ;
213220
214221 } catch ( error ) {
215222 window . reasoningConsole . logError ( error . message ) ;
@@ -233,9 +240,10 @@ document.addEventListener('DOMContentLoaded', async function() {
233240 return ;
234241 }
235242
236- if ( ! client ) {
243+ const activeClient = getVLMClient ( ) ;
244+ if ( ! activeClient ) {
237245 window . reasoningConsole . logError ( 'No API key configured' ) ;
238- updateStatus ( 'Please configure your Moondream API key' , 'error' ) ;
246+ updateStatus ( 'Please configure an API key' , 'error' ) ;
239247 window . apiKeyManager . showModal ( ) ;
240248 return ;
241249 }
@@ -250,7 +258,7 @@ document.addEventListener('DOMContentLoaded', async function() {
250258 try {
251259 window . reasoningConsole . logApiCall ( '/ask' , 0 ) ;
252260
253- const result = await client . askVideo ( video , question ) ;
261+ const result = await activeClient . askVideo ( video , question ) ;
254262 const elapsed = Date . now ( ) - startTime ;
255263
256264 window . reasoningConsole . logDecision ( 'Answer received' , `${ elapsed } ms` ) ;
@@ -282,6 +290,7 @@ document.addEventListener('DOMContentLoaded', async function() {
282290 } ) ;
283291
284292 updateStatus ( `Answered in ${ elapsed } ms` , 'success' ) ;
293+ VLMResultBadge . showCurrent ( elapsed ) ;
285294
286295 } catch ( error ) {
287296 window . reasoningConsole . logError ( error . message ) ;
@@ -492,9 +501,10 @@ document.addEventListener('DOMContentLoaded', async function() {
492501 }
493502
494503 async function runDetection ( ) {
495- if ( ! client ) {
504+ const activeClient = getVLMClient ( ) ;
505+ if ( ! activeClient ) {
496506 window . reasoningConsole . logError ( 'No API key configured' ) ;
497- updateStatus ( 'Please configure your Moondream API key' , 'error' ) ;
507+ updateStatus ( 'Please configure an API key' , 'error' ) ;
498508 window . apiKeyManager . showModal ( ) ;
499509 return ;
500510 }
@@ -513,7 +523,7 @@ document.addEventListener('DOMContentLoaded', async function() {
513523 try {
514524 const promises = activeDetections . map ( async ( detection ) => {
515525 try {
516- const result = await client . detectInVideo ( video , detection . target ) ;
526+ const result = await activeClient . detectInVideo ( video , detection . target ) ;
517527 detectionResults [ detection . id ] = result ;
518528 window . reasoningConsole . logInfo ( `Detected ${ result . objects . length } "${ detection . target } "` ) ;
519529 return { id : detection . id , success : true , count : result . objects . length } ;
@@ -533,6 +543,7 @@ document.addEventListener('DOMContentLoaded', async function() {
533543
534544 updateStatus ( `Detected ${ totalObjects } object(s) across ${ successCount } target(s) in ${ elapsed } ms` , 'success' ) ;
535545 window . reasoningConsole . logDecision ( 'Detection complete' , `${ totalObjects } objects found in ${ elapsed } ms` ) ;
546+ VLMResultBadge . showCurrent ( elapsed ) ;
536547
537548 updateJsonOutput ( {
538549 type : 'object_detection' ,
0 commit comments