Backup #1407
| ID | 1407 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Domain/Entity/ChatSession.php |
| Version | 15 |
| Typ |
modified |
| Größe | 7.9 KB |
| Hash | 835e702ac4b514ff6ad76207b7f33805372c333e782c66fc59fc8f747cd651cf |
| Datum | 2025-12-25 16:58:35 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Domain\Entity;
// @responsibility: Repräsentiert eine Chat-Session mit ihren Metadaten
use Domain\ValueObject\SessionMetadata;
use Domain\ValueObject\SessionUuid;
class ChatSession
{
public function __construct(
private SessionUuid $uuid,
private SessionMetadata $metadata,
private ?int $id = null,
private ?string $sessionToken = null,
private ?int $userId = null,
private ?int $personaId = null,
private ?string $title = null,
private ?int $authorProfileId = null,
private ?int $systemPromptId = null,
private ?\DateTimeImmutable $createdAt = null,
private ?\DateTimeImmutable $updatedAt = null,
private ?\DateTimeImmutable $lastActivity = null
) {
$this->createdAt ??= new \DateTimeImmutable();
$this->updatedAt ??= new \DateTimeImmutable();
$this->lastActivity ??= new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid->value();
}
public function getUuidObject(): SessionUuid
{
return $this->uuid;
}
public function getSessionToken(): ?string
{
return $this->sessionToken;
}
public function getUserId(): ?int
{
return $this->userId;
}
public function getPersonaId(): ?int
{
return $this->personaId;
}
public function getTitle(): ?string
{
return $this->title;
}
public function getModel(): string
{
return $this->metadata->getModel();
}
/**
* @return array<string>
*/
public function getCollections(): array
{
return $this->metadata->getCollections();
}
public function getContextLimit(): int
{
return $this->metadata->getContextLimit();
}
public function getTemperature(): float
{
return $this->metadata->getTemperature();
}
public function getMaxTokens(): int
{
return $this->metadata->getMaxTokens();
}
public function getAuthorProfileId(): ?int
{
return $this->authorProfileId;
}
public function getSystemPromptId(): ?int
{
return $this->systemPromptId;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function getLastActivity(): \DateTimeImmutable
{
return $this->lastActivity;
}
public function withId(int $id): self
{
return new self(
uuid: $this->uuid,
metadata: $this->metadata,
id: $id,
sessionToken: $this->sessionToken,
userId: $this->userId,
personaId: $this->personaId,
title: $this->title,
authorProfileId: $this->authorProfileId,
systemPromptId: $this->systemPromptId,
createdAt: $this->createdAt,
updatedAt: $this->updatedAt,
lastActivity: $this->lastActivity
);
}
public function withTitle(string $title): self
{
return new self(
uuid: $this->uuid,
metadata: $this->metadata,
id: $this->id,
sessionToken: $this->sessionToken,
userId: $this->userId,
personaId: $this->personaId,
title: $title,
authorProfileId: $this->authorProfileId,
systemPromptId: $this->systemPromptId,
createdAt: $this->createdAt,
updatedAt: new \DateTimeImmutable(),
lastActivity: new \DateTimeImmutable()
);
}
public function updateSettings(
string $model,
array $collections,
int $contextLimit,
?int $authorProfileId,
float $temperature,
int $maxTokens
): self {
$newMetadata = SessionMetadata::create(
model: $model,
collections: $collections,
contextLimit: $contextLimit,
temperature: $temperature,
maxTokens: $maxTokens
);
return new self(
uuid: $this->uuid,
metadata: $newMetadata,
id: $this->id,
sessionToken: $this->sessionToken,
userId: $this->userId,
personaId: $this->personaId,
title: $this->title,
authorProfileId: $authorProfileId,
systemPromptId: $this->systemPromptId,
createdAt: $this->createdAt,
updatedAt: new \DateTimeImmutable(),
lastActivity: new \DateTimeImmutable()
);
}
/**
* Convert to array for persistence.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid->value(),
'session_token' => $this->sessionToken,
'user_id' => $this->userId,
'persona_id' => $this->personaId,
'title' => $this->title,
'model' => $this->model,
'collections' => json_encode($this->collections),
'context_limit' => $this->contextLimit,
'temperature' => $this->temperature,
'max_tokens' => $this->maxTokens,
'author_profile_id' => $this->authorProfileId,
'system_prompt_id' => $this->systemPromptId,
'created_at' => $this->createdAt->format('Y-m-d H:i:s'),
'updated_at' => $this->updatedAt->format('Y-m-d H:i:s'),
'last_activity' => $this->lastActivity->format('Y-m-d H:i:s'),
];
}
/**
* Create from database row.
*
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
$session = new self();
if (isset($data['id'])) {
$session->setId((int) $data['id']);
}
if (isset($data['uuid'])) {
$session->setUuid($data['uuid']);
}
if (isset($data['session_token'])) {
$session->setSessionToken($data['session_token']);
}
if (isset($data['user_id'])) {
$session->setUserId((int) $data['user_id']);
}
if (isset($data['persona_id'])) {
$session->setPersonaId((int) $data['persona_id']);
}
if (isset($data['title'])) {
$session->title = $data['title'];
}
if (isset($data['model'])) {
$session->model = $data['model'];
}
if (isset($data['collections'])) {
$collections = is_string($data['collections'])
? json_decode($data['collections'], true)
: $data['collections'];
$session->collections = is_array($collections) ? $collections : ['documents'];
}
if (isset($data['context_limit'])) {
$session->contextLimit = (int) $data['context_limit'];
}
if (isset($data['temperature'])) {
$session->temperature = (float) $data['temperature'];
}
if (isset($data['max_tokens'])) {
$session->maxTokens = (int) $data['max_tokens'];
}
if (isset($data['author_profile_id'])) {
$session->authorProfileId = (int) $data['author_profile_id'];
}
if (isset($data['system_prompt_id'])) {
$session->systemPromptId = (int) $data['system_prompt_id'];
}
if (isset($data['created_at'])) {
$session->createdAt = new \DateTimeImmutable($data['created_at']);
}
if (isset($data['updated_at'])) {
$session->updatedAt = new \DateTimeImmutable($data['updated_at']);
}
if (isset($data['last_activity'])) {
$session->lastActivity = new \DateTimeImmutable($data['last_activity']);
}
return $session;
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1430 |
18 |
modified |
4.5 KB |
2025-12-25 16:59 |
| 1422 |
17 |
modified |
5.6 KB |
2025-12-25 16:59 |
| 1416 |
16 |
modified |
5.7 KB |
2025-12-25 16:59 |
| 1407 |
15 |
modified |
7.9 KB |
2025-12-25 16:58 |
| 1398 |
14 |
modified |
9.8 KB |
2025-12-25 16:58 |
| 1394 |
13 |
modified |
9.9 KB |
2025-12-25 16:58 |
| 1392 |
12 |
modified |
10.0 KB |
2025-12-25 16:57 |
| 1151 |
11 |
modified |
10.0 KB |
2025-12-25 09:53 |
| 1150 |
10 |
modified |
9.9 KB |
2025-12-25 09:53 |
| 1149 |
9 |
modified |
9.8 KB |
2025-12-25 09:53 |
| 1148 |
8 |
modified |
9.8 KB |
2025-12-25 09:53 |
| 1147 |
7 |
modified |
10.0 KB |
2025-12-25 09:53 |
| 1146 |
6 |
modified |
10.0 KB |
2025-12-25 09:53 |
| 1138 |
5 |
modified |
9.8 KB |
2025-12-25 09:43 |
| 1129 |
4 |
modified |
9.8 KB |
2025-12-25 09:40 |
| 1128 |
3 |
modified |
9.8 KB |
2025-12-25 09:40 |
| 1127 |
2 |
modified |
9.8 KB |
2025-12-25 09:40 |
| 1126 |
1 |
modified |
9.1 KB |
2025-12-25 09:40 |
← Zurück zur Übersicht