Enable recipe deeplink parameters for pre-population (#5757)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Kai Lu
2025-12-03 07:45:25 -08:00
committed by GitHub
parent 039a845c42
commit 5d53643b61
8 changed files with 295 additions and 40 deletions
+4
View File
@@ -449,6 +449,10 @@ function BaseChatContent({
parameters={recipe.parameters}
onSubmit={setRecipeUserParams}
onClose={() => setView('chat')}
initialValues={
(window.appConfig?.get('recipeParameters') as Record<string, string> | undefined) ||
undefined
}
/>
)}
@@ -6,29 +6,31 @@ interface ParameterInputModalProps {
parameters: Parameter[];
onSubmit: (values: Record<string, string>) => void;
onClose: () => void;
initialValues?: Record<string, string>;
}
const ParameterInputModal: React.FC<ParameterInputModalProps> = ({
parameters,
onSubmit,
onClose,
initialValues,
}) => {
const [inputValues, setInputValues] = useState<Record<string, string>>({});
const [validationErrors, setValidationErrors] = useState<Record<string, string>>({});
const [showCancelOptions, setShowCancelOptions] = useState(false);
// Pre-fill the form with default values from the recipe
// Pre-fill the form with default values from the recipe and initialValues from deeplink
useEffect(() => {
const initialValues: Record<string, string> = {};
const defaultValues: Record<string, string> = {};
parameters.forEach((param) => {
if (param.requirement === 'optional' && param.default) {
const defaultValue =
defaultValues[param.key] =
param.input_type === 'boolean' ? param.default.toLowerCase() : param.default;
initialValues[param.key] = defaultValue;
}
});
setInputValues(initialValues);
}, [parameters]);
setInputValues({ ...defaultValues, ...initialValues });
}, [parameters, initialValues]);
const handleChange = (name: string, value: string): void => {
setInputValues((prevValues: Record<string, string>) => ({ ...prevValues, [name]: value }));