AgentThreadRunResource.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\AgentRun;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 会话历史里的一轮问答:用户看得见的那部分。
  7. *
  8. * 研究过程(路由、计划、证据、步骤)不在这里——那是改进回答与防滥用用的,
  9. * 不回给终端用户。user_message_id / assistant_message_id 是 AG-UI 消息 id,
  10. * 续聊时客户端用它们把旧消息原样回灌给 agent。
  11. *
  12. * @mixin AgentRun
  13. */
  14. class AgentThreadRunResource extends BaseResource
  15. {
  16. /**
  17. * @param Request $request
  18. * @return array{
  19. * run_id: string,
  20. * question: string,
  21. * answer: string|null,
  22. * citations: array<int, object>|null,
  23. * deep: bool,
  24. * status: string,
  25. * user_message_id: string|null,
  26. * assistant_message_id: string|null,
  27. * created_at: string
  28. * }
  29. */
  30. public function toArray($request): array
  31. {
  32. return [
  33. 'run_id' => $this->run_id,
  34. 'question' => $this->question,
  35. 'answer' => $this->answer,
  36. 'citations' => $this->citations,
  37. 'deep' => $this->deep,
  38. 'status' => $this->status,
  39. 'user_message_id' => $this->user_message_id,
  40. 'assistant_message_id' => $this->assistant_message_id,
  41. 'created_at' => $this->started_at ?? $this->created_at,
  42. ];
  43. }
  44. }