StoreAgentFeedbackRequest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\AgentFeedback;
  4. use App\Models\AgentThread;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. use Illuminate\Validation\Rule;
  7. /**
  8. * `POST /v3/agent-feedback` 的入参:对一条 AI 回答点赞 / 点踩。
  9. */
  10. class StoreAgentFeedbackRequest extends FormRequest
  11. {
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * @return array<string, array<int, mixed>>
  18. */
  19. public function rules(): array
  20. {
  21. return [
  22. 'message_id' => ['required', 'string', 'max:64', 'regex:/^[A-Za-z0-9_\-]+$/'],
  23. 'thread_id' => ['nullable', 'uuid'],
  24. 'rating' => ['required', 'integer', Rule::in([1, -1])],
  25. 'tags' => ['nullable', 'array', 'max:8'],
  26. 'tags.*' => ['string', Rule::in([...AgentFeedback::UP_TAGS, ...AgentFeedback::DOWN_REASONS])],
  27. 'comment' => ['nullable', 'string', 'max:1000'],
  28. 'asked' => ['boolean'],
  29. 'device_id' => ['nullable', 'uuid'],
  30. 'client' => ['nullable', Rule::in(AgentThread::CLIENTS)],
  31. ];
  32. }
  33. }