import { JupyterNotebook , PythonCodeHelper } from 'common/lib/utilities/Jupyter' ; declare namespace CustomFunctions { function setCustomFunctionInvoker ( invoker ) ; interface ICustomFunctionInvoker { invoke ( functionName , parameters , context ) : void ; } interface InvocationContext { onCanceled : ( ) => void ; functionName : string ; address : string ; setResult ( result ) : void ; } } export function initializeJupyter ( pythonConfig ) { const notebook = new JupyterNotebook ( { baseUrl : pythonConfig . url , token : pythonConfig . token , } , pythonConfig . notebook ) ; CustomFunctions . setCustomFunctionInvoker ( new JupyterCustomFunctionInvoker ( notebook ) ) ; } class JupyterCustomFunctionInvoker implements CustomFunctions . ICustomFunctionInvoker { constructor ( private _notebook ) { } invoke ( functionName , parameters , context ) { let code ; if ( functionName === 'code' ) { code = parameters [ 0 ] ; } else { code = PythonCodeHelper . buildFunctionInvokeStatement ( functionName , parameters ) ; } this . _notebook . executeCode ( code ) . then ( ( codeResult ) => { const value = PythonCodeHelper . parseFromPythonLiteral ( codeResult ) ; context . setResult ( value ) ; } ) ; } }