lisichatbot 1.4.9 → 1.5.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +267 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.4.9",
3
+ "version": "1.5.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -198,6 +198,13 @@ function updateEditIcons() {
198
198
  const stepData = flowData.flow[stepNumber];
199
199
  const hasInput = stepData && !!stepData.input;
200
200
 
201
+ // ✅ NEW: Check if edit is disabled for this step
202
+ if (stepData && stepData.disableEdit === true) {
203
+ editIcon.style.setProperty('display', 'none', 'important');
204
+ console.log(` 🚫 Step ${stepNumber}: Icon HIDDEN (edit disabled)`);
205
+ return;
206
+ }
207
+
201
208
  if (chatState.completed) {
202
209
  editIcon.style.setProperty('display', 'none', 'important');
203
210
  console.log(` 🏁 Step ${stepNumber}: Icon HIDDEN (flow completed)`);
@@ -1214,6 +1221,23 @@ function handleCustomSelectClick(element, field, customConfig) {
1214
1221
  chatState.currentSelection = { field, value, name: optionName };
1215
1222
  console.log(' ✅ Regular option selected:', value);
1216
1223
  enableNextButton();
1224
+
1225
+ // ✅ NEW: Check if auto-advance is enabled for regular options (not custom)
1226
+ const currentStep = flowData.flow[chatState.step];
1227
+ if (currentStep.autoAdvance === true) {
1228
+ console.log(' ⚡ Auto-advance enabled - proceeding to next step');
1229
+
1230
+ // Add a small delay for visual feedback
1231
+ const delay = currentStep.autoAdvanceDelay || 500;
1232
+ console.log(` ⏱️ Waiting ${delay}ms before advancing`);
1233
+
1234
+ setTimeout(() => {
1235
+ if (elements.nextBtn && !elements.nextBtn.disabled) {
1236
+ console.log(' ▶️ Auto-advancing to next step');
1237
+ handleNext();
1238
+ }
1239
+ }, delay);
1240
+ }
1217
1241
  }
1218
1242
  }
1219
1243
 
@@ -1647,6 +1671,23 @@ function handleOptionClick(element, field, isSingleSelect, options) {
1647
1671
  chatState.currentSelection = { field, value, name: optionName };
1648
1672
 
1649
1673
  enableNextButton();
1674
+
1675
+ // ✅ NEW: Check if auto-advance is enabled
1676
+ const currentStep = flowData.flow[chatState.step];
1677
+ if (currentStep.autoAdvance === true) {
1678
+ console.log(' ⚡ Auto-advance enabled - proceeding to next step');
1679
+
1680
+ // Add a small delay for visual feedback
1681
+ const delay = currentStep.autoAdvanceDelay || 500;
1682
+ console.log(` ⏱️ Waiting ${delay}ms before advancing`);
1683
+
1684
+ setTimeout(() => {
1685
+ if (elements.nextBtn && !elements.nextBtn.disabled) {
1686
+ console.log(' ▶️ Auto-advancing to next step');
1687
+ handleNext();
1688
+ }
1689
+ }, delay);
1690
+ }
1650
1691
  }
1651
1692
 
1652
1693
  } else {
@@ -1842,11 +1883,113 @@ async function handleNext() {
1842
1883
  if (currentStep.onNext) {
1843
1884
  try {
1844
1885
  disableNextButton();
1845
- const canProceed = await currentStep.onNext(
1886
+ const result = await currentStep.onNext(
1846
1887
  chatState.currentSelection ? chatState.currentSelection.value : null,
1847
1888
  chatState.data
1848
1889
  );
1849
1890
 
1891
+ // ✅ NEW: Check if onNext wants to display a message in chat
1892
+ if (result && typeof result === 'object' && result.showMessage) {
1893
+ console.log('💬 onNext displaying message:', result.showMessage);
1894
+ addMessage(result.showMessage, 'bot', false, null);
1895
+ scrollToBottom();
1896
+ }
1897
+
1898
+ // ✅ NEW: Check if onNext returned data to update next step
1899
+ if (result && typeof result === 'object' && result.updateNextStep) {
1900
+ console.log('📝 onNext returned data to update next step:', result);
1901
+
1902
+ const nextStepIndex = chatState.step + 1;
1903
+ if (nextStepIndex < flowData.flow.length) {
1904
+ const nextStep = flowData.flow[nextStepIndex];
1905
+
1906
+ // ✅ NEW: Support for updating specific input by field name
1907
+ // Example: { updateNextStep: true, fuel: { options: [...] } }
1908
+ if (nextStep.input && nextStep.input.field) {
1909
+ const inputFieldName = nextStep.input.field;
1910
+
1911
+ // Check if result has a property matching the input field name
1912
+ if (result[inputFieldName]) {
1913
+ console.log(` ✅ Updating input properties for field "${inputFieldName}":`, result[inputFieldName]);
1914
+
1915
+ // Update nested properties
1916
+ if (result[inputFieldName].options !== undefined) {
1917
+ nextStep.input.options = result[inputFieldName].options;
1918
+ console.log(` → input.options updated with ${result[inputFieldName].options.length} items`);
1919
+ }
1920
+
1921
+ // Can also update other input properties
1922
+ if (result[inputFieldName].field !== undefined) {
1923
+ nextStep.input.field = result[inputFieldName].field;
1924
+ console.log(` → input.field updated to: ${result[inputFieldName].field}`);
1925
+ }
1926
+
1927
+ if (result[inputFieldName].selectedInputValueType !== undefined) {
1928
+ nextStep.input.selectedInputValueType = result[inputFieldName].selectedInputValueType;
1929
+ }
1930
+
1931
+ if (result[inputFieldName].selectedInputPrefix !== undefined) {
1932
+ nextStep.input.selectedInputPrefix = result[inputFieldName].selectedInputPrefix;
1933
+ }
1934
+
1935
+ if (result[inputFieldName].selectedInputSuffix !== undefined) {
1936
+ nextStep.input.selectedInputSuffix = result[inputFieldName].selectedInputSuffix;
1937
+ }
1938
+
1939
+ if (result[inputFieldName].custom !== undefined) {
1940
+ nextStep.input.custom = result[inputFieldName].custom;
1941
+ }
1942
+
1943
+ if (result[inputFieldName].min !== undefined) {
1944
+ nextStep.input.min = result[inputFieldName].min;
1945
+ }
1946
+
1947
+ if (result[inputFieldName].max !== undefined) {
1948
+ nextStep.input.max = result[inputFieldName].max;
1949
+ }
1950
+ }
1951
+ }
1952
+
1953
+ // ✅ LEGACY: Direct properties (backwards compatible)
1954
+ // Update options if provided
1955
+ if (result.options && nextStep.input) {
1956
+ console.log(` ✅ Updating step ${nextStepIndex} input.options (direct):`, result.options);
1957
+ nextStep.input.options = result.options;
1958
+ }
1959
+
1960
+ // ✅ Update field name if provided
1961
+ if (result.field && nextStep.input) {
1962
+ console.log(` ✅ Updating step ${nextStepIndex} field name: ${result.field}`);
1963
+ nextStep.input.field = result.field;
1964
+ }
1965
+
1966
+ // Update any other step properties if provided
1967
+ if (result.message) {
1968
+ console.log(` ✅ Updating step ${nextStepIndex} message:`, result.message);
1969
+ nextStep.message = result.message;
1970
+ }
1971
+
1972
+ if (result.inputType) {
1973
+ console.log(` ✅ Updating step ${nextStepIndex} inputType:`, result.inputType);
1974
+ nextStep.inputType = result.inputType;
1975
+ }
1976
+
1977
+ if (result.shouldDisplay !== undefined) {
1978
+ console.log(` ✅ Updating step ${nextStepIndex} shouldDisplay`);
1979
+ nextStep.shouldDisplay = result.shouldDisplay;
1980
+ }
1981
+
1982
+ if (result.dependsOn !== undefined) {
1983
+ console.log(` ✅ Updating step ${nextStepIndex} dependsOn:`, result.dependsOn);
1984
+ nextStep.dependsOn = result.dependsOn;
1985
+ }
1986
+ }
1987
+ }
1988
+
1989
+ // Check if onNext returned false to block progression
1990
+ const canProceed = result === undefined || result === true ||
1991
+ (typeof result === 'object' && result.canProceed !== false);
1992
+
1850
1993
  if (!canProceed) {
1851
1994
  enableNextButton();
1852
1995
  return;
@@ -2037,9 +2180,130 @@ async function showNextStep() {
2037
2180
 
2038
2181
  if (nextStep.onStart) {
2039
2182
  try {
2040
- const canStart = await nextStep.onStart(chatState.data);
2183
+ const result = await nextStep.onStart(chatState.data);
2184
+
2185
+ // ✅ NEW: Check if onStart returned data to update current step
2186
+ if (result && typeof result === 'object' && result.updateCurrentStep) {
2187
+ console.log('📝 onStart returned data to update current step:', result);
2188
+
2189
+ const currentStepIndex = chatState.step;
2190
+ const currentStep = flowData.flow[currentStepIndex];
2191
+
2192
+ // ✅ Support for updating specific input by field name
2193
+ if (currentStep.input && currentStep.input.field) {
2194
+ const inputFieldName = currentStep.input.field;
2195
+
2196
+ // Check if result has a property matching the input field name
2197
+ if (result[inputFieldName]) {
2198
+ console.log(` ✅ Updating current step input.${inputFieldName}:`, result[inputFieldName]);
2199
+
2200
+ // Update nested properties
2201
+ if (result[inputFieldName].options !== undefined) {
2202
+ currentStep.input.options = result[inputFieldName].options;
2203
+ console.log(` → input.options updated with ${result[inputFieldName].options.length} items`);
2204
+ }
2205
+
2206
+ if (result[inputFieldName].field !== undefined) {
2207
+ currentStep.input.field = result[inputFieldName].field;
2208
+ }
2209
+
2210
+ if (result[inputFieldName].selectedInputValueType !== undefined) {
2211
+ currentStep.input.selectedInputValueType = result[inputFieldName].selectedInputValueType;
2212
+ }
2213
+
2214
+ if (result[inputFieldName].selectedInputPrefix !== undefined) {
2215
+ currentStep.input.selectedInputPrefix = result[inputFieldName].selectedInputPrefix;
2216
+ }
2217
+
2218
+ if (result[inputFieldName].selectedInputSuffix !== undefined) {
2219
+ currentStep.input.selectedInputSuffix = result[inputFieldName].selectedInputSuffix;
2220
+ }
2221
+
2222
+ if (result[inputFieldName].custom !== undefined) {
2223
+ currentStep.input.custom = result[inputFieldName].custom;
2224
+ }
2225
+
2226
+ if (result[inputFieldName].min !== undefined) {
2227
+ currentStep.input.min = result[inputFieldName].min;
2228
+ }
2229
+
2230
+ if (result[inputFieldName].max !== undefined) {
2231
+ currentStep.input.max = result[inputFieldName].max;
2232
+ }
2233
+ }
2234
+ }
2235
+
2236
+ // ✅ Direct properties (backwards compatible)
2237
+ if (result.options && currentStep.input) {
2238
+ console.log(` ✅ Updating current step input.options (direct):`, result.options);
2239
+ currentStep.input.options = result.options;
2240
+ }
2241
+
2242
+ if (result.field && currentStep.input) {
2243
+ console.log(` ✅ Updating current step field name: ${result.field}`);
2244
+ currentStep.input.field = result.field;
2245
+ }
2246
+
2247
+ // Update step-level properties
2248
+ if (result.message) {
2249
+ console.log(` ✅ Updating current step message:`, result.message);
2250
+ currentStep.message = result.message;
2251
+ }
2252
+
2253
+ if (result.inputType) {
2254
+ console.log(` ✅ Updating current step inputType:`, result.inputType);
2255
+ currentStep.inputType = result.inputType;
2256
+ }
2257
+
2258
+ if (result.shouldDisplay !== undefined) {
2259
+ console.log(` ✅ Updating current step shouldDisplay`);
2260
+ currentStep.shouldDisplay = result.shouldDisplay;
2261
+ }
2262
+
2263
+ if (result.dependsOn !== undefined) {
2264
+ console.log(` ✅ Updating current step dependsOn:`, result.dependsOn);
2265
+ currentStep.dependsOn = result.dependsOn;
2266
+ }
2267
+
2268
+ if (result.autoAdvance !== undefined) {
2269
+ console.log(` ✅ Updating current step autoAdvance:`, result.autoAdvance);
2270
+ currentStep.autoAdvance = result.autoAdvance;
2271
+ }
2272
+
2273
+ if (result.autoAdvanceDelay !== undefined) {
2274
+ console.log(` ✅ Updating current step autoAdvanceDelay:`, result.autoAdvanceDelay);
2275
+ currentStep.autoAdvanceDelay = result.autoAdvanceDelay;
2276
+ }
2277
+ }
2278
+
2279
+ // ✅ NEW: Check if onStart wants to display a message in chat
2280
+ if (result && typeof result === 'object' && result.showMessage) {
2281
+ console.log('💬 onStart displaying message:', result.showMessage);
2282
+ addMessage(result.showMessage, 'bot', false, null);
2283
+ scrollToBottom();
2284
+ }
2285
+
2286
+ // ✅ NEW: Check if onStart wants to block this step and skip to next
2287
+ if (result && typeof result === 'object' && result.blockStep === true) {
2288
+ console.log('⏭️ Step blocked by onStart - skipping to next step');
2289
+ chatState.step++;
2290
+
2291
+ if (chatState.step >= flowData.flow.length) {
2292
+ handleCompletion();
2293
+ return;
2294
+ }
2295
+
2296
+ // Recursively show next step
2297
+ await showNextStep();
2298
+ return;
2299
+ }
2300
+
2301
+ // Check if onStart blocked the step (old behavior - stops flow)
2302
+ const canStart = result === undefined || result === true ||
2303
+ (typeof result === 'object' && result.canStart !== false);
2304
+
2041
2305
  if (!canStart) {
2042
- console.log('Step blocked');
2306
+ console.log('Step blocked by onStart - flow stopped');
2043
2307
  return;
2044
2308
  }
2045
2309
  } catch (error) {