Shared Page: - Merge consecutive assistant text messages (same iteration) - Add iteration field to thread API response - Unified rendering for single/thread messages UI Reorganization (manual changes): - Session + Agent forms: collapsible 'Weitere Einstellungen' section - Agent defaults: tool_choice unchecked, web_search 2025, model opus-4-6 - Profile: default-path field hidden, divider removed - Form spacing adjustments, .more toggle style
72 lines
2.3 KiB
JavaScript
72 lines
2.3 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 = _mergeConsecutiveTexts(messages);
|
|
|
|
for (const msg of messages) {
|
|
const div = document.createElement('div');
|
|
div.className = 'msg ' + (msg.role === 'user' ? 'user' : 'assistant') + ' markdown';
|
|
if (msg.role === 'user') {
|
|
renderUserContent(div, msg.content);
|
|
} else {
|
|
div.innerHTML = renderMarkdown(msg.content);
|
|
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: () => {}
|
|
});
|
|
|
|
function _mergeConsecutiveTexts(msgs) {
|
|
const result = [];
|
|
for (const msg of msgs) {
|
|
if (msg.role === 'assistant') {
|
|
const prev = result[result.length - 1];
|
|
if (prev && prev.role === 'assistant'
|
|
&& prev.iteration === msg.iteration) {
|
|
prev.content = (prev.content || '') + ' ' + (msg.content || '');
|
|
if (msg.createdAt) prev.createdAt = msg.createdAt;
|
|
continue;
|
|
}
|
|
}
|
|
result.push(Object.assign({}, msg));
|
|
}
|
|
return result;
|
|
}
|