|null, * error?: string|null, * model?: string|null, * prompt_version?: string|null, * steps?: array * } */ public function toArray($request): array { $detail = $this->relationLoaded('steps'); return [ 'run_id' => $this->run_id, 'thread_id' => $this->thread?->thread_id, 'thread_title' => $this->thread?->title, 'account_type' => $this->account_type, // 只有登录用户才查得到人;游客的 account_id 是设备 id,不能拿去当用户 uid 'user' => $this->account_type === 'user' ? $this->actor($this->user) : null, 'device_id' => $this->account_type === 'guest' ? $this->account_id : null, 'client_ip' => $this->client_ip, 'client' => $this->client, 'app_version' => $this->app_version, 'question' => $this->question, 'route' => $this->route, 'deep' => $this->deep, 'improve' => $this->improve, 'status' => $this->status, 'latency_ms' => $this->latency_ms, 'tokens_in' => $this->tokens_in, 'tokens_out' => $this->tokens_out, 'llm_calls' => $this->llm_calls, 'tool_calls' => $this->tool_calls, 'started_at' => $this->started_at, $this->mergeWhen($detail, fn () => [ 'answer' => $this->answer, 'evidence' => $this->evidence, 'plan' => $this->plan, 'passage' => $this->passage, 'citations' => $this->citations, 'error' => $this->error, 'model' => $this->model, 'prompt_version' => $this->prompt_version, 'steps' => $this->steps->map(fn ($s) => [ 'seq' => $s->seq, 'kind' => $s->kind, 'name' => $s->name, 'args' => $s->args, 'result' => $s->result, 'result_chars' => $s->result_chars, 'tokens_in' => $s->tokens_in, 'tokens_out' => $s->tokens_out, 'ms' => $s->ms, 'error' => $s->error, ])->all(), ]), ]; } }