Merge pull request #11 from Rodribm10/kilo/auto-fix-erro-adicionar-faq

fix(captain): evita erro ao adicionar FAQ em conversa
This commit is contained in:
Rodribm10 2026-04-27 14:52:06 -03:00 committed by GitHub
commit 4f31e11b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 4 deletions

View File

@ -2,7 +2,7 @@
import { reactive, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useVuelidate } from '@vuelidate/core';
import { required, minLength } from '@vuelidate/validators';
import { required, minLength, maxLength } from '@vuelidate/validators';
import { useMapGetter } from 'dashboard/composables/store';
import Input from 'dashboard/components-next/input/Input.vue';
@ -39,11 +39,17 @@ const initialState = {
assistant_id: '',
};
const QUESTION_MAX_LENGTH = 255;
const state = reactive({ ...initialState });
const validationRules = computed(() => {
const rules = {
question: { required, minLength: minLength(1) },
question: {
required,
minLength: minLength(1),
maxLength: maxLength(QUESTION_MAX_LENGTH),
},
answer: { required, minLength: minLength(1) },
};
@ -123,6 +129,7 @@ watch(
:placeholder="t('CAPTAIN.RESPONSES.FORM.QUESTION.PLACEHOLDER')"
:message="formErrors.question"
:message-type="formErrors.question ? 'error' : 'info'"
:maxlength="QUESTION_MAX_LENGTH"
/>
<Editor
v-model="state.answer"

View File

@ -18,6 +18,8 @@ import NextButton from 'dashboard/components-next/button/Button.vue';
import Editor from 'dashboard/components-next/Editor/Editor.vue';
import { useUISettings } from 'dashboard/composables/useUISettings';
const FAQ_QUESTION_MAX_LENGTH = 255;
export default {
components: {
AddCannedModal,
@ -93,6 +95,11 @@ export default {
this.message.content_attributes ?? this.message.contentAttributes
);
},
faqQuestion() {
return (this.plainTextContent || '')
.trim()
.slice(0, FAQ_QUESTION_MAX_LENGTH);
},
},
methods: {
handleEnterKey(e) {
@ -251,7 +258,7 @@ export default {
ref="faqDialog"
type="create"
:selected-response="{
question: plainTextContent,
question: faqQuestion,
assistant_id: copilotAssistant?.id,
}"
@close="hideFaqModal"

View File

@ -30,7 +30,7 @@ class Captain::AssistantResponse < ApplicationRecord
belongs_to :documentable, polymorphic: true, optional: true
has_neighbors :embedding, normalize: true
validates :question, presence: true
validates :question, presence: true, length: { maximum: 255 }
validates :answer, presence: true
before_validation :ensure_account

View File

@ -197,6 +197,22 @@ RSpec.describe 'Api::V1::Accounts::Captain::AssistantResponses', type: :request
expect(response).to have_http_status(:unprocessable_entity)
end
it 'returns unprocessable entity when question exceeds 255 characters' do
long_question = 'a' * 256
post "/api/v1/accounts/#{account.id}/captain/assistant_responses",
params: {
assistant_response: {
question: long_question,
answer: 'Test answer',
assistant_id: assistant.id
}
},
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unprocessable_entity)
end
end
end