- fix: _oldestLoadedMessageId → _oldestLoadedSortKey (chat.js, chat-page.js) - move: formatTimestamp nach ui-helpers.js (war _formatTimestamp in msg-actions.js) - move: _isReviewMessage nach ui-helpers.js (war in history.js) - add: _getSubAgentMeta + _createSubAgentHeader in ui-helpers.js - refactor: stream-ui.js + history.js nutzen _createSubAgentHeader - refactor: flushText() Hilfsfunktion in _renderReviewGroup (history.js) - refactor: shared-page.js nutzt _mergeConsecutiveAssistantTexts statt eigener Kopie - refactor: _initCardMenu + _onCardMenuAction Helper in dashboard.js -53 Zeilen netto
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
// ── Shared Message Page (öffentlich, kein Login nötig) ──
|
|
|
|
registerPage('shared', {
|
|
init: async (params) => {
|
|
const token = params.id;
|
|
const container = document.getElementById('sharedContent');
|
|
if (!token || !container) {
|
|
container.innerHTML = '<div class="shared-error"><i class="fa fa-times-circle"></i> Ungültiger Link</div>';
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const data = await apiGetShared(token);
|
|
container.innerHTML = '';
|
|
|
|
let messages = [];
|
|
|
|
if (data.messages && data.messages.length > 0) {
|
|
messages = data.messages;
|
|
} else if (data.message) {
|
|
messages = [data.message];
|
|
}
|
|
|
|
// Aufeinanderfolgende Assistant-Text-Messages mergen (wie im Chat)
|
|
messages = _mergeConsecutiveAssistantTexts(messages);
|
|
|
|
for (const msg of messages) {
|
|
const c = msg.content || '';
|
|
|
|
// Web-Search-Results als Tool-Box mit Sources rendern
|
|
if (msg.type === 'web_search_result') {
|
|
var wsSources = [];
|
|
try { wsSources = JSON.parse(c || '[]'); } catch(e) {}
|
|
if (wsSources.length === 0) continue;
|
|
const div = document.createElement('div');
|
|
div.className = 'tool-box';
|
|
div.dataset.toolName = 'web_search';
|
|
renderToolBoxContent(div, 'web_search', null, null, false, wsSources);
|
|
container.appendChild(div);
|
|
continue;
|
|
}
|
|
|
|
const isReview = _isReviewMessage(c);
|
|
const div = document.createElement('div');
|
|
if (isReview) {
|
|
div.className = 'msg review-bubble markdown' + (c.startsWith('[Finalizer:') ? ' finalizer-bubble' : '');
|
|
} else {
|
|
div.className = 'msg ' + (msg.role === 'user' ? 'user' : 'assistant') + ' markdown';
|
|
}
|
|
if (!isReview && msg.role === 'user') {
|
|
renderUserContent(div, msg.content);
|
|
} else {
|
|
div.innerHTML = renderMarkdown(c);
|
|
parseFluentEmojis(div);
|
|
wrapKreaGalleries(div);
|
|
}
|
|
container.appendChild(div);
|
|
}
|
|
|
|
// Timestamp anzeigen
|
|
if (data.createdAt) {
|
|
const meta = document.createElement('div');
|
|
meta.className = 'shared-meta';
|
|
const d = new Date(data.createdAt);
|
|
meta.innerHTML = '<i class="fa fa-clock-o"></i> Geteilt am ' + d.toLocaleDateString('de-DE') + ' um ' + d.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' });
|
|
container.appendChild(meta);
|
|
}
|
|
|
|
} catch (err) {
|
|
container.innerHTML = '<div class="shared-error"><i class="fa fa-times-circle"></i> ' + esc(err.message) + '</div>';
|
|
}
|
|
},
|
|
destroy: () => {}
|
|
});
|
|
|
|
// _mergeConsecutiveTexts → replaced by _mergeConsecutiveAssistantTexts from history.js
|