AgentThreadResource.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\AgentThread;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 我的一个 AI 对话会话。列表里不带 runs,详情里带全部可见的问答轮次。
  7. *
  8. * deleted_at 只在删除接口的响应里非空(软删后返回的就是这条记录本身)。
  9. *
  10. * @mixin AgentThread
  11. */
  12. class AgentThreadResource extends BaseResource
  13. {
  14. /**
  15. * @param Request $request
  16. * @return array{
  17. * thread_id: string,
  18. * title: string,
  19. * client: string|null,
  20. * archived_at: string|null,
  21. * last_run_at: string,
  22. * created_at: string,
  23. * updated_at: string,
  24. * deleted_at: string|null,
  25. * runs?: array<int, array{run_id: string, question: string, answer: string|null, citations: array<int, object>|null, deep: bool, status: string, user_message_id: string|null, assistant_message_id: string|null, created_at: string}>
  26. * }
  27. */
  28. public function toArray($request): array
  29. {
  30. return [
  31. 'thread_id' => $this->thread_id,
  32. 'title' => $this->title,
  33. 'client' => $this->client,
  34. 'archived_at' => $this->archived_at,
  35. 'last_run_at' => $this->last_run_at,
  36. 'created_at' => $this->created_at,
  37. 'updated_at' => $this->updated_at,
  38. 'deleted_at' => $this->deleted_at,
  39. 'runs' => AgentThreadRunResource::collection($this->whenLoaded('runs')),
  40. ];
  41. }
  42. }