Ship War Room UX, CEO inbox, mobile chat, and Agents NAS workspace.

Make A2A togglable, keep reply context while reading, route agent data to //10.4.7.11/share/Agents, and polish themes plus export-intel sync cancel.
This commit is contained in:
Aissa
2026-08-16 22:40:32 +00:00
parent 910ba465d7
commit c5ea8cbb63
26 changed files with 2891 additions and 407 deletions
+60 -49
View File
@@ -1,38 +1,48 @@
/** 3D-style agent poppetjes met headset — consistent team look */
/** Agent avatars — bright cool cyan/blue team look (readable on dark UI) */
window.AgentAvatars = (function () {
var CFG = {
herman: { hoodie: '#1e3a5f', hair: '#4a3728', skin: '#e8b896', style: 'exec', accent: '#ffd700' },
marketing: { hoodie: '#9d174d', hair: '#1f2937', skin: '#f5c9a8', style: 'bob', accent: '#ff6b9d' },
bizdev: { hoodie: '#0e4d6e', hair: '#2d1810', skin: '#ddb896', style: 'short', accent: '#00e5ff' },
finance: { hoodie: '#14532d', hair: '#3d2314', skin: '#e8b896', style: 'glasses', accent: '#22c55e' },
sourcing: { hoodie: '#9a3412', hair: '#1a1a1a', skin: '#c9a07a', style: 'short', accent: '#f97316' },
product: { hoodie: '#581c87', hair: '#4a3728', skin: '#f5c9a8', style: 'curl', accent: '#a855f7' },
halal: { hoodie: '#065f46', hair: '#1f2937', skin: '#d4a574', style: 'short', accent: '#34d399' },
design: { hoodie: '#831843', hair: '#111827', skin: '#f5c9a8', style: 'long', accent: '#ec4899' },
knowledge: { hoodie: '#312e81', hair: '#374151', skin: '#e8b896', style: 'glasses', accent: '#6366f1' },
retail: { hoodie: '#365314', hair: '#2d1810', skin: '#ddb896', style: 'short', accent: '#b8ff3c' },
browser: { hoodie: '#0c4a6e', hair: '#1f2937', skin: '#c9a07a', style: 'short', accent: '#38bdf8' },
hr: { hoodie: '#6b21a8', hair: '#2d1810', skin: '#ddb896', style: 'bob', accent: '#e879f9' },
email: { hoodie: '#334155', hair: '#4a3728', skin: '#ddb896', style: 'short', accent: '#94a3b8' },
research: { hoodie: '#115e59', hair: '#1a1a1a', skin: '#f5c9a8', style: 'glasses', accent: '#14b8a6' },
sysops: { hoodie: '#1e3a5f', hair: '#4a3728', skin: '#e8b896', style: 'short', accent: '#38bdf8', hat: 'cap' },
packaging: { hoodie: '#7c2d12', hair: '#2d1810', skin: '#c9a07a', style: 'short', accent: '#fb923c' },
webbuilder: { hoodie: '#0c4a6e', hair: '#1f2937', skin: '#ddb896', style: 'glasses', accent: '#0ea5e9', hat: 'cap' },
herman: { hoodie: '#1d4ed8', hair: '#5b3a29', skin: '#f0c9a8', style: 'exec', accent: '#fbbf24' },
marketing: { hoodie: '#0891b2', hair: '#1f2937', skin: '#f5d0b0', style: 'bob', accent: '#22d3ee' },
bizdev: { hoodie: '#0284c7', hair: '#3d2314', skin: '#e8c4a0', style: 'short', accent: '#38bdf8' },
finance: { hoodie: '#0d9488', hair: '#3d2314', skin: '#f0c9a8', style: 'glasses', accent: '#2dd4bf' },
sourcing: { hoodie: '#0369a1', hair: '#1a1a1a', skin: '#e0b890', style: 'short', accent: '#7dd3fc' },
product: { hoodie: '#4f46e5', hair: '#5b3a29', skin: '#f5d0b0', style: 'curl', accent: '#818cf8' },
halal: { hoodie: '#059669', hair: '#1f2937', skin: '#e8c4a0', style: 'short', accent: '#34d399' },
design: { hoodie: '#0e7490', hair: '#111827', skin: '#f5d0b0', style: 'long', accent: '#67e8f9' },
knowledge: { hoodie: '#4338ca', hair: '#374151', skin: '#f0c9a8', style: 'glasses', accent: '#a5b4fc' },
retail: { hoodie: '#0f766e', hair: '#3d2314', skin: '#e8c4a0', style: 'short', accent: '#5eead4' },
browser: { hoodie: '#2563eb', hair: '#1f2937', skin: '#e0b890', style: 'short', accent: '#60a5fa' },
hr: { hoodie: '#6366f1', hair: '#3d2314', skin: '#e8c4a0', style: 'bob', accent: '#c7d2fe' },
email: { hoodie: '#475569', hair: '#5b3a29', skin: '#e8c4a0', style: 'short', accent: '#94a3b8' },
research: { hoodie: '#0f766e', hair: '#1a1a1a', skin: '#f5d0b0', style: 'glasses', accent: '#2dd4bf' },
sysops: { hoodie: '#1e40af', hair: '#5b3a29', skin: '#f0c9a8', style: 'short', accent: '#38bdf8', hat: 'cap' },
packaging: { hoodie: '#1d4ed8', hair: '#3d2314', skin: '#e0b890', style: 'short', accent: '#93c5fd' },
webbuilder: { hoodie: '#0284c7', hair: '#1f2937', skin: '#e8c4a0', style: 'glasses', accent: '#38bdf8', hat: 'cap' },
};
function cfg(key, fallbackColor) {
var k = (key || 'agent').toLowerCase();
var c = CFG[k] || { hoodie: fallbackColor || '#1e3a5f', hair: '#3d2314', skin: '#e8b896', style: 'short', accent: '#38bdf8' };
var c = CFG[k] || { hoodie: fallbackColor || '#0284c7', hair: '#3d2314', skin: '#f0c9a8', style: 'short', accent: '#38bdf8' };
return c;
}
function lighten(hex, amt) {
hex = (hex || '#0284c7').replace('#', '');
if (hex.length === 3) hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
var n = parseInt(hex, 16);
var r = Math.min(255, ((n >> 16) & 255) + amt);
var g = Math.min(255, ((n >> 8) & 255) + amt);
var b = Math.min(255, (n & 255) + amt);
return '#' + (0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function capSvg(hid, c) {
return (
'<path d="M22,44 Q50,30 78,44 L82,48 Q50,54 18,48Z" fill="#0f172a" opacity="0.35"/>' +
'<ellipse cx="50" cy="36" rx="26" ry="12" fill="' + c.hoodie + '"/>' +
'<path d="M24,40 Q50,26 76,40 L88,46 Q50,52 14,46Z" fill="#1e40af"/>' +
'<path d="M26,38 Q50,28 74,38" fill="none" stroke="#38bdf8" stroke-width="1.2" opacity="0.5"/>' +
'<rect x="46" y="28" width="8" height="5" rx="1" fill="#38bdf8" opacity="0.85"/>'
'<path d="M22,44 Q50,30 78,44 L82,48 Q50,54 18,48Z" fill="#0f172a" opacity="0.2"/>' +
'<ellipse cx="50" cy="36" rx="26" ry="12" fill="' + lighten(c.hoodie, 40) + '"/>' +
'<path d="M24,40 Q50,26 76,40 L88,46 Q50,52 14,46Z" fill="' + c.hoodie + '"/>' +
'<path d="M26,38 Q50,28 74,38" fill="none" stroke="' + c.accent + '" stroke-width="1.4" opacity="0.7"/>' +
'<rect x="46" y="28" width="8" height="5" rx="1" fill="' + c.accent + '"/>'
);
}
@@ -45,50 +55,51 @@ window.AgentAvatars = (function () {
function svgAvatar(key, color) {
var c = cfg(key, color);
var hid = 'av-' + key;
var hid = 'av-' + key + '-' + Math.random().toString(36).slice(2, 7);
var hoodLite = lighten(c.hoodie, 55);
return (
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 120" class="agent-char-svg" aria-hidden="true">' +
'<defs>' +
'<linearGradient id="' + hid + '-bg" x1="0%" y1="0%" x2="100%" y2="100%">' +
'<stop offset="0%" stop-color="#0c1929"/><stop offset="50%" stop-color="#152238"/><stop offset="100%" stop-color="#0a1020"/>' +
'<stop offset="0%" stop-color="#1a3a5c"/><stop offset="55%" stop-color="#245a82"/><stop offset="100%" stop-color="#1e4a6e"/>' +
'</linearGradient>' +
'<linearGradient id="' + hid + '-hood" x1="30%" y1="0%" x2="70%" y2="100%">' +
'<stop offset="0%" stop-color="' + c.hoodie + '"/><stop offset="100%" stop-color="#0a0f18"/>' +
'<stop offset="0%" stop-color="' + hoodLite + '"/><stop offset="100%" stop-color="' + c.hoodie + '"/>' +
'</linearGradient>' +
'<linearGradient id="' + hid + '-skin" x1="40%" y1="0%" x2="60%" y2="100%">' +
'<stop offset="0%" stop-color="' + c.skin + '"/><stop offset="100%" stop-color="#c9956e"/>' +
'<stop offset="0%" stop-color="' + c.skin + '"/><stop offset="100%" stop-color="#d4a07a"/>' +
'</linearGradient>' +
'<radialGradient id="' + hid + '-glow" cx="75%" cy="25%" r="45%">' +
'<stop offset="0%" stop-color="' + c.accent + '" stop-opacity="0.35"/><stop offset="100%" stop-opacity="0"/>' +
'<radialGradient id="' + hid + '-glow" cx="70%" cy="20%" r="50%">' +
'<stop offset="0%" stop-color="' + c.accent + '" stop-opacity="0.55"/><stop offset="100%" stop-opacity="0"/>' +
'</radialGradient>' +
'<filter id="' + hid + '-sh"><feDropShadow dx="0" dy="2" stdDeviation="2" flood-opacity="0.45"/></filter>' +
'<filter id="' + hid + '-sh"><feDropShadow dx="0" dy="2" stdDeviation="1.5" flood-opacity="0.3"/></filter>' +
'</defs>' +
'<rect width="100" height="120" fill="url(#' + hid + '-bg)"/>' +
'<ellipse cx="78" cy="28" rx="35" ry="30" fill="url(#' + hid + '-glow)"/>' +
'<ellipse cx="50" cy="100" rx="30" ry="14" fill="rgba(0,0,0,0.4)"/>' +
'<rect width="100" height="120" rx="14" fill="url(#' + hid + '-bg)"/>' +
'<ellipse cx="78" cy="26" rx="38" ry="32" fill="url(#' + hid + '-glow)"/>' +
'<ellipse cx="50" cy="100" rx="28" ry="12" fill="rgba(0,0,0,0.22)"/>' +
'<path d="M18,118 Q18,74 50,68 Q82,74 82,118Z" fill="url(#' + hid + '-hood)" filter="url(#' + hid + '-sh)"/>' +
'<path d="M20,70 Q50,58 80,70 L76,82 Q50,76 24,82Z" fill="' + c.hoodie + '" opacity="0.9"/>' +
'<path d="M20,70 Q50,58 80,70 L76,82 Q50,76 24,82Z" fill="' + hoodLite + '" opacity="0.95"/>' +
'<path d="M28,68 Q50,48 72,68 L68,78 Q50,72 32,78Z" fill="' + c.hoodie + '"/>' +
'<ellipse cx="50" cy="54" rx="23" ry="25" fill="url(#' + hid + '-skin)" filter="url(#' + hid + '-sh)"/>' +
'<ellipse cx="56" cy="56" rx="10" ry="14" fill="rgba(0,0,0,0.08)"/>' +
'<ellipse cx="56" cy="56" rx="10" ry="14" fill="rgba(255,255,255,0.12)"/>' +
(c.hat === 'cap' ? '' : '<path d="' + hairPath(c.style) + '" fill="' + c.hair + '"/>') +
(c.style === 'glasses'
? '<ellipse cx="42" cy="52" rx="8" ry="6" fill="none" stroke="#334155" stroke-width="1.5"/>' +
'<ellipse cx="58" cy="52" rx="8" ry="6" fill="none" stroke="#334155" stroke-width="1.5"/>' +
'<line x1="50" y1="52" x2="50" y2="52" stroke="#334155" stroke-width="1.5"/>'
? '<ellipse cx="42" cy="52" rx="8" ry="6" fill="none" stroke="#e2e8f0" stroke-width="1.6"/>' +
'<ellipse cx="58" cy="52" rx="8" ry="6" fill="none" stroke="#e2e8f0" stroke-width="1.6"/>' +
'<line x1="50" y1="52" x2="50" y2="52" stroke="#e2e8f0" stroke-width="1.5"/>'
: '') +
'<ellipse cx="42" cy="52" rx="3" ry="3.5" fill="#1e293b"/><ellipse cx="58" cy="52" rx="3" ry="3.5" fill="#1e293b"/>' +
'<ellipse cx="43" cy="51" rx="1" ry="1.2" fill="#fff" opacity="0.7"/><ellipse cx="59" cy="51" rx="1" ry="1.2" fill="#fff" opacity="0.7"/>' +
'<ellipse cx="42" cy="52" rx="3.2" ry="3.6" fill="#0f172a"/><ellipse cx="58" cy="52" rx="3.2" ry="3.6" fill="#0f172a"/>' +
'<ellipse cx="43.2" cy="50.8" rx="1.1" ry="1.3" fill="#fff" opacity="0.85"/><ellipse cx="59.2" cy="50.8" rx="1.1" ry="1.3" fill="#fff" opacity="0.85"/>' +
'<path d="M44,62 Q50,66 56,62" fill="none" stroke="#b45309" stroke-width="1.5" stroke-linecap="round"/>' +
'<path d="M16,50 Q50,26 84,50" fill="none" stroke="#cbd5e1" stroke-width="4" stroke-linecap="round"/>' +
'<rect x="10" y="44" width="14" height="18" rx="5" fill="#1e293b" stroke="#94a3b8" stroke-width="1.8"/>' +
'<path d="M16,50 Q50,26 84,50" fill="none" stroke="#e2e8f0" stroke-width="3.5" stroke-linecap="round"/>' +
'<rect x="10" y="44" width="14" height="18" rx="5" fill="#1e293b" stroke="' + c.accent + '" stroke-width="1.8"/>' +
'<rect x="12" y="47" width="10" height="12" rx="3" fill="#334155"/>' +
'<rect x="76" y="44" width="14" height="18" rx="5" fill="#1e293b" stroke="#94a3b8" stroke-width="1.8"/>' +
'<rect x="76" y="44" width="14" height="18" rx="5" fill="#1e293b" stroke="' + c.accent + '" stroke-width="1.8"/>' +
'<rect x="78" y="47" width="10" height="12" rx="3" fill="#334155"/>' +
'<path d="M78,60 Q86,72 82,82" fill="none" stroke="#94a3b8" stroke-width="2.8" stroke-linecap="round"/>' +
'<circle cx="82" cy="84" r="3.5" fill="#64748b" stroke="#94a3b8" stroke-width="1"/>' +
'<circle cx="88" cy="32" r="2.5" fill="' + c.accent + '" opacity="0.9"/>' +
'<circle cx="12" cy="40" r="1.5" fill="' + c.accent + '" opacity="0.5"/>' +
'<path d="M78,60 Q86,72 82,82" fill="none" stroke="#cbd5e1" stroke-width="2.6" stroke-linecap="round"/>' +
'<circle cx="82" cy="84" r="3.5" fill="' + c.accent + '" stroke="#e2e8f0" stroke-width="1"/>' +
'<circle cx="88" cy="32" r="3" fill="' + c.accent + '"/>' +
'<circle cx="14" cy="38" r="2" fill="' + c.accent + '" opacity="0.7"/>' +
(c.hat === 'cap' ? capSvg(hid, c) : '') +
'</svg>'
);
@@ -98,7 +109,7 @@ window.AgentAvatars = (function () {
if (!el) return;
var k = (key || '').toLowerCase();
var c = color || '';
var sig = k + '|' + c;
var sig = k + '|v2|' + c;
if (!force && el.getAttribute('data-avatar-painted') === sig && el.querySelector('svg')) return;
el.innerHTML = svgAvatar(k, color);
el.setAttribute('data-avatar-painted', sig);
+518 -58
View File
@@ -17,6 +17,21 @@ window.WarRoomHub = (function () {
rooms: [],
room: null,
messages: [],
chatSearch: '',
searchOpen: false,
toolsOpen: false,
screenCleared: false,
autoDebate: true,
ceoInboxOpen: false,
ceoInbox: [],
ceoUnread: 0,
replyTo: null,
replyHighlightId: null,
stickToBottom: true,
showJumpLatest: false,
_typingScrollAt: 0,
rosterCollapsed: true,
a2aPausedUntil: 0,
draft: '',
busy: false,
me: { username: '', avatar_url: '', role: '' },
@@ -37,9 +52,9 @@ window.WarRoomHub = (function () {
callSlug: '',
voiceRecording: false,
voiceBusy: false,
speakReplies: true,
speakReplies: false,
voiceRoomOpen: false,
voiceRoomAgents: ['herman'],
voiceRoomAgents: ['herman', 'bizdev', 'finance', 'retail', 'marketing'],
voiceSpeakingKey: '',
voiceLastHeard: '',
_voiceRec: null,
@@ -49,6 +64,7 @@ window.WarRoomHub = (function () {
async init() {
this.voiceRoomOpen = false;
this.busy = false;
this._sendLock = false;
await Promise.all([this.loadMe(), this.loadSouls(), this.loadRooms()]);
var params = new URLSearchParams(window.location.search || '');
var want = params.get('room');
@@ -58,7 +74,13 @@ window.WarRoomHub = (function () {
if (wr) await this.openRoom(wr.id);
else if (this.rooms.length) await this.openRoom(this.rooms[0].id);
}
try {
var saved = localStorage.getItem('flk-warroom-a2a');
this.autoDebate = (saved === null || saved === '1' || saved === 'true');
} catch (e) { this.autoDebate = true; }
this.startPoll();
this.loadCeoInbox();
if (this.autoDebate && this.room && this.room.kind === 'warroom') this.scheduleContinue(60000);
},
destroy() {
@@ -129,26 +151,35 @@ window.WarRoomHub = (function () {
async openRoom(id) {
if (!id) return;
id = parseInt(id, 10);
this.busy = true;
this.status = '';
this.typing = null;
try {
if (!(this.rooms || []).length) await this.loadRooms();
var meta = (this.rooms || []).find(function (r) { return Number(r.id) === id; }) || null;
var r = await fetch('/api/agents/warroom/rooms/' + id + '/messages?limit=120').then(function (x) {
return x.json();
});
this.room = r.room;
// messages API returns {items}, NOT {room} — keep room from rooms list
this.room = meta || r.room || { id: id, kind: 'warroom', title: 'War Room' };
this.messages = this.normalizeList(r.items || []);
this.lastId = this.maxId(this.messages);
this.stickToBottom = true;
this.showJumpLatest = false;
this.$nextTick(function () {
this.paintAvatars();
this.scrollLog();
this.scrollLog(true);
this.focusComposer();
}.bind(this));
var last = (this.messages || [])[(this.messages || []).length - 1];
if (last && last.sender_type === 'agent' && this.room && this.room.kind === 'warroom') {
this.scheduleContinue(4000);
if (this.autoDebate) this.scheduleContinue(60000);
}
} catch (e) {
this.status = e.message || 'Laden mislukt';
// Still keep a usable room id so send works
if (!this.room) this.room = { id: id, kind: 'warroom', title: 'War Room' };
}
this.busy = false;
},
@@ -203,12 +234,44 @@ window.WarRoomHub = (function () {
return changed;
},
scrollLog() {
isNearBottom(el, px) {
if (!el) return true;
var gap = el.scrollHeight - el.scrollTop - el.clientHeight;
return gap <= (px == null ? 80 : px);
},
onLogScroll() {
var el = this.$refs && this.$refs.wrLog;
if (el) el.scrollTop = el.scrollHeight;
if (!el) return;
var near = this.isNearBottom(el, 100);
this.stickToBottom = near;
this.showJumpLatest = !near;
},
scrollLog(force) {
var el = this.$refs && this.$refs.wrLog;
if (!el) return;
if (!force && !this.stickToBottom) {
this.showJumpLatest = true;
return;
}
el.scrollTop = el.scrollHeight;
this.stickToBottom = true;
this.showJumpLatest = false;
},
jumpToLatest() {
this.stickToBottom = true;
this.showJumpLatest = false;
this.scrollLog(true);
},
startPoll() {
var selfCeo = this;
if (!this._ceoPoll) {
this._ceoPoll = setInterval(function () { selfCeo.loadCeoInbox(); }, 20000);
}
var self = this;
if (this._poll) clearInterval(this._poll);
this._poll = setInterval(function () { self.pollNew(); }, 4000);
@@ -283,6 +346,7 @@ window.WarRoomHub = (function () {
},
onDraftInput() {
if ((this.draft || '').trim()) this.pauseA2A(90000);
var d = this.draft || '';
var m = /(^|\s)@([a-zA-Z0-9_-]*)$/.exec(d);
if (m) {
@@ -344,51 +408,153 @@ window.WarRoomHub = (function () {
this.pendingFiles = (this.pendingFiles || []).filter(function (_, i) { return i !== idx; });
},
focusComposer() {
try {
var el = this.$refs && this.$refs.wrInput;
if (el) {
el.removeAttribute('disabled');
el.readOnly = false;
el.focus();
}
} catch (e) {}
},
canSend() {
return !this.busy && this.room && (((this.draft || '').trim()) || (this.pendingFiles || []).length);
var hasText = !!(this.draft || '').trim();
var hasFiles = !!(this.pendingFiles || []).length;
return !!(hasText || hasFiles);
},
async ensureRoom() {
if (this.room && this.room.id) return true;
try {
await this.loadRooms();
var wr = this.warroomRoom();
if (wr) {
await this.openRoom(wr.id);
} else {
// fallback: known warroom id 1
await this.openRoom(1);
}
} catch (e) {}
return !!(this.room && this.room.id);
},
onEnter(e) {
if (e && e.shiftKey) return; // Shift+Enter = nieuwe regel
if (this.mentionOpen) {
var sug = this.mentionSuggestions();
if (sug && sug.length) {
if (e) e.preventDefault();
this.pickMention(sug[this.mentionIndex] || sug[0]);
return;
}
}
if (e) e.preventDefault();
this.send();
},
async send() {
var text = (this.draft || '').trim();
var files = (this.pendingFiles || []).slice();
if (!this.room || this.busy) return;
if (!text && !files.length) return;
// Never get stuck behind a stale busy flag
if (this._sendLock) return;
this._sendLock = true;
this.busy = true;
this.mentionOpen = false;
this.emojiOpen = false;
var okRoom = await this.ensureRoom();
if (!okRoom) {
this.busy = false;
this._sendLock = false;
this.status = 'Room niet geladen — klik ↻';
if (window.Cockpit) Cockpit.toast(this.status, 'error');
return;
}
// Instant UI — no waiting for network/LLM
var tempId = 'local-' + Date.now();
var replySnapshot = this.replyTo ? {
id: this.replyTo.id,
agent_key: this.replyTo.agent_key,
username: this.replyTo.username,
sender_type: this.replyTo.sender_type,
excerpt: this.replyTo.excerpt,
label: this.replyTo.label,
} : null;
var replyToId = replySnapshot ? replySnapshot.id : null;
var optimisticMeta = {};
if (files.length) optimisticMeta.attachments = files;
if (replySnapshot) optimisticMeta.reply_to = replySnapshot;
var optimistic = {
id: tempId,
room_id: this.room.id,
sender_type: 'user',
content: text || (files.length ? '(bijlage)' : ''),
username: (this.me && this.me.username) || 'Jij',
sender_avatar_url: (this.me && this.me.avatar_url) || null,
metadata: optimisticMeta,
created_at: new Date().toISOString(),
};
this.draft = '';
this.pendingFiles = [];
this.replyTo = null;
this.replyHighlightId = replyToId;
this.pauseA2A(90000);
this.typing = null;
this.status = 'Verzenden…';
this.upsertMessage(optimistic);
this.status = '';
this.stickToBottom = true;
this.$nextTick(function () {
this.scrollLog(true);
this.focusComposer();
}.bind(this));
try {
var resp = await fetch('/api/agents/warroom/rooms/' + this.room.id + '/messages/stream', {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream' },
body: JSON.stringify({ content: text, attachments: files }),
body: JSON.stringify({ content: text, attachments: files, reply_to_id: replyToId }),
});
if (!resp.ok) {
var err = await resp.json().catch(function () { return {}; });
throw new Error(err.detail || ('HTTP ' + resp.status));
}
await this.consumeStream(resp);
this.status = '';
this.scheduleContinue(2000);
// Drop temp bubble if server user msg arrived with real id
this.messages = (this.messages || []).filter(function (m) {
return m.id !== tempId;
});
// Herlaad recente geschiedenis (merge) zodat reply-parent niet "kwijt" raakt in de UI
await this.refreshMessages({ silent: true });
if (replyToId) {
var self = this;
this.$nextTick(function () {
self.scrollToMessage(replyToId);
setTimeout(function () { self.replyHighlightId = null; }, 4000);
});
}
if (this.autoDebate) this.scheduleContinue(60000);
} catch (e) {
this.draft = text;
this.pendingFiles = files;
// Keep optimistic message; restore draft only on hard fail
this.status = e.message || 'Verzenden mislukt';
if (window.Cockpit) Cockpit.toast(this.status, 'error');
}
this.typing = null;
this.busy = false;
this._sendLock = false;
this.$nextTick(function () {
this.paintAvatars();
this.scrollLog();
this.scrollLog(true);
this.focusComposer();
}.bind(this));
},
async consumeStream(resp) {
var reader = resp.body.getReader();
var decoder = new TextDecoder();
@@ -422,6 +588,7 @@ window.WarRoomHub = (function () {
}
var type = ev.event || '';
if (type === 'user' && ev.message) {
this.messages = (this.messages || []).filter(function (m) { return String(m.id).indexOf('local-') !== 0; });
this.upsertMessage(ev.message);
this.status = 'Agent typt…';
this.$nextTick(function () { this.scrollLog(); }.bind(this));
@@ -434,7 +601,9 @@ window.WarRoomHub = (function () {
text: '',
};
this.status = (this.typing.display_name || 'Agent') + ' typt…';
this.$nextTick(function () { this.scrollLog(); }.bind(this));
// alleen meescrollen als je al onderaan zit
if (this.stickToBottom) this.$nextTick(function () { this.scrollLog(); }.bind(this));
else this.showJumpLatest = true;
} else if (type === 'typing') {
if (!this.typing || this.typing.agent_key !== ev.agent_key) {
this.typing = {
@@ -446,11 +615,20 @@ window.WarRoomHub = (function () {
this.typing.text = (this.typing.text || '') + (ev.delta || '');
// force alpine refresh
this.typing = Object.assign({}, this.typing);
this.$nextTick(function () { this.scrollLog(); }.bind(this));
// geen jump tijdens teruglezen; max 1x / 600ms als je onderaan zit
if (this.stickToBottom) {
var now = Date.now();
if (now - (this._typingScrollAt || 0) > 600) {
this._typingScrollAt = now;
this.$nextTick(function () { this.scrollLog(); }.bind(this));
}
} else {
this.showJumpLatest = true;
}
} else if (type === 'agent' && ev.message) {
this.typing = null;
this.upsertMessage(ev.message);
if (ev.message.content) this.speakText(ev.message.content, ev.message.agent_key);
if (this.voiceRoomOpen && this.speakReplies && ev.message.content) this.speakText(ev.message.content, ev.message.agent_key);
this.$nextTick(function () {
this.paintAvatars();
this.scrollLog();
@@ -468,54 +646,142 @@ window.WarRoomHub = (function () {
},
onKey(e) {
if (!this.mentionOpen) return;
var sug = this.mentionSuggestions();
if (this.mentionOpen && sug.length) {
if (e.key === 'ArrowDown') {
e.preventDefault();
this.mentionIndex = (this.mentionIndex + 1) % sug.length;
return;
}
if (e.key === 'ArrowUp') {
e.preventDefault();
this.mentionIndex = (this.mentionIndex - 1 + sug.length) % sug.length;
return;
}
if (e.key === 'Enter' || e.key === 'Tab') {
e.preventDefault();
this.pickMention(sug[this.mentionIndex] || sug[0]);
return;
}
if (e.key === 'Escape') {
this.mentionOpen = false;
return;
}
}
if (e.key === 'Enter' && !e.shiftKey) {
if (!sug.length) return;
if (e.key === 'ArrowDown') {
e.preventDefault();
this.send();
this.mentionIndex = (this.mentionIndex + 1) % sug.length;
return;
}
if (e.key === 'ArrowUp') {
e.preventDefault();
this.mentionIndex = (this.mentionIndex - 1 + sug.length) % sug.length;
return;
}
if (e.key === 'Tab') {
e.preventDefault();
this.pickMention(sug[this.mentionIndex] || sug[0]);
return;
}
if (e.key === 'Escape') {
this.mentionOpen = false;
}
},
scheduleContinue(delayMs) {
if (!this.autoDebate || !this.room || this.room.kind !== 'warroom') return;
if (this._continueTimer) clearTimeout(this._continueTimer);
if (!this.autoDebate) return;
var self = this;
this._continueTimer = setTimeout(function () { self.runContinue(2); }, delayMs || 2500);
// default: rustig tempo (~50s), niet elke paar seconden
var wait = (typeof delayMs === 'number' && delayMs >= 0) ? delayMs : 50000;
this._continueTimer = setTimeout(function () { self.runContinue(1); }, wait);
},
toggleA2A() {
this.autoDebate = !this.autoDebate;
try { localStorage.setItem('flk-warroom-a2a', this.autoDebate ? '1' : '0'); } catch (e) {}
if (this._continueTimer) clearTimeout(this._continueTimer);
if (this.autoDebate) {
this.status = 'A2A aan — agents mogen onderling verder praten';
this.scheduleContinue(8000);
if (window.Cockpit) Cockpit.toast('A2A aan', 'ok');
} else {
this.status = 'A2A uit — alleen reacties op jouw berichten';
this.a2aPausedUntil = 0;
if (window.Cockpit) Cockpit.toast('A2A uit', 'ok');
}
},
pauseA2A(ms) {
this.a2aPausedUntil = Date.now() + (ms || 45000);
if (this._continueTimer) clearTimeout(this._continueTimer);
},
setReply(m) {
if (!m || !m.id || String(m.id).indexOf('local-') === 0) return;
this.replyTo = {
id: m.id,
agent_key: m.agent_key || null,
username: m.username || null,
sender_type: m.sender_type,
excerpt: ((m.content || '').trim().slice(0, 160)) + (((m.content || '').length > 160) ? '…' : ''),
label: this.labelForMessage(m),
};
this.replyHighlightId = m.id;
this.pauseA2A(90000);
this.$nextTick(function () {
this.scrollToMessage(m.id);
this.focusComposer();
}.bind(this));
},
scrollToMessage(id) {
if (id == null) return;
var root = (this.$refs && this.$refs.wrLog) || document;
var el = root.querySelector && root.querySelector('[data-msg-id="' + id + '"]');
if (el && el.scrollIntoView) {
try { el.scrollIntoView({ block: 'center', behavior: 'smooth' }); } catch (e) {
el.scrollIntoView(true);
}
}
},
async refreshMessages(opts) {
opts = opts || {};
if (!this.room || !this.room.id) return;
try {
var r = await fetch('/api/agents/warroom/rooms/' + this.room.id + '/messages?limit=200', {
credentials: 'same-origin',
}).then(function (x) { return x.json(); });
var items = this.normalizeList(r.items || []);
if (items.length) {
this.messages = items;
this.lastId = this.maxId(items);
}
if (!opts.silent) {
this.$nextTick(function () {
this.paintAvatars();
this.scrollLog();
}.bind(this));
} else {
this.$nextTick(function () { this.paintAvatars(); }.bind(this));
}
} catch (e) { /* quiet */ }
},
clearReply() {
this.replyTo = null;
this.replyHighlightId = null;
},
replyPreview(m) {
var meta = (m && m.metadata) || {};
return meta.reply_to || null;
},
async runContinue(turns) {
if (!this.autoDebate || !this.room || this.room.kind !== 'warroom') return;
if (this.busy || this._continueBusy) return;
// only continue if last message is from an agent (they are mid-debate)
var last = (this.messages || [])[(this.messages || []).length - 1];
if (!last || last.sender_type !== 'agent') return;
if (this.busy || this._continueBusy || this._sendLock) {
this.scheduleContinue(20000);
return;
}
if (Date.now() < (this.a2aPausedUntil || 0)) {
this.scheduleContinue(Math.max(10000, this.a2aPausedUntil - Date.now()));
return;
}
// niet doorkletsen terwijl jij typt
if ((this.draft || '').trim().length > 0 || this.replyTo) {
this.scheduleContinue(25000);
return;
}
this._continueBusy = true;
this.status = 'Agents overleggen verder…';
this.status = 'A2A — agents reageren…';
try {
var resp = await fetch('/api/agents/warroom/rooms/' + this.room.id + '/continue?turns=' + (turns || 2), {
var resp = await fetch('/api/agents/warroom/rooms/' + this.room.id + '/continue?turns=' + (turns || 1), {
method: 'POST',
credentials: 'same-origin',
headers: { Accept: 'text/event-stream', 'Content-Type': 'application/json' },
@@ -525,16 +791,208 @@ window.WarRoomHub = (function () {
this.busy = true;
await this.consumeStream(resp);
this.busy = false;
this.status = '';
// keep the debate alive a bit while the tab is open
this.scheduleContinue(12000);
this.status = 'A2A live';
// keep conversation alive
this.scheduleContinue(55000);
} catch (e) {
this.busy = false;
this.status = '';
this.status = 'A2A hervatten…';
this.scheduleContinue(45000);
}
this._continueBusy = false;
},
async loadCeoInbox() {
try {
var r = await fetch('/api/agents/warroom/ceo-inbox?limit=40', { credentials: 'same-origin' })
.then(function (x) { return x.json(); });
this.ceoInbox = r.items || [];
this.ceoUnread = r.unread || 0;
} catch (e) {
this.ceoInbox = this.ceoInbox || [];
}
},
openCeoInbox() {
this.ceoInboxOpen = true;
this.loadCeoInbox();
},
closeCeoInbox() {
this.ceoInboxOpen = false;
},
async markCeoRead(id) {
try {
await fetch('/api/agents/warroom/ceo-inbox/read', {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(id ? { ids: [id] } : { all: true }),
});
await this.loadCeoInbox();
} catch (e) {}
},
async markAllCeoRead() {
await this.markCeoRead(null);
if (window.Cockpit) Cockpit.toast('CEO-inbox gelezen', 'ok');
},
isCeoDirect(m) {
if (!m) return false;
if (m.ceo_inbox_id || (m.metadata && m.metadata.ceo_direct)) return true;
var c = (m.content || '').toLowerCase();
return c.indexOf('@aissa') >= 0 || c.indexOf('@ceo') >= 0 || c.indexOf('@ervoorz') >= 0;
},
formatMsgTime(m) {
var raw = (m && (m.created_at || m.createdAt || m.ts)) || '';
if (!raw) return '';
var d = new Date(raw);
if (isNaN(d.getTime())) return '';
return d.toLocaleTimeString('nl-NL', { hour: '2-digit', minute: '2-digit' });
},
formatMsgDate(m) {
var raw = (m && (m.created_at || m.createdAt || m.ts)) || '';
if (!raw) return '';
var d = new Date(raw);
if (isNaN(d.getTime())) return '';
var today = new Date();
var yest = new Date(); yest.setDate(today.getDate() - 1);
var same = function (a, b) {
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
};
if (same(d, today)) return 'Vandaag';
if (same(d, yest)) return 'Gisteren';
return d.toLocaleDateString('nl-NL', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' });
},
dayKey(m) {
var raw = (m && (m.created_at || m.createdAt || m.ts)) || '';
if (!raw) return '';
var d = new Date(raw);
if (isNaN(d.getTime())) return '';
return d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
},
showDaySep(idx) {
var list = this.visibleMessages();
if (!list.length || idx < 0 || idx >= list.length) return false;
if (idx === 0) return !!this.dayKey(list[idx]);
return this.dayKey(list[idx]) !== this.dayKey(list[idx - 1]);
},
visibleMessages() {
if (this.screenCleared) return [];
var q = (this.chatSearch || '').trim().toLowerCase();
var list = this.messages || [];
if (!q) return list;
return list.filter(function (m) {
var hay = [
m.content || '',
m.agent_key || '',
m.username || '',
m.display_name || '',
m.sender_type || '',
].join(' ').toLowerCase();
return hay.indexOf(q) >= 0;
});
},
toggleSearch() {
this.searchOpen = !this.searchOpen;
this.toolsOpen = false;
if (this.searchOpen) {
var self = this;
this.$nextTick(function () {
var el = self.$refs && self.$refs.wrSearch;
if (el) el.focus();
});
} else {
this.chatSearch = '';
}
},
clearScreen() {
this.screenCleared = true;
this.status = 'Scherm geleegd (berichten blijven bewaard)';
if (window.Cockpit) Cockpit.toast('Chat-scherm geleegd', 'ok');
},
restoreScreen() {
this.screenCleared = false;
this.status = '';
this.$nextTick(function () { this.scrollLog(); }.bind(this));
},
async clearChatHistory() {
if (!this.room) return;
if (!window.confirm('Alle berichten in dit kanaal permanent van het scherm wissen (soft-delete)?')) return;
try {
var r = await fetch('/api/agents/warroom/rooms/' + this.room.id + '/messages', {
method: 'DELETE',
credentials: 'same-origin',
}).then(function (x) { return x.json().then(function (d) { return { ok: x.ok, d: d }; }); });
if (!r.ok) throw new Error((r.d && (r.d.detail || r.d.message)) || 'Wissen mislukt');
this.messages = [];
this.screenCleared = false;
this.lastId = 0;
this.status = 'Geschiedenis gewist (' + ((r.d && r.d.cleared) || 0) + ')';
if (window.Cockpit) Cockpit.toast('Chatgeschichte gewist', 'ok');
} catch (e) {
if (window.Cockpit) Cockpit.toast(e.message || 'Wissen mislukt', 'error');
}
},
downloadChat(fmt) {
fmt = fmt || 'txt';
var list = this.messages || [];
if (!list.length) {
if (window.Cockpit) Cockpit.toast('Geen berichten om te downloaden', 'info');
return;
}
var title = (this.room && (this.room.title || this.room.kind)) || 'war-room';
var stamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-');
var filename = 'foodlinkk-' + String(title).replace(/[^\w\-]+/g, '_') + '-' + stamp;
var body = '';
var mime = 'text/plain;charset=utf-8';
if (fmt === 'json') {
body = JSON.stringify({ room: this.room, exported_at: new Date().toISOString(), messages: list }, null, 2);
filename += '.json';
mime = 'application/json;charset=utf-8';
} else if (fmt === 'md') {
body = '# ' + title + '\n\n_Geëxporteerd: ' + new Date().toLocaleString('nl-NL') + '_\n\n';
list.forEach(function (m) {
var who = this.labelForMessage(m) + (m.agent_key ? (' (@' + m.agent_key + ')') : '');
var when = this.formatMsgDate(m) + ' ' + this.formatMsgTime(m);
body += '### ' + who + ' · ' + when.trim() + '\n\n' + (m.content || '') + '\n\n---\n\n';
}.bind(this));
filename += '.md';
mime = 'text/markdown;charset=utf-8';
} else {
body = title + '\nGeëxporteerd: ' + new Date().toLocaleString('nl-NL') + '\n' + ('='.repeat(48)) + '\n\n';
list.forEach(function (m) {
var who = this.labelForMessage(m) + (m.agent_key ? (' (@' + m.agent_key + ')') : '');
var when = (this.formatMsgDate(m) + ' ' + this.formatMsgTime(m)).trim();
body += '[' + when + '] ' + who + ':\n' + (m.content || '') + '\n\n';
}.bind(this));
filename += '.txt';
}
var blob = new Blob([body], { type: mime });
var a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function () { URL.revokeObjectURL(a.href); a.remove(); }, 500);
this.toolsOpen = false;
if (window.Cockpit) Cockpit.toast('Download gestart (' + fmt + ')', 'ok');
},
async deleteMessage(m) {
if (!this.room || !m || !m.id) return;
if (!window.confirm('Bericht verwijderen?')) return;
@@ -554,8 +1012,10 @@ window.WarRoomHub = (function () {
removeDeletedIds(ids) {
if (!ids || !ids.length) return;
var set = {};
ids.forEach(function (id) { set[id] = true; });
this.messages = (this.messages || []).filter(function (m) { return !set[m.id]; });
ids.forEach(function (id) { set[String(id)] = true; });
this.messages = (this.messages || []).filter(function (m) {
return !set[String(m.id)];
});
},
@@ -566,9 +1026,9 @@ window.WarRoomHub = (function () {
return;
}
if (!(this.voiceRoomAgents || []).length) {
this.voiceRoomAgents = ['herman'];
this.voiceRoomAgents = ['herman', 'bizdev', 'finance', 'retail', 'marketing'];
}
this.speakReplies = true;
// voorlezen blijft uit tot gebruiker 🔊 aanzet
this.voiceRoomOpen = true;
this.callOpen = false;
this.status = 'Voice Room open — houd 🎤 in om te praten';
+34 -4
View File
@@ -4,6 +4,8 @@ function exportIntelApp() {
tabIndicatorTop: 0,
tabIndicatorH: 40,
busy: false,
overlayDismissed: false,
syncAbort: null,
syncMsg: '',
syncMonitor: null,
syncMonitorOpen: true,
@@ -291,9 +293,30 @@ function exportIntelApp() {
},
isWorking() {
if (this.overlayDismissed) return false;
return this.busy || this.crmPushBusy || this.mapLoading || this.drawerLoading;
},
dismissOverlay() {
this.overlayDismissed = true;
},
async cancelSync() {
try {
if (this.syncAbort) {
try { this.syncAbort.abort(); } catch (e) {}
}
await fetch('/api/export-intel/sync/cancel', { method: 'POST' });
this.syncMsg = 'Sync wordt geannuleerd…';
this.busy = false;
this.overlayDismissed = true;
if (window.Cockpit) Cockpit.toast('Sync annuleren…', 'info');
await this.pollSyncStatus();
} catch (e) {
this.syncMsg = 'Annuleren mislukt: ' + e.message;
}
},
progressLabel() {
if (this.busy && this.syncMsg) return this.syncMsg;
if (this.crmPushBusy) return 'CRM import bezig…';
@@ -792,7 +815,9 @@ function exportIntelApp() {
return;
}
this.busy = true;
this.overlayDismissed = false;
this.syncMsg = kind === 'world' ? 'Wereld-sync gestart…' : 'Sync gestart…';
this.syncAbort = (typeof AbortController !== 'undefined') ? new AbortController() : null;
try {
var body = {
country_iso2: this.country || null,
@@ -806,20 +831,25 @@ function exportIntelApp() {
return;
}
var endpoint = kind === 'region' ? 'region' : kind;
var r = await fetch('/api/export-intel/sync/' + endpoint, {
var fetchOpts = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
}).then((x) => x.json());
};
if (this.syncAbort) fetchOpts.signal = this.syncAbort.signal;
var r = await fetch('/api/export-intel/sync/' + endpoint, fetchOpts).then((x) => x.json());
if (r.error) this.syncMsg = 'Fout: ' + r.error;
else if (r.cancelled || (r.result && r.result.cancelled)) this.syncMsg = 'Sync geannuleerd';
else if (kind === 'world') this.syncMsg = 'Wereld-sync voltooid — kaart wordt ververst';
else if (kind === 'all' || kind === 'region') this.syncMsg = 'Regio-sync voltooid';
else this.syncMsg = 'Sync voltooid';
await this.refresh();
if (!(r.cancelled || (r.result && r.result.cancelled))) await this.refresh();
} catch (e) {
this.syncMsg = 'Sync mislukt: ' + e.message;
if (e && e.name === 'AbortError') this.syncMsg = 'Sync geannuleerd';
else this.syncMsg = 'Sync mislukt: ' + e.message;
}
this.busy = false;
this.syncAbort = null;
},
tabCount(id) {