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+
import React, {useEffect, useState} from 'react';
|
| 7 |
+
|
| 8 |
+
interface ParametersPanelProps {
|
| 9 |
+
currentLength: number;
|
| 10 |
+
onUpdateHistoryLength: (newLength: number) => void; // Renamed for clarity
|
| 11 |
+
onClosePanel: () => void;
|
| 12 |
+
isStatefulnessEnabled: boolean;
|
| 13 |
+
onSetStatefulness: (enabled: boolean) => void; // Changed to accept a boolean
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const ParametersPanel: React.FC<ParametersPanelProps> = ({
|
| 17 |
+
currentLength,
|
| 18 |
+
onUpdateHistoryLength,
|
| 19 |
+
onClosePanel,
|
| 20 |
+
isStatefulnessEnabled,
|
| 21 |
+
onSetStatefulness,
|
| 22 |
+
}) => {
|
| 23 |
+
// Local state for pending changes
|
| 24 |
+
const [localHistoryLengthInput, setLocalHistoryLengthInput] =
|
| 25 |
+
useState<string>(currentLength.toString());
|
| 26 |
+
const [localStatefulnessChecked, setLocalStatefulnessChecked] =
|
| 27 |
+
useState<boolean>(isStatefulnessEnabled);
|
| 28 |
+
|
| 29 |
+
// Update local state if props change (e.g., panel re-opened)
|
| 30 |
+
useEffect(() => {
|
| 31 |
+
setLocalHistoryLengthInput(currentLength.toString());
|
| 32 |
+
}, [currentLength]);
|
| 33 |
+
|
| 34 |
+
useEffect(() => {
|
| 35 |
+
setLocalStatefulnessChecked(isStatefulnessEnabled);
|
| 36 |
+
}, [isStatefulnessEnabled]);
|
| 37 |
+
|
| 38 |
+
const handleHistoryLengthInputChange = (
|
| 39 |
+
event: React.ChangeEvent<HTMLInputElement>,
|
| 40 |
+
) => {
|
| 41 |
+
setLocalHistoryLengthInput(event.target.value);
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const handleStatefulnessCheckboxChange = (
|
| 45 |
+
event: React.ChangeEvent<HTMLInputElement>,
|
| 46 |
+
) => {
|
| 47 |
+
setLocalStatefulnessChecked(event.target.checked);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
const handleApplyParameters = () => {
|
| 51 |
+
// Apply history length
|
| 52 |
+
const newLength = parseInt(localHistoryLengthInput, 10);
|
| 53 |
+
if (!isNaN(newLength) && newLength >= 0 && newLength <= 10) {
|
| 54 |
+
onUpdateHistoryLength(newLength);
|
| 55 |
+
} else {
|
| 56 |
+
alert('Please enter a number between 0 and 10 for history length.');
|
| 57 |
+
setLocalHistoryLengthInput(currentLength.toString()); // Revert local input to original prop on error
|
| 58 |
+
return; // Do not proceed to close if there's an error
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// Apply statefulness if it has changed
|
| 62 |
+
if (localStatefulnessChecked !== isStatefulnessEnabled) {
|
| 63 |
+
onSetStatefulness(localStatefulnessChecked);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
onClosePanel(); // Close the panel after applying settings
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
const handleClose = () => {
|
| 70 |
+
// Reset local state to reflect original props before closing, ensuring no pending changes carry over visually if panel is quickly reopened
|
| 71 |
+
setLocalHistoryLengthInput(currentLength.toString());
|
| 72 |
+
setLocalStatefulnessChecked(isStatefulnessEnabled);
|
| 73 |
+
onClosePanel();
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
return (
|
| 77 |
+
<div className="p-6 bg-gray-50 h-full flex flex-col items-start pt-8">
|
| 78 |
+
{/* Interaction History Row */}
|
| 79 |
+
<div className="w-full max-w-md mb-6">
|
| 80 |
+
<div className="llm-row items-center">
|
| 81 |
+
<label
|
| 82 |
+
htmlFor="maxHistoryLengthInput"
|
| 83 |
+
className="llm-label whitespace-nowrap mr-3 flex-shrink-0"
|
| 84 |
+
style={{minWidth: '150px'}}>
|
| 85 |
+
Max History Length:
|
| 86 |
+
</label>
|
| 87 |
+
<input
|
| 88 |
+
type="number"
|
| 89 |
+
id="maxHistoryLengthInput"
|
| 90 |
+
value={localHistoryLengthInput}
|
| 91 |
+
onChange={handleHistoryLengthInputChange}
|
| 92 |
+
min="0"
|
| 93 |
+
max="10"
|
| 94 |
+
className="llm-input flex-grow"
|
| 95 |
+
aria-describedby="historyLengthHelpText"
|
| 96 |
+
/>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
|
| 100 |
+
{/* Statefulness Row */}
|
| 101 |
+
<div className="w-full max-w-md mb-4">
|
| 102 |
+
<div className="llm-row items-center">
|
| 103 |
+
<label
|
| 104 |
+
htmlFor="statefulnessCheckbox"
|
| 105 |
+
className="llm-label whitespace-nowrap mr-3 flex-shrink-0"
|
| 106 |
+
style={{minWidth: '150px'}}>
|
| 107 |
+
Enable Statefulness:
|
| 108 |
+
</label>
|
| 109 |
+
<input
|
| 110 |
+
type="checkbox"
|
| 111 |
+
id="statefulnessCheckbox"
|
| 112 |
+
checked={localStatefulnessChecked}
|
| 113 |
+
onChange={handleStatefulnessCheckboxChange}
|
| 114 |
+
className="h-5 w-5 text-blue-600 border-gray-300 rounded focus:ring-blue-500 cursor-pointer"
|
| 115 |
+
aria-describedby="statefulnessHelpText"
|
| 116 |
+
/>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
{/* Action Buttons */}
|
| 121 |
+
<div className="mt-6 w-full max-w-md flex justify-start gap-3">
|
| 122 |
+
{' '}
|
| 123 |
+
{/* Changed pt-2 to mt-6, justify-end to justify-start */}
|
| 124 |
+
<button
|
| 125 |
+
onClick={handleApplyParameters}
|
| 126 |
+
className="llm-button"
|
| 127 |
+
aria-label="Apply all parameter settings and close">
|
| 128 |
+
Apply Parameters
|
| 129 |
+
</button>
|
| 130 |
+
<button
|
| 131 |
+
onClick={handleClose}
|
| 132 |
+
className="llm-button bg-gray-500 hover:bg-gray-600 active:bg-gray-700"
|
| 133 |
+
aria-label="Close parameters panel without applying current changes">
|
| 134 |
+
Close Parameters
|
| 135 |
+
</button>
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
);
|
| 139 |
+
};
|