@@ -24,6 +24,7 @@ import { replace_saved_context_symbol } from '@/views/panel/backend/utils/replac
2424import { replace_selection_symbol } from '@/views/panel/backend/utils/replace-selection-symbol'
2525import { PanelProvider } from '@/views/panel/backend/panel-provider'
2626import { replace_skill_symbol } from '@/views/panel/backend/utils/replace-skill-symbol'
27+ import { replace_image_symbol } from '@/views/panel/backend/utils/replace-image-symbol'
2728import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
2829import { EditContextMessage } from '@/views/panel/types/messages'
2930import { dictionary } from '@shared/constants/dictionary'
@@ -364,6 +365,12 @@ export const handle_edit_context = async (
364365 skill_definitions += result . skill_definitions
365366 }
366367
368+ if ( processed_instructions . includes ( '#Image(' ) ) {
369+ processed_instructions = await replace_image_symbol ( {
370+ instruction : processed_instructions
371+ } )
372+ }
373+
367374 const is_prune_context = panel_provider . api_prompt_type == 'prune-context'
368375 const collected_files = await files_collector . collect_files ( {
369376 compact : is_prune_context
@@ -465,6 +472,29 @@ export const handle_edit_context = async (
465472 . get < string > ( 'editContextSystemInstructions' ) ||
466473 default_system_instructions
467474
475+ let user_content : any = content
476+
477+ if ( content . includes ( '<cwc-image>' ) ) {
478+ user_content = [ ]
479+ const parts = content . split ( / < c w c - i m a g e > ( [ \s \S ] * ?) < \/ c w c - i m a g e > / )
480+
481+ for ( let i = 0 ; i < parts . length ; i ++ ) {
482+ const part = parts [ i ]
483+ if ( i % 2 == 0 ) {
484+ if ( part . length > 0 ) {
485+ user_content . push ( { type : 'text' , text : part . trim ( ) } )
486+ }
487+ } else {
488+ user_content . push ( {
489+ type : 'image_url' ,
490+ image_url : {
491+ url : `data:image/png;base64,${ part } `
492+ }
493+ } )
494+ }
495+ }
496+ }
497+
468498 const messages = [
469499 ...( system_instructions
470500 ? [
@@ -476,7 +506,7 @@ export const handle_edit_context = async (
476506 : [ ] ) ,
477507 {
478508 role : 'user' ,
479- content
509+ content : user_content
480510 }
481511 ]
482512
0 commit comments