@@ -5,8 +5,8 @@ import { isExternalFileDrag } from '@src/components/Explorer/utils'
55import Loading from '@src/components/Loading'
66import { MakeathonAnnouncement } from '@src/components/MakeathonAnnouncement'
77import Tooltip from '@src/components/Tooltip'
8- import { ViewportAnnotationOverlay } from '@src/components/ViewportAnnotationOverlay'
98import { noAutofillInputProps } from '@src/lib/autofill'
9+ import { useApp } from '@src/lib/boot'
1010import { dataUrlToFile , takeViewportScreenshot } from '@src/lib/screenshot'
1111import { err } from '@src/lib/trap'
1212import { isNonNullable } from '@src/lib/utils'
@@ -17,8 +17,12 @@ import type {
1717 MlCopilotModeOption ,
1818} from '@src/machines/mlEphantManagerMachine'
1919import type { Selections } from '@src/machines/modelingSharedTypes'
20+ import {
21+ activateZoodleRuntimeExtension ,
22+ deactivateZoodleRuntimeExtension ,
23+ } from '@src/registry/extensions/engineScene/zoodleRuntimeExtension'
2024import type { ChangeEvent , ReactNode } from 'react'
21- import { useEffect , useRef , useState } from 'react'
25+ import { useCallback , useEffect , useRef , useState } from 'react'
2226
2327const noop = ( ) => { }
2428
@@ -263,6 +267,7 @@ interface MlEphantConversationInputProps {
263267export const MlEphantConversationInput = (
264268 props : MlEphantConversationInputProps
265269) => {
270+ const { registry } = useApp ( )
266271 const refDiv = useRef < HTMLTextAreaElement > ( null )
267272 const fileInputRef = useRef < HTMLInputElement > ( null )
268273 const [ value , setValue ] = useState < string > ( '' )
@@ -273,9 +278,22 @@ export const MlEphantConversationInput = (
273278 const lastModeScopeKey = useRef ( props . modeScopeKey )
274279 const [ attachments , setAttachments ] = useState < File [ ] > ( [ ] )
275280 const [ isDraggingOver , setIsDraggingOver ] = useState ( false )
276- const [ annotationImageDataUrl , setAnnotationImageDataUrl ] = useState <
277- string | null
278- > ( null )
281+ const zoodleRuntimeExtensionActive = useRef ( false )
282+
283+ const stopZoodleRuntimeExtension = useCallback ( ( ) => {
284+ if ( ! zoodleRuntimeExtensionActive . current ) {
285+ return
286+ }
287+
288+ zoodleRuntimeExtensionActive . current = false
289+ deactivateZoodleRuntimeExtension ( registry )
290+ } , [ registry ] )
291+
292+ useEffect ( ( ) => {
293+ return ( ) => {
294+ stopZoodleRuntimeExtension ( )
295+ }
296+ } , [ stopZoodleRuntimeExtension ] )
279297
280298 // Without this the cursor ends up at the start of the text
281299 useEffect ( ( ) => setValue ( props . defaultPrompt || '' ) , [ props . defaultPrompt ] )
@@ -395,7 +413,18 @@ export const MlEphantConversationInput = (
395413 try {
396414 const dataUrl = takeViewportScreenshot ( )
397415 if ( ! dataUrl ) return
398- setAnnotationImageDataUrl ( dataUrl )
416+ zoodleRuntimeExtensionActive . current = true
417+ activateZoodleRuntimeExtension ( registry , {
418+ imageDataUrl : dataUrl ,
419+ onCancel : stopZoodleRuntimeExtension ,
420+ onSend : ( annotatedDataUrl ) => {
421+ appendDataUrlAttachment (
422+ annotatedDataUrl ,
423+ 'annotated-viewport-screenshot.png'
424+ )
425+ stopZoodleRuntimeExtension ( )
426+ } ,
427+ } )
399428 } catch ( e ) {
400429 console . error ( 'Failed to capture viewport screenshot for annotation' , e )
401430 }
@@ -590,19 +619,6 @@ export const MlEphantConversationInput = (
590619 Zookeeper can make mistakes. We send selection context to help. Always
591620 verify information.
592621 </ div >
593- { annotationImageDataUrl && (
594- < ViewportAnnotationOverlay
595- imageDataUrl = { annotationImageDataUrl }
596- onCancel = { ( ) => setAnnotationImageDataUrl ( null ) }
597- onSend = { ( annotatedDataUrl ) => {
598- appendDataUrlAttachment (
599- annotatedDataUrl ,
600- 'annotated-viewport-screenshot.png'
601- )
602- setAnnotationImageDataUrl ( null )
603- } }
604- />
605- ) }
606622 </ div >
607623 )
608624}
0 commit comments