Backup #1922
| ID | 1922 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/View/chat/partials/message.php |
| Version | 4 |
| Typ |
modified |
| Größe | 3.8 KB |
| Hash | a8ddf3b3f899726b18ff1572a5fb395b16c480584b36e3a3629225c998a9a4e9 |
| Datum | 2025-12-28 01:20:24 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
/**
* Chat Message Partial
*
* @var array $message Message data from database
* @var \Infrastructure\Formatting\ChatMessageFormatter|null $formatter Optional formatter instance
*/
$role = $message['role'] ?? 'user';
$content = $message['content'] ?? '';
// Fix #404: Handle double-encoded JSON sources
$sources = [];
if (!empty($message['sources'])) {
$decoded = json_decode($message['sources'], true);
if (is_array($decoded)) {
foreach ($decoded as $item) {
// Handle double-encoded JSON (each item is a JSON string)
$sources[] = is_string($item) ? json_decode($item, true) : $item;
}
}
}
// Fix #402: Use formatter for assistant messages
$formattedContent = $content;
if ($role === 'assistant') {
if (isset($formatter)) {
$formattedContent = $formatter->formatAnswer($content);
} else {
// Fallback: inline formatting for control tokens
$formattedContent = preg_replace('/<\/?end_of_turn>/i', '', $content);
$formattedContent = preg_replace('/<\/?start_of_turn>/i', '', $formattedContent);
$formattedContent = nl2br(htmlspecialchars($formattedContent));
}
}
$inputTokens = (int) ($message['tokens_input'] ?? 0);
$outputTokens = (int) ($message['tokens_output'] ?? 0);
$model = $message['model'] ?? 'claude-opus-4-5-20251101';
$isOllama = str_starts_with($model, 'ollama:');
$modelLabel = $isOllama ? substr($model, 7) : $model;
$cost = ($inputTokens * 0.000015) + ($outputTokens * 0.000075);
?>
<div class="chat-msg chat-msg--<?= htmlspecialchars($role) ?>">
<div class="chat-msg__content">
<?php if ($role === 'user'): ?>
<?= htmlspecialchars($content) ?>
<?php else: ?>
<?= $formattedContent ?>
<?php if (!empty($sources)): ?>
<?php $uniqueId = 'sources-' . ($message['id'] ?? uniqid()); ?>
<div class="chat-sources chat-sources--collapsed" id="<?= $uniqueId ?>">
<button type="button" class="chat-sources__toggle" onclick="toggleSources('<?= $uniqueId ?>')">
<span class="chat-sources__count"><?= count($sources) ?> Quelle<?= count($sources) > 1 ? 'n' : '' ?></span>
<span class="chat-sources__arrow">▼</span>
</button>
<div class="chat-sources__list">
<?php foreach ($sources as $source): ?>
<div class="source-item">
<div class="source-item__header">
<span class="source-item__title"><?= htmlspecialchars($source['title'] ?? 'Unbekannt') ?></span>
<span class="source-item__score"><?= round(($source['score'] ?? 0) * 100) ?>%</span>
</div>
<?php if (!empty($source['content'])): ?>
<div class="source-item__content">"<?= htmlspecialchars(mb_substr($source['content'], 0, 200)) ?><?= mb_strlen($source['content']) > 200 ? '...' : '' ?>"</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="chat-msg__meta">
<span><?= htmlspecialchars($modelLabel) ?></span>
<?php if (!$isOllama && ($inputTokens > 0 || $outputTokens > 0)): ?>
<span class="chat-msg__tokens">↓<?= number_format($inputTokens) ?> ↑<?= number_format($outputTokens) ?></span>
<span class="chat-msg__cost">~$<?= number_format($cost, 4) ?></span>
<?php elseif ($isOllama): ?>
<span class="chat-msg__local">lokal</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1922 |
4 |
modified |
3.8 KB |
2025-12-28 01:20 |
| 1772 |
3 |
modified |
4.0 KB |
2025-12-27 13:56 |
| 1771 |
2 |
modified |
4.0 KB |
2025-12-27 13:55 |
| 1770 |
1 |
modified |
3.3 KB |
2025-12-27 13:55 |
← Zurück zur Übersicht