id = $data['id'] ?? null; $this->conversation_uuid = $data['conversation_uuid'] ?? ''; $this->role = $data['role'] ?? 'user'; $this->content = $data['content'] ?? ''; $this->metadata = isset( $data['metadata'] ) ? json_decode( $data['metadata'], true ) : null; $this->created_at = $data['created_at'] ?? ''; } /** * Convert to array * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'conversation_uuid' => $this->conversation_uuid, 'role' => $this->role, 'content' => $this->content, 'metadata' => $this->metadata, 'created_at' => $this->created_at, ]; } /** * Format for API response * * @return array */ public function toApiFormat( $index = null ): array { $data = [ 'role' => $this->role, 'content' => $this->content, 'timestamp' => $this->created_at, 'index' => $index ?? $this->id, ]; if ( ! empty( $this->metadata['mentioned_tools'] ) ) { $data['mentioned_tools'] = $this->metadata['mentioned_tools']; } if ( ! empty( $this->metadata['pending_approval'] ) ) { $data['pending_approval'] = $this->metadata['pending_approval']; } return $data; } }