session-list.php

Code Hygiene Score: 100

Keine Issues gefunden.

Versionen 2

Code

<?php foreach ($sessions ?? [] as $s):
    $totalTokens = (int) ($s['total_input_tokens'] ?? 0) + (int) ($s['total_output_tokens'] ?? 0);
    $totalCost = ((int) ($s['total_input_tokens'] ?? 0) * 0.000015) + ((int) ($s['total_output_tokens'] ?? 0) * 0.000075);
    $isOllama = str_starts_with($s['model'] ?? '', 'ollama:');
    $createdAt = $s['created_at'] ?? null;
    $dateStr = $createdAt ? (new DateTime($createdAt))->format('d.m. H:i') : '';
    ?>
<a href="/chat/<?= $s['uuid'] ?>"
   class="chat-session <?= ($currentUuid ?? '') === $s['uuid'] ? 'chat-session--active' : '' ?>"
   data-uuid="<?= $s['uuid'] ?>">
    <div class="chat-session__title" id="title-<?= $s['uuid'] ?>"><?= htmlspecialchars($s['title'] ?? 'Neuer Chat') ?></div>
    <div class="chat-session__meta">
        <span class="chat-session__date"><?= $dateStr ?></span>
        <span><?= $s['message_count'] ?? 0 ?> Nachr.</span>
        <?php if (!$isOllama && $totalTokens > 0): ?>
        <span class="chat-session__cost">~$<?= number_format($totalCost, 2) ?></span>
        <?php elseif ($isOllama): ?>
        <span class="chat-session__local">lokal</span>
        <?php endif; ?>
    </div>
    <div class="chat-session__actions">
        <button class="chat-session__edit" onclick="event.preventDefault(); event.stopPropagation(); editTitle('<?= $s['uuid'] ?>');" title="Bearbeiten">&#9998;</button>
        <button class="chat-session__delete" hx-delete="/chat/<?= $s['uuid'] ?>" hx-headers='{"X-CSRF-TOKEN": "<?= $csrfToken ?>"}' hx-confirm="Session löschen?" onclick="event.preventDefault(); event.stopPropagation();">&times;</button>
    </div>
</a>
<?php endforeach; ?>
<?php if (empty($sessions)): ?>
<div class="chat-session chat-session--empty">Keine Sessions</div>
<?php endif; ?>
← Übersicht