diff --git a/config/type_defs/catalog_types.py b/config/type_defs/catalog_types.py index e0d687b..b543870 100644 --- a/config/type_defs/catalog_types.py +++ b/config/type_defs/catalog_types.py @@ -4,7 +4,7 @@ CATALOG_TYPES = { "name": "Standard Catalog", "description": "A Catalog with information in Evie's Library, to be considered as a whole", }, - "TRAICIE_ROLE_DEFINITION_CATALOG": { + "TRAICIE_RQC": { "name": "Role Definition Catalog", "description": "A Catalog with information about roles, to be considered as a whole", "partner": "traicie" diff --git a/eveai_chat_client/static/assets/vue-components/DynamicForm.vue b/eveai_chat_client/static/assets/vue-components/DynamicForm.vue index 683d4c3..6e34867 100644 --- a/eveai_chat_client/static/assets/vue-components/DynamicForm.vue +++ b/eveai_chat_client/static/assets/vue-components/DynamicForm.vue @@ -155,10 +155,19 @@ export default { const fieldId = field.id || field.name; if (field.required) { const value = this.localFormValues[fieldId]; - if (value === undefined || value === null || - (typeof value === 'string' && !value.trim()) || - (Array.isArray(value) && value.length === 0)) { - missingFields.push(field.name); + // Voor boolean velden is false een geldige waarde + if (field.type === 'boolean') { + // Boolean velden zijn altijd geldig als ze een boolean waarde hebben + if (typeof value !== 'boolean') { + missingFields.push(field.name); + } + } else { + // Bestaande validatie voor andere veldtypen + if (value === undefined || value === null || + (typeof value === 'string' && !value.trim()) || + (Array.isArray(value) && value.length === 0)) { + missingFields.push(field.name); + } } } }); @@ -167,10 +176,19 @@ export default { Object.entries(this.formData.fields).forEach(([fieldId, field]) => { if (field.required) { const value = this.localFormValues[fieldId]; - if (value === undefined || value === null || - (typeof value === 'string' && !value.trim()) || - (Array.isArray(value) && value.length === 0)) { - missingFields.push(field.name); + // Voor boolean velden is false een geldige waarde + if (field.type === 'boolean') { + // Boolean velden zijn altijd geldig als ze een boolean waarde hebben + if (typeof value !== 'boolean') { + missingFields.push(field.name); + } + } else { + // Bestaande validatie voor andere veldtypen + if (value === undefined || value === null || + (typeof value === 'string' && !value.trim()) || + (Array.isArray(value) && value.length === 0)) { + missingFields.push(field.name); + } } } }); @@ -185,10 +203,23 @@ export default { // Gebruik een vlag om recursieve updates te voorkomen if (JSON.stringify(newValues) !== JSON.stringify(this.localFormValues)) { this.localFormValues = JSON.parse(JSON.stringify(newValues)); + // Proactief alle boolean velden corrigeren na externe wijziging + this.$nextTick(() => { + this.initializeBooleanFields(); + }); } }, deep: true }, + formData: { + handler() { + // Herinitialiseer boolean velden wanneer form structuur verandert + this.$nextTick(() => { + this.initializeBooleanFields(); + }); + }, + deep: true + }, localFormValues: { handler(newValues) { // Gebruik een vlag om recursieve updates te voorkomen @@ -202,53 +233,132 @@ export default { created() { // Icon loading is now handled automatically by useIconManager composable }, + mounted() { + // Proactief alle boolean velden initialiseren bij het laden + this.initializeBooleanFields(); + }, methods: { + // Proactieve initialisatie van alle boolean velden + initializeBooleanFields() { + const updatedValues = { ...this.localFormValues }; + let hasChanges = false; + + // Behandel alle boolean velden in het formulier + const fields = Array.isArray(this.formData.fields) + ? this.formData.fields + : Object.entries(this.formData.fields).map(([id, field]) => ({ ...field, id })); + + fields.forEach(field => { + const fieldId = field.id || field.name; + if (field.type === 'boolean') { + const currentValue = updatedValues[fieldId]; + // Initialiseer als de waarde undefined, null, of een lege string is + if (currentValue === undefined || currentValue === null || currentValue === '') { + updatedValues[fieldId] = field.default === true ? true : false; + hasChanges = true; + } else if (typeof currentValue !== 'boolean') { + // Converteer andere waarden naar boolean + updatedValues[fieldId] = Boolean(currentValue); + hasChanges = true; + } + } + }); + + // Update alleen als er wijzigingen zijn + if (hasChanges) { + this.localFormValues = updatedValues; + } + }, + updateFieldValue(fieldId, value) { + // Zoek het veld om het type te bepalen + let field = null; + if (Array.isArray(this.formData.fields)) { + field = this.formData.fields.find(f => (f.id || f.name) === fieldId); + } else { + field = this.formData.fields[fieldId]; + } + + // Type conversie voor boolean velden + let processedValue = value; + if (field && field.type === 'boolean') { + processedValue = Boolean(value); + } + // Update lokale waarde this.localFormValues = { ...this.localFormValues, - [fieldId]: value + [fieldId]: processedValue }; + + // Na elke field update, controleer alle boolean velden + this.$nextTick(() => { + this.initializeBooleanFields(); + }); }, handleSubmit() { - // Basic validation - const missingFields = []; + // Eerst proactief alle boolean velden corrigeren + this.initializeBooleanFields(); + + // Wacht tot updates zijn verwerkt, dan valideer en submit + this.$nextTick(() => { + // Basic validation + const missingFields = []; - if (Array.isArray(this.formData.fields)) { - // Valideer array-gebaseerde velden - this.formData.fields.forEach(field => { - const fieldId = field.id || field.name; - if (field.required) { - const value = this.localFormValues[fieldId]; - if (value === undefined || value === null || - (typeof value === 'string' && !value.trim()) || - (Array.isArray(value) && value.length === 0)) { - missingFields.push(field.name); + if (Array.isArray(this.formData.fields)) { + // Valideer array-gebaseerde velden + this.formData.fields.forEach(field => { + const fieldId = field.id || field.name; + if (field.required) { + const value = this.localFormValues[fieldId]; + // Voor boolean velden is false een geldige waarde + if (field.type === 'boolean') { + // Boolean velden zijn altijd geldig als ze een boolean waarde hebben + if (typeof value !== 'boolean') { + missingFields.push(field.name); + } + } else { + // Bestaande validatie voor andere veldtypen + if (value === undefined || value === null || + (typeof value === 'string' && !value.trim()) || + (Array.isArray(value) && value.length === 0)) { + missingFields.push(field.name); + } + } } - } - }); - } else { - // Valideer object-gebaseerde velden - Object.entries(this.formData.fields).forEach(([fieldId, field]) => { - if (field.required) { - const value = this.localFormValues[fieldId]; - if (value === undefined || value === null || - (typeof value === 'string' && !value.trim()) || - (Array.isArray(value) && value.length === 0)) { - missingFields.push(field.name); + }); + } else { + // Valideer object-gebaseerde velden + Object.entries(this.formData.fields).forEach(([fieldId, field]) => { + if (field.required) { + const value = this.localFormValues[fieldId]; + // Voor boolean velden is false een geldige waarde + if (field.type === 'boolean') { + // Boolean velden zijn altijd geldig als ze een boolean waarde hebben + if (typeof value !== 'boolean') { + missingFields.push(field.name); + } + } else { + // Bestaande validatie voor andere veldtypen + if (value === undefined || value === null || + (typeof value === 'string' && !value.trim()) || + (Array.isArray(value) && value.length === 0)) { + missingFields.push(field.name); + } + } } - } - }); - } + }); + } - if (missingFields.length > 0) { - alert(`De volgende velden zijn verplicht: ${missingFields.join(', ')}`); - return; - } + if (missingFields.length > 0) { + alert(`De volgende velden zijn verplicht: ${missingFields.join(', ')}`); + return; + } - // Emit submit event - this.$emit('submit', this.localFormValues); + // Emit submit event + this.$emit('submit', this.localFormValues); + }); }, handleCancel() { @@ -277,7 +387,7 @@ export default { // Format different field types if (field.type === 'boolean') { - return value ? 'Ja' : 'Nee'; + return value ? true : false; } else if (field.type === 'enum' && !value && field.default) { return field.default; } diff --git a/eveai_chat_client/static/assets/vue-components/FormField.vue b/eveai_chat_client/static/assets/vue-components/FormField.vue index c81a8bc..0c1a486 100644 --- a/eveai_chat_client/static/assets/vue-components/FormField.vue +++ b/eveai_chat_client/static/assets/vue-components/FormField.vue @@ -199,9 +199,18 @@ export default { return this.modelValue; }, set(value) { + // Type conversie voor boolean velden + let processedValue = value; + if (this.field.type === 'boolean') { + // Converteer alle mogelijke waarden naar echte boolean + console.log('FormField Boolean Value: ', value); + processedValue = Boolean(value); + console.log('FormField Boolean Processed Value: ', processedValue); + } + // Voorkom emit als de waarde niet is veranderd - if (JSON.stringify(value) !== JSON.stringify(this.modelValue)) { - this.$emit('update:modelValue', value); + if (JSON.stringify(processedValue) !== JSON.stringify(this.modelValue)) { + this.$emit('update:modelValue', processedValue); } } }, diff --git a/eveai_chat_workers/specialists/traicie/TRAICIE_SELECTION_SPECIALIST/1_4.py b/eveai_chat_workers/specialists/traicie/TRAICIE_SELECTION_SPECIALIST/1_4.py index 8087cd5..90ab38d 100644 --- a/eveai_chat_workers/specialists/traicie/TRAICIE_SELECTION_SPECIALIST/1_4.py +++ b/eveai_chat_workers/specialists/traicie/TRAICIE_SELECTION_SPECIALIST/1_4.py @@ -35,11 +35,13 @@ KO_CRITERIA_MET_MESSAGE = "We processed your answers with a positive result." RQC_MESSAGE = "You are well suited for this job." CONTACT_DATA_QUESTION = ("Are you willing to provide us with your contact data, so we can contact you to continue " "the selection process?") +CONTACT_DATA_GUIDING_MESSAGE = ("Thank you for trusting your contact data with us. Below you find a form to help you " + "to provide us the necessary information.") NO_CONTACT_DATA_QUESTION = ("We are sorry to hear that. The only way to proceed with the selection process is " "to provide us with your contact data. Do you want to provide us with your contact data?" "if not, we thank you, and we'll end the selection process.") -CONTACT_DATA_PROCESSED_MESSAGE = "We successfully processed your contact data." -CONTACT_TIME_QUESTION = "When do you prefer us to contact you? Provide us with some preferred weekdays and times!" +CONTACT_DATA_PROCESSED_MESSAGE = "Thank you for allowing us to contact you." +CONTACT_TIME_QUESTION = "When do you prefer us to contact you? You can select some options in the provided form" NO_CONTACT_TIME_MESSAGE = ("We could not process your preferred contact time. Can you please provide us with your " "preferred contact time?") CONTACT_TIME_PROCESSED_MESSAGE = ("We successfully processed your preferred contact time. We will contact you as soon " @@ -85,7 +87,7 @@ class SpecialistExecutor(CrewAIBaseSpecialistExecutor): self._add_state_result_relation("competency_questions") self._add_state_result_relation("competency_scores") self._add_state_result_relation("personal_contact_data") - self._add_state_result_relation("contact_time") + self._add_state_result_relation("contact_time_prefs") def _instantiate_specialist(self): verbose = self.tuning @@ -264,11 +266,13 @@ class SpecialistExecutor(CrewAIBaseSpecialistExecutor): contact_form = cache_manager.specialist_forms_config_cache.get_config("PERSONAL_CONTACT_FORM", "1.0") contact_form = TranslationServices.translate_config(self.tenant_id, contact_form, "fields", arguments.language) + guiding_message = TranslationServices.translate(self.tenant_id, CONTACT_DATA_GUIDING_MESSAGE, + arguments.language) rag_output = self._check_and_execute_rag(arguments, formatted_context, citations) if rag_output: - answer = f"{rag_output.answer}" + answer = f"{rag_output.answer}\n\n{guiding_message}" else: - answer = "" + answer = guiding_message self.flow.state.answer = answer self.flow.state.form_request = contact_form @@ -291,6 +295,9 @@ class SpecialistExecutor(CrewAIBaseSpecialistExecutor): answer = ( f"{TranslationServices.translate(self.tenant_id, CONTACT_DATA_PROCESSED_MESSAGE, arguments.language)}\n" f"{TranslationServices.translate(self.tenant_id, CONTACT_TIME_QUESTION, arguments.language)}") + time_pref_form = cache_manager.specialist_forms_config_cache.get_config("CONTACT_TIME_PREFERENCES_SIMPLE", "1.0") + time_pref_form = TranslationServices.translate_config(self.tenant_id, time_pref_form, "fields", + arguments.language) rag_output = self._check_and_execute_rag(arguments, formatted_context, citations) if rag_output: @@ -299,6 +306,7 @@ class SpecialistExecutor(CrewAIBaseSpecialistExecutor): self.flow.state.answer = answer self.flow.state.phase = "contact_time_evaluation" self.flow.state.personal_contact_data = arguments.form_values + self.flow.state.form_request = time_pref_form results = SelectionResult.create_for_type(self.type, self.type_version,) return results @@ -306,29 +314,21 @@ class SpecialistExecutor(CrewAIBaseSpecialistExecutor): def execute_contact_time_evaluation_state(self, arguments: SpecialistArguments, formatted_context, citations) \ -> SpecialistResult: self.log_tuning("Traicie Selection Specialist contact_time_evaluation started", {}) - contact_time_answer = HumanAnswerServices.get_answer_to_question(self.tenant_id, CONTACT_TIME_QUESTION, - arguments.question, arguments.language) rag_output = self._check_and_execute_rag(arguments, formatted_context, citations) - if contact_time_answer == "No answer provided": - answer = TranslationServices.translate(self.tenant_id, NO_CONTACT_TIME_MESSAGE, arguments.language) - if rag_output: - answer = f"{answer}\n\n{rag_output.answer}" + message = TranslationServices.translate(self.tenant_id, CONTACT_TIME_PROCESSED_MESSAGE, arguments.language) - self.flow.state.answer = answer - self.flow.state.phase = "contact_time_evaluation" + answer = TranslationServices.translate(self.tenant_id, CONTACT_TIME_PROCESSED_MESSAGE, arguments.language) + if rag_output: + answer = f"{rag_output.answer}\n\n{message}" - results = SelectionResult.create_for_type(self.type, self.type_version,) - else: - answer = TranslationServices.translate(self.tenant_id, CONTACT_TIME_PROCESSED_MESSAGE, arguments.language) - if rag_output: - answer = f"{answer}\n\n{rag_output.answer}" + self.flow.state.answer = answer + self.flow.state.phase = "candidate_selected" + current_app.logger.debug(f"Contact time evaluation: {arguments.form_values}") + self.flow.state.contact_time_prefs = arguments.form_values - self.flow.state.answer = answer - self.flow.state.phase = "candidate_selected" - self.flow.state.contact_time = contact_time_answer - - results = SelectionResult.create_for_type(self.type, self.type_version,) + results = SelectionResult.create_for_type(self.type, self.type_version,) + current_app.logger.debug(f"Results: {results.model_dump()}") return results @@ -481,6 +481,14 @@ class PersonalContactData(BaseModel): consent: bool = Field(..., description="Consent", alias="consent") +class ContactTimePreferences(BaseModel): + early: Optional[bool] = Field(None, description="Early", alias="early") + late_morning: Optional[bool] = Field(None, description="Late Morning", alias="late_morning") + afternoon: Optional[bool] = Field(None, description="Afternoon", alias="afternoon") + evening: Optional[bool] = Field(None, description="Evening", alias="evening") + other: Optional[str] = Field(None, description="Other", alias="other") + + class SelectionInput(BaseModel): # RAG elements language: Optional[str] = Field(None, alias="language") @@ -508,7 +516,7 @@ class SelectionFlowState(EveAIFlowState): rag_output: Optional[RAGOutput] = None ko_criteria_answers: Optional[Dict[str, str]] = None personal_contact_data: Optional[PersonalContactData] = None - contact_time: Optional[str] = None + contact_time_prefs: Optional[ContactTimePreferences] = None citations: Optional[List[Dict[str, Any]]] = None @@ -516,7 +524,7 @@ class SelectionResult(SpecialistResult): rag_output: Optional[RAGOutput] = Field(None, alias="rag_output") ko_criteria_answers: Optional[Dict[str, str]] = Field(None, alias="ko_criteria_answers") personal_contact_data: Optional[PersonalContactData] = Field(None, alias="personal_contact_data") - contact_time: Optional[str] = None + contact_time_prefs: Optional[ContactTimePreferences] = None class SelectionFlow(EveAICrewAIFlow[SelectionFlowState]): diff --git a/test_boolean_field_fix.html b/test_boolean_field_fix.html new file mode 100644 index 0000000..3d524df --- /dev/null +++ b/test_boolean_field_fix.html @@ -0,0 +1,407 @@ + + +
+ + +Test dat een niet-aangevinkte checkbox false retourneert in plaats van een lege string.
+ +Test dat required boolean velden correct valideren (false is een geldige waarde).
+ +Test een formulier met zowel boolean als andere veldtypen.
+ +