fix(captain): evita erro ao adicionar FAQ com pergunta longa
Some checks failed
Build and Push to GHCR (multi-arch) / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Build and Push to GHCR (multi-arch) / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Build and Push to GHCR (multi-arch) / merge (push) Has been cancelled

This commit is contained in:
Kilo-Oracle 2026-04-27 15:12:09 +00:00
parent 21f5fcce6a
commit 60079a1b9e
4 changed files with 34 additions and 4 deletions

View File

@ -2,7 +2,7 @@
import { reactive, computed, watch } from 'vue'; import { reactive, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useVuelidate } from '@vuelidate/core'; 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 { useMapGetter } from 'dashboard/composables/store';
import Input from 'dashboard/components-next/input/Input.vue'; import Input from 'dashboard/components-next/input/Input.vue';
@ -39,11 +39,17 @@ const initialState = {
assistant_id: '', assistant_id: '',
}; };
const QUESTION_MAX_LENGTH = 255;
const state = reactive({ ...initialState }); const state = reactive({ ...initialState });
const validationRules = computed(() => { const validationRules = computed(() => {
const rules = { const rules = {
question: { required, minLength: minLength(1) }, question: {
required,
minLength: minLength(1),
maxLength: maxLength(QUESTION_MAX_LENGTH),
},
answer: { required, minLength: minLength(1) }, answer: { required, minLength: minLength(1) },
}; };
@ -123,6 +129,7 @@ watch(
:placeholder="t('CAPTAIN.RESPONSES.FORM.QUESTION.PLACEHOLDER')" :placeholder="t('CAPTAIN.RESPONSES.FORM.QUESTION.PLACEHOLDER')"
:message="formErrors.question" :message="formErrors.question"
:message-type="formErrors.question ? 'error' : 'info'" :message-type="formErrors.question ? 'error' : 'info'"
:maxlength="QUESTION_MAX_LENGTH"
/> />
<Editor <Editor
v-model="state.answer" 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 Editor from 'dashboard/components-next/Editor/Editor.vue';
import { useUISettings } from 'dashboard/composables/useUISettings'; import { useUISettings } from 'dashboard/composables/useUISettings';
const FAQ_QUESTION_MAX_LENGTH = 255;
export default { export default {
components: { components: {
AddCannedModal, AddCannedModal,
@ -93,6 +95,11 @@ export default {
this.message.content_attributes ?? this.message.contentAttributes this.message.content_attributes ?? this.message.contentAttributes
); );
}, },
faqQuestion() {
return (this.plainTextContent || '')
.trim()
.slice(0, FAQ_QUESTION_MAX_LENGTH);
},
}, },
methods: { methods: {
handleEnterKey(e) { handleEnterKey(e) {
@ -251,7 +258,7 @@ export default {
ref="faqDialog" ref="faqDialog"
type="create" type="create"
:selected-response="{ :selected-response="{
question: plainTextContent, question: faqQuestion,
assistant_id: copilotAssistant?.id, assistant_id: copilotAssistant?.id,
}" }"
@close="hideFaqModal" @close="hideFaqModal"

View File

@ -30,7 +30,7 @@ class Captain::AssistantResponse < ApplicationRecord
belongs_to :documentable, polymorphic: true, optional: true belongs_to :documentable, polymorphic: true, optional: true
has_neighbors :embedding, normalize: true has_neighbors :embedding, normalize: true
validates :question, presence: true validates :question, presence: true, length: { maximum: 255 }
validates :answer, presence: true validates :answer, presence: true
before_validation :ensure_account 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) expect(response).to have_http_status(:unprocessable_entity)
end 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
end end