@@ -526,6 +526,42 @@ define(function (require, exports, module) {
526526 }
527527 }
528528
529+ function _getRequiredDataForAI ( message ) {
530+ // this is to get the currently live document that is being served in the live preview
531+ const editor = _getEditorAndValidate ( message . tagId ) ;
532+ if ( ! editor ) {
533+ return ;
534+ }
535+
536+ const range = _getElementRange ( editor , message . tagId ) ;
537+ if ( ! range ) {
538+ return ;
539+ }
540+
541+ const { startPos, endPos } = range ;
542+ // this is the actual source code for the element that we need to duplicate
543+ const text = editor . getTextBetween ( startPos , endPos ) ;
544+ const fileName = editor . document . file . name ;
545+ const filePath = editor . document . file . fullPath ;
546+
547+ const AIData = {
548+ editor : editor , // the editor instance that is being served in the live preview
549+ fileName : fileName ,
550+ filePath : filePath , // the complete absolute path
551+ tagId : message . tagId , // the data-brackets-id of the element which was selected for AI edit
552+ range : { startPos, endPos} , // the start and end position text in the source code for that element
553+ text : text , // the actual source code in between the start and the end pos
554+ prompt : message . prompt // the prompt that user typed
555+ } ;
556+
557+ return AIData ;
558+ }
559+
560+ function _editWithAI ( message ) {
561+ const AIData = _getRequiredDataForAI ( message ) ;
562+ // write the AI implementation here...@abose
563+ }
564+
529565 /**
530566 * This is the main function that is exported.
531567 * it will be called by LiveDevProtocol when it receives a message from RemoteFunctions.js
@@ -537,9 +573,11 @@ define(function (require, exports, module) {
537573 * {
538574 livePreviewEditEnabled: true,
539575 tagId: tagId,
540- delete || duplicate || livePreviewTextEdit: true
576+ delete || duplicate || livePreviewTextEdit || AISend : true
541577 undoLivePreviewOperation: true (this property is available only for undo operation)
542578
579+ prompt: prompt (only for AI)
580+
543581 sourceId: sourceId, (these are for move (drag & drop))
544582 targetId: targetId,
545583 insertAfter: boolean, (whether to insert after the target element)
@@ -569,6 +607,8 @@ define(function (require, exports, module) {
569607 _duplicateElementInSourceByTagId ( message . tagId ) ;
570608 } else if ( message . livePreviewTextEdit ) {
571609 _editTextInSource ( message ) ;
610+ } else if ( message . AISend ) {
611+ _editWithAI ( message ) ;
572612 }
573613 }
574614
0 commit comments