lisichatbot 1.5.6 → 1.5.7
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/package.json +1 -1
- package/src/index.js +108 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1987,6 +1987,60 @@ async function handleNext() {
|
|
|
1987
1987
|
scrollToBottom();
|
|
1988
1988
|
}
|
|
1989
1989
|
|
|
1990
|
+
// ✅ NEW: Check if onNext wants to update steps by field name
|
|
1991
|
+
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
1992
|
+
console.log('🎯 onNext returned data to update steps by field name:', result.updateStepByField);
|
|
1993
|
+
|
|
1994
|
+
// Iterate through all field updates
|
|
1995
|
+
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
1996
|
+
const updates = result.updateStepByField[fieldName];
|
|
1997
|
+
|
|
1998
|
+
// Find the step with this field name
|
|
1999
|
+
const targetStepIndex = flowData.flow.findIndex(step =>
|
|
2000
|
+
step.input && step.input.field === fieldName
|
|
2001
|
+
);
|
|
2002
|
+
|
|
2003
|
+
if (targetStepIndex !== -1) {
|
|
2004
|
+
const targetStep = flowData.flow[targetStepIndex];
|
|
2005
|
+
console.log(` ✅ Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2006
|
+
|
|
2007
|
+
// Update the step's input properties
|
|
2008
|
+
if (updates.options !== undefined) {
|
|
2009
|
+
targetStep.input.options = updates.options;
|
|
2010
|
+
console.log(` → Updated options (${updates.options.length} items)`);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
if (updates.min !== undefined) {
|
|
2014
|
+
targetStep.input.min = updates.min;
|
|
2015
|
+
console.log(` → Updated min: ${updates.min}`);
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
if (updates.max !== undefined) {
|
|
2019
|
+
targetStep.input.max = updates.max;
|
|
2020
|
+
console.log(` → Updated max: ${updates.max}`);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
if (updates.selectedInputValueType !== undefined) {
|
|
2024
|
+
targetStep.input.selectedInputValueType = updates.selectedInputValueType;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
if (updates.selectedInputPrefix !== undefined) {
|
|
2028
|
+
targetStep.input.selectedInputPrefix = updates.selectedInputPrefix;
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
if (updates.selectedInputSuffix !== undefined) {
|
|
2032
|
+
targetStep.input.selectedInputSuffix = updates.selectedInputSuffix;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
if (updates.custom !== undefined) {
|
|
2036
|
+
targetStep.input.custom = updates.custom;
|
|
2037
|
+
}
|
|
2038
|
+
} else {
|
|
2039
|
+
console.warn(` ⚠️ No step found with field name "${fieldName}"`);
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
|
|
1990
2044
|
// ✅ NEW: Check if onNext wants to jump to a specific step
|
|
1991
2045
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
1992
2046
|
console.log(`🎯 onNext requested jump to step ${result.goToStep}`);
|
|
@@ -2265,6 +2319,60 @@ async function showNextStep() {
|
|
|
2265
2319
|
try {
|
|
2266
2320
|
const result = await nextStep.onStart(chatState.data);
|
|
2267
2321
|
|
|
2322
|
+
// ✅ NEW: Check if onStart wants to update steps by field name
|
|
2323
|
+
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
2324
|
+
console.log('🎯 onStart returned data to update steps by field name:', result.updateStepByField);
|
|
2325
|
+
|
|
2326
|
+
// Iterate through all field updates
|
|
2327
|
+
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
2328
|
+
const updates = result.updateStepByField[fieldName];
|
|
2329
|
+
|
|
2330
|
+
// Find the step with this field name
|
|
2331
|
+
const targetStepIndex = flowData.flow.findIndex(step =>
|
|
2332
|
+
step.input && step.input.field === fieldName
|
|
2333
|
+
);
|
|
2334
|
+
|
|
2335
|
+
if (targetStepIndex !== -1) {
|
|
2336
|
+
const targetStep = flowData.flow[targetStepIndex];
|
|
2337
|
+
console.log(` ✅ Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2338
|
+
|
|
2339
|
+
// Update the step's input properties
|
|
2340
|
+
if (updates.options !== undefined) {
|
|
2341
|
+
targetStep.input.options = updates.options;
|
|
2342
|
+
console.log(` → Updated options (${updates.options.length} items)`);
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
if (updates.min !== undefined) {
|
|
2346
|
+
targetStep.input.min = updates.min;
|
|
2347
|
+
console.log(` → Updated min: ${updates.min}`);
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
if (updates.max !== undefined) {
|
|
2351
|
+
targetStep.input.max = updates.max;
|
|
2352
|
+
console.log(` → Updated max: ${updates.max}`);
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
if (updates.selectedInputValueType !== undefined) {
|
|
2356
|
+
targetStep.input.selectedInputValueType = updates.selectedInputValueType;
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
if (updates.selectedInputPrefix !== undefined) {
|
|
2360
|
+
targetStep.input.selectedInputPrefix = updates.selectedInputPrefix;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
if (updates.selectedInputSuffix !== undefined) {
|
|
2364
|
+
targetStep.input.selectedInputSuffix = updates.selectedInputSuffix;
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
if (updates.custom !== undefined) {
|
|
2368
|
+
targetStep.input.custom = updates.custom;
|
|
2369
|
+
}
|
|
2370
|
+
} else {
|
|
2371
|
+
console.warn(` ⚠️ No step found with field name "${fieldName}"`);
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2268
2376
|
// ✅ NEW: Check if onStart returned data to update current step
|
|
2269
2377
|
if (result && typeof result === 'object' && result.updateCurrentStep) {
|
|
2270
2378
|
console.log('📝 onStart returned data to update current step:', result);
|