@innovastudio/contentbox 1.6.101 → 1.6.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/package.json +2 -2
- package/public/contentbox/contentbox.esm.js +513 -19
- package/public/contentbox/contentbox.min.js +15 -15
- package/readme.txt +26 -6
@@ -31396,9 +31396,10 @@ class Util$1 {
|
|
31396
31396
|
const dom = this.dom;
|
31397
31397
|
pop.style.display = '';
|
31398
31398
|
dom.removeClass(pop, 'active');
|
31399
|
-
|
31400
|
-
|
31401
|
-
//
|
31399
|
+
|
31400
|
+
// this.builder.doc.activeElement.blur();
|
31401
|
+
// document.activeElement.blur();
|
31402
|
+
this.builder.doc.body.focus();
|
31402
31403
|
pop.setAttribute('aria-hidden', true);
|
31403
31404
|
|
31404
31405
|
// pop.removeEventListener('keydown', this.handlePopKeyDown);
|
@@ -76259,10 +76260,13 @@ class Module {
|
|
76259
76260
|
let btnOk = moduleModal.querySelector('.input-ok');
|
76260
76261
|
dom.addEventListener(btnOk, 'click', () => {
|
76261
76262
|
let modalIframe = moduleModal.querySelector('iframe');
|
76262
|
-
if (modalIframe.contentWindow.construct) modalIframe.contentWindow.construct();
|
76263
|
+
if (modalIframe.contentWindow.construct) modalIframe.contentWindow.construct(); // transfer module code to hidContentModuleCode & hidContentModuleSettings for saving
|
76264
|
+
|
76263
76265
|
this.builder.uo.saveForUndo();
|
76264
76266
|
let module = this.builder.activeModule;
|
76265
76267
|
|
76268
|
+
// The saving (saved in data attributes)
|
76269
|
+
|
76266
76270
|
//Save Html (original)
|
76267
76271
|
module.setAttribute('data-html', encodeURIComponent(builderStuff.querySelector('#hidContentModuleCode').value));
|
76268
76272
|
|
@@ -76468,6 +76472,7 @@ class Module {
|
|
76468
76472
|
class Code {
|
76469
76473
|
constructor(builder) {
|
76470
76474
|
this.builder = builder;
|
76475
|
+
this.renderTool();
|
76471
76476
|
}
|
76472
76477
|
renderTool() {
|
76473
76478
|
const builderStuff = this.builder.builderStuff;
|
@@ -78138,6 +78143,8 @@ class RowTool {
|
|
78138
78143
|
constructor(builder) {
|
78139
78144
|
this.builder = builder;
|
78140
78145
|
this.grid = new Grid(builder); // a must (also for ContentBox's command.js)
|
78146
|
+
|
78147
|
+
this.renderRowMore();
|
78141
78148
|
}
|
78142
78149
|
|
78143
78150
|
// Render row & column tools on each row
|
@@ -80032,6 +80039,7 @@ class ColumnTool {
|
|
80032
80039
|
});
|
80033
80040
|
});
|
80034
80041
|
}
|
80042
|
+
this.renderColMore();
|
80035
80043
|
}
|
80036
80044
|
renderColMore() {
|
80037
80045
|
const builder = this.builder;
|
@@ -112984,6 +112992,7 @@ ${answer}
|
|
112984
112992
|
let temperature = localStorage.getItem('_temp') || this.builder.temperature;
|
112985
112993
|
let topP = localStorage.getItem('_top_p') || this.builder.topP;
|
112986
112994
|
let num = 1;
|
112995
|
+
if (this.builder.settings.onStartRequest) this.builder.settings.onStartRequest();
|
112987
112996
|
const messages = {
|
112988
112997
|
question,
|
112989
112998
|
context,
|
@@ -112991,8 +113000,12 @@ ${answer}
|
|
112991
113000
|
functs,
|
112992
113001
|
temperature,
|
112993
113002
|
topP,
|
112994
|
-
num
|
113003
|
+
num,
|
113004
|
+
metadata: this.builder.settings.metadata || {}
|
112995
113005
|
};
|
113006
|
+
|
113007
|
+
// console.log(messages);
|
113008
|
+
|
112996
113009
|
try {
|
112997
113010
|
/*
|
112998
113011
|
const response = await fetch(this.builder.sendCommandUrl, {
|
@@ -123884,6 +123897,7 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
|
|
123884
123897
|
}
|
123885
123898
|
this.ai_width = width;
|
123886
123899
|
this.ai_height = height;
|
123900
|
+
if (this.settings.onStartRequest) this.settings.onStartRequest();
|
123887
123901
|
const messages = {
|
123888
123902
|
model,
|
123889
123903
|
prompt: prompt,
|
@@ -123894,8 +123908,12 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
|
|
123894
123908
|
guidance,
|
123895
123909
|
scheduler,
|
123896
123910
|
output_format: 'jpeg',
|
123897
|
-
folder_path: ''
|
123911
|
+
folder_path: '',
|
123912
|
+
metadata: this.settings.metadata || {}
|
123898
123913
|
};
|
123914
|
+
|
123915
|
+
// console.log(messages);
|
123916
|
+
|
123899
123917
|
try {
|
123900
123918
|
let url = this.textToImageUrl;
|
123901
123919
|
let headers = {
|
@@ -146742,7 +146760,285 @@ class Lib {
|
|
146742
146760
|
description: 'User requests to add a new section with 4 boxes.'
|
146743
146761
|
}
|
146744
146762
|
},
|
146745
|
-
required: [
|
146763
|
+
required: []
|
146764
|
+
}
|
146765
|
+
}];
|
146766
|
+
}
|
146767
|
+
|
146768
|
+
getFunctionsInitial() {
|
146769
|
+
return [{
|
146770
|
+
name: 'get_intent',
|
146771
|
+
description: 'analyze user command to modify or create section/content',
|
146772
|
+
parameters: {
|
146773
|
+
type: 'object',
|
146774
|
+
properties: {
|
146775
|
+
new_section: {
|
146776
|
+
type: 'boolean',
|
146777
|
+
description: 'User requests to add a new section and not updating current section.'
|
146778
|
+
} // edit_section: {
|
146779
|
+
// type: 'boolean',
|
146780
|
+
// description: 'User provides section to edit, such as improve content or rewrite.',
|
146781
|
+
// },
|
146782
|
+
|
146783
|
+
},
|
146784
|
+
required: []
|
146785
|
+
}
|
146786
|
+
}];
|
146787
|
+
}
|
146788
|
+
|
146789
|
+
getFunctionsMore() {
|
146790
|
+
return [{
|
146791
|
+
name: 'get_intent',
|
146792
|
+
description: 'analyze user command to modify or create section/content',
|
146793
|
+
parameters: {
|
146794
|
+
type: 'object',
|
146795
|
+
properties: {
|
146796
|
+
asking_info: {
|
146797
|
+
type: 'boolean',
|
146798
|
+
description: 'User request an information.'
|
146799
|
+
},
|
146800
|
+
add_info: {
|
146801
|
+
// Without this, adding info will be considered as asking_info. Tha add_info should be the same as change_text
|
146802
|
+
type: 'boolean',
|
146803
|
+
description: 'User request an information to be added to the current content.'
|
146804
|
+
},
|
146805
|
+
// Add new Column or Block (in General Mode)
|
146806
|
+
add_column_or_block: {
|
146807
|
+
type: 'boolean',
|
146808
|
+
description: 'User requests to add a column or a block.'
|
146809
|
+
},
|
146810
|
+
change_text: {
|
146811
|
+
type: 'boolean',
|
146812
|
+
description: 'User explicitely requests to update text of the current content, rewrite, paraphrase, translate or change text.'
|
146813
|
+
},
|
146814
|
+
write_based_on_the_current_content: {
|
146815
|
+
type: 'boolean',
|
146816
|
+
description: 'User request to create new content based on the current content, such as to summarize, expand, make short, create a tweet or social media post, etc'
|
146817
|
+
},
|
146818
|
+
add_headline: {
|
146819
|
+
type: 'boolean',
|
146820
|
+
description: 'If requested to add a headline.'
|
146821
|
+
},
|
146822
|
+
add_paragraph: {
|
146823
|
+
type: 'boolean',
|
146824
|
+
description: 'If requested to add a paragraph.'
|
146825
|
+
},
|
146826
|
+
add_space: {
|
146827
|
+
type: 'boolean',
|
146828
|
+
description: 'If requested to add a space.'
|
146829
|
+
},
|
146830
|
+
add_button: {
|
146831
|
+
type: 'boolean',
|
146832
|
+
description: 'If requested to add a button.'
|
146833
|
+
},
|
146834
|
+
add_youtube: {
|
146835
|
+
type: 'boolean',
|
146836
|
+
description: 'If requested to add a youtube/vimeo video.'
|
146837
|
+
},
|
146838
|
+
add_video: {
|
146839
|
+
type: 'boolean',
|
146840
|
+
description: 'If requested to add a video.'
|
146841
|
+
},
|
146842
|
+
add_audio: {
|
146843
|
+
type: 'boolean',
|
146844
|
+
description: 'If requested to add an audio.'
|
146845
|
+
},
|
146846
|
+
add_map: {
|
146847
|
+
type: 'boolean',
|
146848
|
+
description: 'If requested to add a google map.'
|
146849
|
+
},
|
146850
|
+
add_code: {
|
146851
|
+
type: 'boolean',
|
146852
|
+
description: 'If requested to add a custom code block.'
|
146853
|
+
},
|
146854
|
+
add_article: {
|
146855
|
+
type: 'boolean',
|
146856
|
+
description: 'If requested to add an article.'
|
146857
|
+
},
|
146858
|
+
add_image: {
|
146859
|
+
type: 'string',
|
146860
|
+
description: 'User request to add image or gallery. Possible value: image, gallery'
|
146861
|
+
},
|
146862
|
+
add_list: {
|
146863
|
+
type: 'boolean',
|
146864
|
+
description: 'If requested to add a list (eg. features, benefits, or list of items to explain).'
|
146865
|
+
},
|
146866
|
+
add_list_with_image: {
|
146867
|
+
type: 'boolean',
|
146868
|
+
description: 'If requested to add a list with an image for each list item.'
|
146869
|
+
},
|
146870
|
+
add_list_with_icon: {
|
146871
|
+
type: 'boolean',
|
146872
|
+
description: 'If requested to add a list with an icon.'
|
146873
|
+
},
|
146874
|
+
add_list_with_number: {
|
146875
|
+
type: 'boolean',
|
146876
|
+
description: 'If requested to add a list with numbering.'
|
146877
|
+
},
|
146878
|
+
// freeform
|
146879
|
+
new_content: {
|
146880
|
+
type: 'boolean',
|
146881
|
+
description: 'User requests to add a new content.'
|
146882
|
+
},
|
146883
|
+
add_block: {
|
146884
|
+
type: 'boolean',
|
146885
|
+
description: 'User requests to add a block.'
|
146886
|
+
},
|
146887
|
+
|
146888
|
+
/*
|
146889
|
+
To make 2 columns not mixed with 2 boxes, each has to be identified separately
|
146890
|
+
*/
|
146891
|
+
redesign_layout: {
|
146892
|
+
type: 'boolean',
|
146893
|
+
description: 'If redesigning the layout is requested.'
|
146894
|
+
},
|
146895
|
+
change_style: {
|
146896
|
+
type: 'boolean',
|
146897
|
+
description: 'If changing element style is requested.'
|
146898
|
+
},
|
146899
|
+
change_font: {
|
146900
|
+
type: 'boolean',
|
146901
|
+
description: 'User requests to change font of the current section.'
|
146902
|
+
},
|
146903
|
+
change_section_height: {
|
146904
|
+
type: 'number',
|
146905
|
+
description: 'Requested height (percentage) of the section. Possible value: 10, 15, 20, 25, 30, 40, 50, 60, 70, 75, 80, 85, 90, 100'
|
146906
|
+
},
|
146907
|
+
section_background: {
|
146908
|
+
type: 'string',
|
146909
|
+
description: 'User request to add or remove section background that can be a background image, video or slider. Possible value: image, video, slider, remove'
|
146910
|
+
}
|
146911
|
+
},
|
146912
|
+
required: []
|
146913
|
+
}
|
146914
|
+
}];
|
146915
|
+
}
|
146916
|
+
|
146917
|
+
getFunctionsFinal() {
|
146918
|
+
return [{
|
146919
|
+
name: 'get_intent',
|
146920
|
+
description: 'categorize user intent',
|
146921
|
+
parameters: {
|
146922
|
+
type: 'object',
|
146923
|
+
properties: {
|
146924
|
+
change_color_individual_text: {
|
146925
|
+
type: 'boolean',
|
146926
|
+
description: 'User requests to change the color of a headline, paragraph of specific element/text.'
|
146927
|
+
},
|
146928
|
+
change_content_dark: {
|
146929
|
+
type: 'boolean',
|
146930
|
+
description: 'If requested to change text/content color to dark/black.'
|
146931
|
+
},
|
146932
|
+
change_content_light: {
|
146933
|
+
type: 'boolean',
|
146934
|
+
description: 'If requested to change text/content color to light/white.'
|
146935
|
+
},
|
146936
|
+
align_individual_text: {
|
146937
|
+
type: 'boolean',
|
146938
|
+
description: 'If requested to align an individual text/element, such as a headline, a paragraph, buttons, etc to left, center or right'
|
146939
|
+
},
|
146940
|
+
align_whole_content: {
|
146941
|
+
type: 'string',
|
146942
|
+
description: 'User requests to align the whole text/content. Possible value: left, center or right'
|
146943
|
+
},
|
146944
|
+
|
146945
|
+
/*
|
146946
|
+
// Block Mode (in General Mode)
|
146947
|
+
block_task: {
|
146948
|
+
type: 'string',
|
146949
|
+
description: 'User requests to move, duplicate, or delete block/row. Possible values: move-up, move-down, duplicate, remove'
|
146950
|
+
},
|
146951
|
+
column_task: {
|
146952
|
+
type: 'string',
|
146953
|
+
description: 'User requests to duplicate column, or delete column. Possible values: duplicate, remove'
|
146954
|
+
},
|
146955
|
+
move_column: {
|
146956
|
+
type: 'string',
|
146957
|
+
description: 'User requests to move column. Possible values: move-up, move-down, move-left, move-right'
|
146958
|
+
},
|
146959
|
+
increase_decrease_column: {
|
146960
|
+
type: 'string',
|
146961
|
+
description: 'User requests to increase/enlarge or decrease/reduce column size/width. Possible values: increase, decrease'
|
146962
|
+
},
|
146963
|
+
move_content_left: {
|
146964
|
+
type: 'boolean',
|
146965
|
+
description: 'Move content to the left',
|
146966
|
+
},
|
146967
|
+
move_content_center: {
|
146968
|
+
type: 'boolean',
|
146969
|
+
description: 'Move content to the center',
|
146970
|
+
},
|
146971
|
+
move_content_right: {
|
146972
|
+
type: 'boolean',
|
146973
|
+
description: 'Move content to the right',
|
146974
|
+
},
|
146975
|
+
move_content_top: {
|
146976
|
+
type: 'boolean',
|
146977
|
+
description: 'Move content to the top',
|
146978
|
+
},
|
146979
|
+
move_content_bottom: {
|
146980
|
+
type: 'boolean',
|
146981
|
+
description: 'Move content to the bottom',
|
146982
|
+
},
|
146983
|
+
*/
|
146984
|
+
content_width: {
|
146985
|
+
type: 'string',
|
146986
|
+
description: 'User requests to increase or decrease content width/size. Possible value: increase, decrease'
|
146987
|
+
},
|
146988
|
+
line_height_paragraph: {
|
146989
|
+
type: 'string',
|
146990
|
+
description: 'User requests to increase/decrease the line height of the paragraph. Possible value: increase, decrease'
|
146991
|
+
},
|
146992
|
+
line_height_individual_text: {
|
146993
|
+
type: 'boolean',
|
146994
|
+
description: 'User requests to increase/decrease the line height of an individual text/element (eg. headline).'
|
146995
|
+
},
|
146996
|
+
font_size_paragraph: {
|
146997
|
+
type: 'string',
|
146998
|
+
description: 'User requests to increase/decrease the font size of the paragraph. Possible value: increase, decrease'
|
146999
|
+
},
|
147000
|
+
font_size_individual_text: {
|
147001
|
+
type: 'boolean',
|
147002
|
+
description: 'User requests to increase/decrease the font size of an individual text/element (eg. headline).'
|
147003
|
+
}
|
147004
|
+
/*
|
147005
|
+
animation: {
|
147006
|
+
type: 'string',
|
147007
|
+
description: 'User requests to add animation. Possible value: fade-in, slide-up, zoom-in, remove'
|
147008
|
+
},
|
147009
|
+
section_task: {
|
147010
|
+
type: 'string',
|
147011
|
+
description: 'User requests to move, duplicate, or delet section. Possible values: move-up, move-top, move-down, move-bottom, duplicate, remove'
|
147012
|
+
},
|
147013
|
+
select_section: {
|
147014
|
+
type: 'string',
|
147015
|
+
description: 'User requests to select a section. Value can be: current, next, previous, first, last.'
|
147016
|
+
},
|
147017
|
+
select_block: {
|
147018
|
+
type: 'string',
|
147019
|
+
description: 'User requests to select a block. Value can be: block, headline, title, paragraph, image, next, previous, first, last'
|
147020
|
+
},
|
147021
|
+
unselect_block: {
|
147022
|
+
type: 'boolean',
|
147023
|
+
description: 'User requests to unselect block'
|
147024
|
+
},
|
147025
|
+
*/
|
147026
|
+
// Must be placed on the last for more precise
|
147027
|
+
// new_section_two_boxes: {
|
147028
|
+
// type: 'boolean',
|
147029
|
+
// description: 'User requests to add a new section with 2 boxes.'
|
147030
|
+
// },
|
147031
|
+
// new_section_three_boxes: {
|
147032
|
+
// type: 'boolean',
|
147033
|
+
// description: 'User requests to add a new section with 3 boxes.'
|
147034
|
+
// },
|
147035
|
+
// new_section_four_boxes: {
|
147036
|
+
// type: 'boolean',
|
147037
|
+
// description: 'User requests to add a new section with 4 boxes.'
|
147038
|
+
// },
|
147039
|
+
|
147040
|
+
},
|
147041
|
+
required: []
|
146746
147042
|
}
|
146747
147043
|
}];
|
146748
147044
|
}
|
@@ -147009,6 +147305,7 @@ Button Example:
|
|
147009
147305
|
|
147010
147306
|
isCanvasMode() {
|
147011
147307
|
let activeBox = this.builder.activeBox;
|
147308
|
+
if (!activeBox) return false;
|
147012
147309
|
let canvasMode = activeBox.classList.contains('box-canvas');
|
147013
147310
|
return canvasMode;
|
147014
147311
|
}
|
@@ -148355,7 +148652,8 @@ ${blockContent}
|
|
148355
148652
|
|
148356
148653
|
if (activeCol) {
|
148357
148654
|
// && numberOfIntents<=2) {
|
148358
|
-
// Update Column or Block (in General Mode)
|
148655
|
+
if (this.builder.consoleLog) console.log('branch block'); // Update Column or Block (in General Mode)
|
148656
|
+
|
148359
148657
|
if (args.align_individual_text || args.font_size_individual_text || args.line_height_individual_text) {
|
148360
148658
|
sendUpdateBlockCommand(question, args);
|
148361
148659
|
return;
|
@@ -148393,6 +148691,8 @@ ${blockContent}
|
|
148393
148691
|
if (container) currentContent = this.builder.editor.readHtml(container, false, false);
|
148394
148692
|
|
148395
148693
|
if (args.add_block || args.new_content || args.new_section || currentContent.trim() === '') {
|
148694
|
+
if (this.builder.consoleLog) console.log('branch 1');
|
148695
|
+
|
148396
148696
|
if (args.add_image === 'gallery') {
|
148397
148697
|
context = cl.new_section_with_gallery;
|
148398
148698
|
} else if (args.add_list_with_image) {
|
@@ -148422,6 +148722,7 @@ ${blockContent}
|
|
148422
148722
|
}
|
148423
148723
|
} else {
|
148424
148724
|
//if(args.redesign_layout || args.change_text || args.change_style || args.add_info) {
|
148725
|
+
if (this.builder.consoleLog) console.log('branch 2');
|
148425
148726
|
let currentHtml = '<div class="is-container">' + currentContent + '</div>';
|
148426
148727
|
let redesign_request = '';
|
148427
148728
|
|
@@ -148564,10 +148865,30 @@ ${currentHtml}
|
|
148564
148865
|
}
|
148565
148866
|
} // if(this.builder.sendCommandUrl==='') return;
|
148566
148867
|
|
148868
|
+
/*
|
148869
|
+
let response = await this.sendCommandSync('analyze',
|
148870
|
+
`This is the command: "${question}"`,
|
148871
|
+
'',
|
148872
|
+
'You will analyze the user\'s command and return what the user needs.',
|
148873
|
+
this.lib.getFunctionsInitial());
|
148874
|
+
const args1 = JSON.parse(response);
|
148875
|
+
response = await this.sendCommandSync('analyze',
|
148876
|
+
`This is the command: "${question}"`,
|
148877
|
+
'',
|
148878
|
+
'You will analyze the user\'s command and return what the user needs.',
|
148879
|
+
this.lib.getFunctionsMore());
|
148880
|
+
const args2 = JSON.parse(response);
|
148881
|
+
response = await this.sendCommandSync('analyze',
|
148882
|
+
`This is the command: "${question}"`,
|
148883
|
+
'',
|
148884
|
+
'You will analyze the user\'s command and return what the user needs.',
|
148885
|
+
this.lib.getFunctionsFinal());
|
148886
|
+
const args3 = JSON.parse(response);
|
148887
|
+
const args = { ...args1, ...args2, ...args3 };
|
148888
|
+
*/
|
148567
148889
|
|
148568
|
-
|
148569
|
-
|
148570
|
-
if (this.builder.consoleLog) console.log(args);
|
148890
|
+
|
148891
|
+
const processGeneralCommand = args => {
|
148571
148892
|
const canvasMode = this.isCanvasMode();
|
148572
148893
|
|
148573
148894
|
if (args.add_block && canvasMode) ; else {
|
@@ -148591,14 +148912,17 @@ ${currentHtml}
|
|
148591
148912
|
|
148592
148913
|
if (activeCol) {
|
148593
148914
|
// && numberOfIntents<=2) {
|
148594
|
-
// Update Column or Block (in General Mode)
|
148915
|
+
if (this.builder.consoleLog) console.log('branch block'); // Update Column or Block (in General Mode)
|
148916
|
+
|
148595
148917
|
if (args.align_individual_text || args.font_size_individual_text || args.line_height_individual_text) {
|
148918
|
+
if (this.builder.consoleLog) console.log('sendUpdateBlockCommand');
|
148596
148919
|
sendUpdateBlockCommand(question, args);
|
148597
148920
|
return;
|
148598
148921
|
} // Add new Column or Block (in General Mode)
|
148599
148922
|
|
148600
148923
|
|
148601
148924
|
if (args.add_column_or_block) {
|
148925
|
+
if (this.builder.consoleLog) console.log('sendBlockCommand');
|
148602
148926
|
sendBlockCommand(question);
|
148603
148927
|
return;
|
148604
148928
|
}
|
@@ -148606,7 +148930,8 @@ ${currentHtml}
|
|
148606
148930
|
|
148607
148931
|
|
148608
148932
|
if (activeBox && numberOfIntents === 1) {
|
148609
|
-
// Block Mode (in General Mode)
|
148933
|
+
if (this.builder.consoleLog) console.log('single intent'); // Block Mode (in General Mode)
|
148934
|
+
|
148610
148935
|
let result = this.blockAction(args);
|
148611
148936
|
|
148612
148937
|
if (result) {
|
@@ -148621,7 +148946,7 @@ ${currentHtml}
|
|
148621
148946
|
activeBox.setAttribute('data-selectbox',1);
|
148622
148947
|
this.section.sectionDuplicate();
|
148623
148948
|
activeBox.removeAttribute('data-selectbox');
|
148624
|
-
|
148949
|
+
this.builder.sectionStack();
|
148625
148950
|
const nextBox = this.builder.wrapperEl.querySelector('[data-selectbox]');
|
148626
148951
|
if(nextBox) {
|
148627
148952
|
nextBox.removeAttribute('data-selectbox');
|
@@ -148892,6 +149217,7 @@ ${currentHtml}
|
|
148892
149217
|
let context = '';
|
148893
149218
|
|
148894
149219
|
if (args.add_block && canvasMode) {
|
149220
|
+
if (this.builder.consoleLog) console.log('branch 1');
|
148895
149221
|
cl = cl2;
|
148896
149222
|
|
148897
149223
|
if (args.add_image === 'gallery') {
|
@@ -148934,7 +149260,11 @@ ${currentHtml}
|
|
148934
149260
|
context = context.replaceAll('{{_IMAGEURL}}', imageUrl);
|
148935
149261
|
}
|
148936
149262
|
} else if (args.new_section || args.new_section_two_boxes || args.new_section_three_boxes || args.new_section_four_boxes) {
|
149263
|
+
if (this.builder.consoleLog) console.log('branch 2');
|
149264
|
+
|
148937
149265
|
if (args.new_section) {
|
149266
|
+
if (this.builder.consoleLog) console.log('branch 2.1');
|
149267
|
+
|
148938
149268
|
if (args.add_image === 'gallery') {
|
148939
149269
|
context = cl.new_section_with_gallery;
|
148940
149270
|
} else if (args.add_list_with_image) {
|
@@ -148975,6 +149305,8 @@ ${currentHtml}
|
|
148975
149305
|
context = context.replaceAll('{{_IMAGEURL}}', imageUrl);
|
148976
149306
|
}
|
148977
149307
|
} else if (args.new_section_two_boxes || args.new_section_three_boxes || args.new_section_four_boxes) {
|
149308
|
+
if (this.builder.consoleLog) console.log('branch 2.2');
|
149309
|
+
|
148978
149310
|
if (args.new_section_two_boxes) {
|
148979
149311
|
context = cl.new_section_two_boxes;
|
148980
149312
|
} else if (args.new_section_three_boxes) {
|
@@ -149010,10 +149342,13 @@ ${currentHtml}
|
|
149010
149342
|
context = context.replaceAll('{{_IMAGEURL}}', imageUrl);
|
149011
149343
|
}
|
149012
149344
|
} else {
|
149345
|
+
if (this.builder.consoleLog) console.log('branch 2.3');
|
149013
149346
|
context = this.chooseContext(cl.new_section_article); // Or use: context = cl.new_section_others;
|
149014
149347
|
}
|
149015
149348
|
} else {
|
149016
149349
|
//if(args.redesign_layout || args.change_text || args.change_style || args.add_info) {
|
149350
|
+
if (this.builder.consoleLog) console.log('branch 3');
|
149351
|
+
|
149017
149352
|
if (!this.checkSelectedContent(activeBox)) {
|
149018
149353
|
this.dictation.finish(true);
|
149019
149354
|
return;
|
@@ -149077,13 +149412,16 @@ ${currentHtml}
|
|
149077
149412
|
|
149078
149413
|
|
149079
149414
|
question = `${redesign_request}${question}. Modify my section according to this instruction and returns the modified section HTML.
|
149415
|
+
Do not replace existing content unless requested.
|
149080
149416
|
|
149081
149417
|
This is my section:
|
149082
|
-
|
149418
|
+
|
149083
149419
|
${currentHtml}
|
149084
149420
|
`;
|
149085
149421
|
|
149086
149422
|
if (args.change_text) ; else {
|
149423
|
+
if (this.builder.consoleLog) console.log('branch 4');
|
149424
|
+
|
149087
149425
|
if ((args.add_headline || args.add_paragraph) && args.add_image === 'image') {
|
149088
149426
|
context += '\n' + cl.update_section_with_image;
|
149089
149427
|
} else if (args.add_image === 'gallery') {
|
@@ -149133,6 +149471,7 @@ ${currentHtml}
|
|
149133
149471
|
|
149134
149472
|
if (!(args.add_block && canvasMode || args.new_section || args.new_section_two_boxes || args.new_section_three_boxes || args.new_section_four_boxes)) {
|
149135
149473
|
// Redesign & Editing (text or style)
|
149474
|
+
if (this.builder.consoleLog) console.log('callback 1');
|
149136
149475
|
html = this.fixButtons(html);
|
149137
149476
|
html = this.fixCustomCode(html);
|
149138
149477
|
html = this.analyzeTitle(html, context); // Merge div.is-overlay-content
|
@@ -149176,7 +149515,10 @@ ${currentHtml}
|
|
149176
149515
|
this.renderResult(html);
|
149177
149516
|
} else {
|
149178
149517
|
// New Section
|
149518
|
+
if (this.builder.consoleLog) console.log('callback 2');
|
149519
|
+
|
149179
149520
|
if (args.add_block && canvasMode) {
|
149521
|
+
if (this.builder.consoleLog) console.log('callback 2.1');
|
149180
149522
|
html = this.fixHtml(html);
|
149181
149523
|
|
149182
149524
|
if (!html) {
|
@@ -149190,6 +149532,7 @@ ${currentHtml}
|
|
149190
149532
|
|
149191
149533
|
this.renderResult_Block(html);
|
149192
149534
|
} else {
|
149535
|
+
if (this.builder.consoleLog) console.log('callback 2.2');
|
149193
149536
|
html = this.fixButtons(html);
|
149194
149537
|
html = this.fixBgImage(html); // only if box has inline bg image, which is incorrect
|
149195
149538
|
|
@@ -149246,7 +149589,14 @@ ${currentHtml}
|
|
149246
149589
|
|
149247
149590
|
|
149248
149591
|
this.sendCommand('html', question, context, systemCmd, [], callback);
|
149249
|
-
}
|
149592
|
+
};
|
149593
|
+
|
149594
|
+
this.sendCommand('analyze', `This is the command: "${question}"`, '', 'You will analyze the user\'s command and return what the user needs.', this.lib.getFunctions(), response => {
|
149595
|
+
const args = JSON.parse(response);
|
149596
|
+
if (this.builder.consoleLog) console.log(args);
|
149597
|
+
processGeneralCommand(args);
|
149598
|
+
}); // console.log(args);
|
149599
|
+
// processGeneralCommand(args);
|
149250
149600
|
};
|
149251
149601
|
|
149252
149602
|
this.dictation.opts.send = question => {
|
@@ -149271,15 +149621,19 @@ ${currentHtml}
|
|
149271
149621
|
const activeBlock = this.activeBlock();
|
149272
149622
|
|
149273
149623
|
if (activeBlock) {
|
149274
|
-
// Special: If current box is a canvas and there is a selected block
|
149624
|
+
if (this.builder.consoleLog) console.log('sendGeneralCommand_CanvasMode'); // Special: If current box is a canvas and there is a selected block
|
149625
|
+
|
149275
149626
|
sendGeneralCommand_CanvasMode(question);
|
149276
149627
|
} else {
|
149277
149628
|
// Normal
|
149629
|
+
if (this.builder.consoleLog) console.log('sendGeneralCommand');
|
149278
149630
|
sendGeneralCommand(question);
|
149279
149631
|
}
|
149280
149632
|
} else if (this.builder.editor.assistantMode === 'others') {
|
149633
|
+
if (this.builder.consoleLog) console.log('sendOtherCommand');
|
149281
149634
|
sendOtherCommand(question);
|
149282
149635
|
} else if (this.builder.editor.assistantMode === 'block') {
|
149636
|
+
if (this.builder.consoleLog) console.log('sendBlockCommand');
|
149283
149637
|
sendBlockCommand(question);
|
149284
149638
|
}
|
149285
149639
|
};
|
@@ -150476,6 +150830,8 @@ ${currentHtml}
|
|
150476
150830
|
|
150477
150831
|
chooseContext(list, num) {
|
150478
150832
|
// random, but will be different from two previous results.
|
150833
|
+
console.log(list);
|
150834
|
+
|
150479
150835
|
if (typeof num !== 'undefined') {
|
150480
150836
|
return list[num];
|
150481
150837
|
}
|
@@ -151459,6 +151815,7 @@ ${currentHtml}
|
|
151459
151815
|
let temperature = localStorage.getItem('_temp') || this.builder.temperature;
|
151460
151816
|
let topP = localStorage.getItem('_top_p') || this.builder.topP;
|
151461
151817
|
let num = 1;
|
151818
|
+
if (this.builder.settings.onStartRequest) this.builder.settings.onStartRequest();
|
151462
151819
|
const messages = {
|
151463
151820
|
question,
|
151464
151821
|
context,
|
@@ -151466,8 +151823,9 @@ ${currentHtml}
|
|
151466
151823
|
functs,
|
151467
151824
|
temperature,
|
151468
151825
|
topP,
|
151469
|
-
num
|
151470
|
-
|
151826
|
+
num,
|
151827
|
+
metadata: this.builder.settings.metadata || {}
|
151828
|
+
}; // console.log(messages);
|
151471
151829
|
|
151472
151830
|
try {
|
151473
151831
|
/*
|
@@ -151580,8 +151938,143 @@ ${currentHtml}
|
|
151580
151938
|
}
|
151581
151939
|
}
|
151582
151940
|
|
151941
|
+
async sendCommandSync(mode, question, context, system, functs) {
|
151942
|
+
this.dictation.startSending(); // Shows sending status & Abort button
|
151943
|
+
|
151944
|
+
this.controller = new AbortController(); // Create a new AbortController
|
151945
|
+
|
151946
|
+
this.signal = this.controller.signal; // Get a new signal object
|
151947
|
+
|
151948
|
+
let temperature = localStorage.getItem('_temp') || this.builder.temperature;
|
151949
|
+
let topP = localStorage.getItem('_top_p') || this.builder.topP;
|
151950
|
+
let num = 1;
|
151951
|
+
const messages = {
|
151952
|
+
question,
|
151953
|
+
context,
|
151954
|
+
system,
|
151955
|
+
functs,
|
151956
|
+
temperature,
|
151957
|
+
topP,
|
151958
|
+
num
|
151959
|
+
};
|
151960
|
+
|
151961
|
+
try {
|
151962
|
+
/*
|
151963
|
+
const response = await fetch(this.builder.sendCommandUrl, {
|
151964
|
+
signal: this.signal, // Abort
|
151965
|
+
method: 'POST',
|
151966
|
+
headers: {
|
151967
|
+
'Content-Type': 'application/json',
|
151968
|
+
},
|
151969
|
+
body: JSON.stringify(messages),
|
151970
|
+
});
|
151971
|
+
const data = await response.json();
|
151972
|
+
*/
|
151973
|
+
let data;
|
151974
|
+
|
151975
|
+
if (this.builder.sendCommand) {
|
151976
|
+
data = await this.builder.sendCommand(messages);
|
151977
|
+
} else {
|
151978
|
+
let headers = { ...this.builder.headers,
|
151979
|
+
...this.builder.defaultHeaders
|
151980
|
+
};
|
151981
|
+
const response = await fetch(this.builder.sendCommandUrl, {
|
151982
|
+
signal: this.signal,
|
151983
|
+
// Abort
|
151984
|
+
method: 'POST',
|
151985
|
+
headers,
|
151986
|
+
body: JSON.stringify(messages)
|
151987
|
+
});
|
151988
|
+
data = await response.json();
|
151989
|
+
}
|
151990
|
+
|
151991
|
+
if (data.error) {
|
151992
|
+
// Error response from OpenAI goes here.
|
151993
|
+
console.log('Error:\n' + data.error); // ex. wrong API Key => Request failed with status code 401
|
151994
|
+
|
151995
|
+
this.builder.showMessage(out('Request failed.'));
|
151996
|
+
this.dictation.finish(); // Must be called after finished
|
151997
|
+
|
151998
|
+
return;
|
151999
|
+
}
|
152000
|
+
|
152001
|
+
if (mode === 'html') {
|
152002
|
+
// console.log(data.answer.usage);
|
152003
|
+
data.answer.choices.forEach(item => {
|
152004
|
+
let html = item.message.content;
|
152005
|
+
html = this.getHtmlResult(html);
|
152006
|
+
|
152007
|
+
if (!html) {
|
152008
|
+
this.builder.showMessage(out('Oops! The response received is insufficient. Please try again.'));
|
152009
|
+
this.dictation.finish(); // Must be called after finished
|
152010
|
+
|
152011
|
+
return;
|
152012
|
+
} // callback(html);
|
152013
|
+
|
152014
|
+
|
152015
|
+
return html;
|
152016
|
+
});
|
152017
|
+
} else if (mode === 'assistant') {
|
152018
|
+
data.answer.choices.forEach(item => {
|
152019
|
+
let answer = item.message.content; // callback(answer);
|
152020
|
+
|
152021
|
+
return answer;
|
152022
|
+
});
|
152023
|
+
} else {
|
152024
|
+
// mode===analyze
|
152025
|
+
|
152026
|
+
/*
|
152027
|
+
Handle Unrelated Request
|
152028
|
+
If OpenAI Function Call stopped (when user is asking unrelated things), it returns:
|
152029
|
+
{
|
152030
|
+
role: 'assistant',
|
152031
|
+
content: 'The user is asking for information.'
|
152032
|
+
}
|
152033
|
+
*/
|
152034
|
+
if (data.answer.role && data.answer.content) {
|
152035
|
+
// callback(JSON.stringify({new_section: true, others: true})); // Just create a new section
|
152036
|
+
// return;
|
152037
|
+
return JSON.stringify({
|
152038
|
+
new_section: true,
|
152039
|
+
others: true
|
152040
|
+
});
|
152041
|
+
} // callback(data.answer);
|
152042
|
+
|
152043
|
+
|
152044
|
+
return data.answer;
|
152045
|
+
}
|
152046
|
+
} catch (error) {
|
152047
|
+
if (error.name === 'AbortError') ; else {
|
152048
|
+
// CORS or code errors goes here
|
152049
|
+
console.error('Error:', error); // console.log('Error:\n'+error);
|
152050
|
+
|
152051
|
+
this.dictation.finish(); // Must be called after finished
|
152052
|
+
// Debug
|
152053
|
+
|
152054
|
+
if (this.builder.consoleLog) {
|
152055
|
+
if (!(error + '').includes('Failed to fetch')) {
|
152056
|
+
// Only if not CORS error
|
152057
|
+
let headers = { ...this.builder.headers,
|
152058
|
+
...this.builder.defaultHeaders
|
152059
|
+
};
|
152060
|
+
const response = await fetch(this.builder.sendCommandUrl, {
|
152061
|
+
method: 'POST',
|
152062
|
+
headers,
|
152063
|
+
body: JSON.stringify(messages)
|
152064
|
+
});
|
152065
|
+
const data = await response.text();
|
152066
|
+
console.log('Response:\n' + data); // Shows code error
|
152067
|
+
}
|
152068
|
+
}
|
152069
|
+
|
152070
|
+
this.builder.showMessage(out('Service Unavailable.'));
|
152071
|
+
}
|
152072
|
+
}
|
152073
|
+
}
|
152074
|
+
|
151583
152075
|
isCanvasMode() {
|
151584
152076
|
let activeBox = this.builder.activeBox;
|
152077
|
+
if (!activeBox) return false;
|
151585
152078
|
let canvasMode = activeBox.classList.contains('box-canvas');
|
151586
152079
|
return canvasMode;
|
151587
152080
|
}
|
@@ -159335,6 +159828,7 @@ Add an image for each feature.`, 'Create a new block showcasing a photo gallery
|
|
159335
159828
|
|
159336
159829
|
editorSetup() {
|
159337
159830
|
this.editor = new ContentBuilder({
|
159831
|
+
onStartRequest: this.settings.onStartRequest,
|
159338
159832
|
controlPanel: this.settings.controlPanel,
|
159339
159833
|
canvas: this.settings.canvas,
|
159340
159834
|
docContainer: this.settings.wrapper,
|