I changed the approach, and made it as SciTE tool.
This way, the selection process, and console writing, is handled internally by SciTE.
To do this you need to add the following to SciTEUser.properties (Adding_utilities_to_the_SciTE_Tools_menu)
#------------------------------------------------------------------------------
# 41 SciTE_AI_Assistant
command.41.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "D:\i\Pro\.AutoIT\SciTE_AI_Assistant\SciTE_AI_Assistant.au3"
command.subsystem.41.$(au3)=0
command.name.41.$(au3)=SciTE AI Assistant
command.shortcut.41.*.au3=F10
command.save.before.41.$(au3)=2
# command.replace.selection.41.$(au3)=1
command.quiet.41.$(au3)=0
command.input.41.$(au3)=$(CurrentSelection)
#------------------------------------------------------------------------------
#---------------------- Contex Menu -------------------------------------------
user.context.menu=\
||\
>>> SciTE AI Assistant <<< |1141|\
||\
Execute Selected Path|IDM_OPENSELECTED|\
#------------------------------------------------------------------------------
and make the necessary adjustments
e.g. in
command.41.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "D:\i\Pro\.AutoIT\SciTE_AI_Assistant\SciTE_AI_Assistant.au3"
your path for the d:\your\location\SciTE_AI_Assistant\SciTE_AI_Assistant.au3
You may need to adjust the 41 to the first tool number available to you.
in this case, change the >>> SciTE AI Assistant <<< |1141|\ as well in the Context Menu
After that, select the text in the SciTE, right-click and select 'instruction' from the context menu '>>> SciTE AI Assistant <<<'