lisichatbot 1.4.5 → 1.4.6

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 +62 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -1930,6 +1930,42 @@ async function handleNext() {
1930
1930
  async function showNextStep() {
1931
1931
  const nextStep = flowData.flow[chatState.step];
1932
1932
 
1933
+ // ✅ NEW: Check if step should be displayed based on condition
1934
+ if (nextStep.shouldDisplay) {
1935
+ let shouldShow = false;
1936
+
1937
+ if (typeof nextStep.shouldDisplay === 'function') {
1938
+ // Custom function
1939
+ try {
1940
+ shouldShow = await nextStep.shouldDisplay(chatState.data);
1941
+ console.log(` 🔍 shouldDisplay function returned: ${shouldShow}`);
1942
+ } catch (error) {
1943
+ console.error('Error in shouldDisplay function:', error);
1944
+ shouldShow = false;
1945
+ }
1946
+ } else if (typeof nextStep.shouldDisplay === 'boolean') {
1947
+ // Simple boolean
1948
+ shouldShow = nextStep.shouldDisplay;
1949
+ console.log(` 🔍 shouldDisplay boolean: ${shouldShow}`);
1950
+ }
1951
+
1952
+ if (!shouldShow) {
1953
+ console.log(` ⏭️ Skipping step ${chatState.step} (shouldDisplay returned false)`);
1954
+ chatState.step++;
1955
+
1956
+ if (chatState.step >= flowData.flow.length) {
1957
+ handleCompletion();
1958
+ return;
1959
+ }
1960
+
1961
+ // Recursively check next step
1962
+ await showNextStep();
1963
+ return;
1964
+ }
1965
+
1966
+ console.log(` ✅ Displaying step ${chatState.step} (shouldDisplay returned true)`);
1967
+ }
1968
+
1933
1969
  if (nextStep.onStart) {
1934
1970
  try {
1935
1971
  const canStart = await nextStep.onStart(chatState.data);
@@ -2264,7 +2300,32 @@ function editStep(stepNumber) {
2264
2300
  console.log(` Clearing history from step ${stepNumber} forward...`);
2265
2301
  chatState.history = chatState.history.filter(h => h.step < stepNumber);
2266
2302
 
2267
- console.log(` Keeping ALL data intact for editing (no data deleted)`);
2303
+ // Find dependent steps (but don't clear anything)
2304
+ const editedStepField = flowData.flow[stepNumber]?.input?.field;
2305
+ console.log(` 🔗 Checking for steps dependent on: ${editedStepField}`);
2306
+
2307
+ if (editedStepField) {
2308
+ // Find all steps that depend on the edited step
2309
+ const dependentSteps = [];
2310
+ flowData.flow.forEach((step, index) => {
2311
+ if (index > stepNumber && step.dependsOn) {
2312
+ // Check if this step depends on the edited field
2313
+ const dependencies = Array.isArray(step.dependsOn) ? step.dependsOn : [step.dependsOn];
2314
+
2315
+ if (dependencies.includes(editedStepField)) {
2316
+ dependentSteps.push(index);
2317
+ console.log(` 🔗 Found dependent step ${index} (depends on ${editedStepField})`);
2318
+ }
2319
+ }
2320
+ });
2321
+
2322
+ if (dependentSteps.length > 0) {
2323
+ console.log(` ✅ ${dependentSteps.length} dependent steps will be re-shown after editing`);
2324
+ console.log(` ✅ All data, messages, and history kept intact`);
2325
+ }
2326
+ }
2327
+
2328
+ console.log(` ✅ Keeping ALL data, messages, and history intact for editing`);
2268
2329
  console.log(` Current data:`, chatState.data);
2269
2330
 
2270
2331
  console.log(` Calling goToStep(${stepNumber})...`);