// 任务 Tab:会话列表 / 聊天(SSE 流式)/ 文件管理 / 阶段开关。
// 交互沿用 1.0:移动优先,聊天详情为全屏覆盖页(盖住底部导航),右滑返回列表。
'use strict';
// ---------- 工具摘要(工具卡片用) ----------
function toolArgsSummary(name, argsStr) {
let s = '';
try {
const o = JSON.parse(argsStr || '{}');
const key = ['path', 'command', 'regex', 'glob', 'url', 'query', 'source_path', 'destination_path'];
for (const k of key) if (o[k]) { s = String(o[k]); break; }
if (!s) s = argsStr || '';
} catch (_) { s = argsStr || ''; }
if (s.length > 80) s = s.slice(0, 80) + '…';
return s;
}
function toolArgsFull(argsStr) {
try { return JSON.stringify(JSON.parse(argsStr || '{}'), null, 2); }
catch (_) { return argsStr || ''; }
}
// ---------- 聊天详情覆盖页进出(底部导航随之隐藏/恢复) ----------
function showChat() {
$('tabbar').classList.add('hidden');
const cp = $('chat-page');
cp.classList.remove('hidden');
cp.classList.add('off-right');
requestAnimationFrame(() => {
requestAnimationFrame(() => cp.classList.remove('off-right'));
});
}
function showList() {
const cp = $('chat-page');
cp.classList.add('off-right');
setTimeout(() => cp.classList.add('hidden'), 50);
$('tabbar').classList.remove('hidden');
}
// 滑动切换:聊天页右滑返回列表
(function bindSwipe() {
let x0 = null, y0 = null;
const cp = $('chat-page');
if (!cp) return;
cp.addEventListener('touchstart', e => {
if (e.touches.length !== 1) return;
x0 = e.touches[0].clientX; y0 = e.touches[0].clientY;
}, { passive: true });
cp.addEventListener('touchend', e => {
if (x0 == null) return;
const t = e.changedTouches[0];
const dx = t.clientX - x0, dy = t.clientY - y0;
x0 = null;
if (dx > 70 && Math.abs(dy) < 60) ui.backToList();
}, { passive: true });
})();
// ---------- 会话列表(活跃 + 归档分页 + 搜索) ----------
const DONE_PAGE = 10; // 归档每页条数
let activeRows = []; // 当前活跃会话(含排队/保持)
let searchMode = false; // 搜索模式:列表区显示搜索结果
let doneRows = []; // 已加载的归档行
let doneTotal = 0; // 归档总数
let doneCursor = null; // 下一页游标 {updated_at, id}
let doneLoading = false;
// 单张会话卡片(活跃/归档/搜索结果共用)
function sessionCard(s) {
const st = { queued: '排队中', active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' }[s.status] || s.status;
const badge = '' + st + (s.status === 'queued' && s.queue_pos ? ' #' + s.queue_pos : '') + ' ';
return '
' +
'
' +
'
' + esc(s.title || s.id) + '
' +
'
' + esc(s.id) + ' ' + badge +
(s.model_id ? '' + esc(s.model_id) + ' ' : '') + '
' +
'
' +
'
删除 ' +
'
';
}
function renderSessionList() {
const el = $('session-list');
let html = activeRows.map(sessionCard).join('');
html += doneRows.map(sessionCard).join('');
if (!activeRows.length && !doneTotal) {
html += '还没有任务,点右上角 + 新建
';
}
const remain = doneTotal - doneRows.length;
if (remain > 0) {
// 括号内是剩余未展示的归档数,如总共 100、已显 10 则显示「加载更多(90)」
html += '加载更多(' + remain + ') ';
}
el.innerHTML = html;
}
async function loadSessions() {
if (searchMode) return doSearch();
try {
const lists = await Promise.all([
req('GET', '/api/sessions?status=active&limit=100'),
req('GET', '/api/sessions?status=done&limit=' + DONE_PAGE + '&with_total=1'),
]);
activeRows = lists[0];
doneRows = lists[1].rows;
doneTotal = lists[1].total;
const last = doneRows[doneRows.length - 1];
doneCursor = last ? { updated_at: last.updated_at, id: last.id } : null;
renderSessionList();
} catch (e) { toast('加载会话失败:' + e.message); }
}
async function loadMoreDone() {
if (doneLoading || !doneCursor) return;
doneLoading = true;
renderSessionList(); // 按钮置灰
try {
const r = await req('GET', '/api/sessions?status=done&limit=' + DONE_PAGE + '&with_total=1' +
'&before=' + encodeURIComponent(doneCursor.updated_at) + '&before_id=' + encodeURIComponent(doneCursor.id));
doneRows = doneRows.concat(r.rows);
doneTotal = r.total;
const last = r.rows[r.rows.length - 1];
if (last) doneCursor = { updated_at: last.updated_at, id: last.id };
else doneTotal = doneRows.length; // 防御:数据变少导致翻页空转,直接隐藏按钮
} catch (e) { toast('加载更多失败:' + e.message); }
doneLoading = false;
renderSessionList();
}
function toggleSearch() {
searchMode = !searchMode;
$('search-bar').classList.toggle('hidden', !searchMode);
const input = $('search-input');
if (searchMode) {
input.focus();
if (input.value.trim()) doSearch();
} else {
input.value = '';
loadSessions();
}
}
async function doSearch() {
const q = $('search-input').value.trim();
if (!q) return loadSessions();
try {
const r = await req('GET', '/api/sessions?q=' + encodeURIComponent(q) + '&limit=50&with_total=1');
const el = $('session-list');
if (!r.rows.length) {
el.innerHTML = '没有找到包含「' + esc(q) + '」的任务
';
return;
}
el.innerHTML = '找到 ' + r.total + ' 个相关任务
' + r.rows.map(sessionCard).join('');
} catch (e) { toast('搜索失败:' + e.message); }
}
// ---------- 待发送附件 ----------
// 选定文件后立即传到任务目录,但**不通知 AI**;下一条用户消息发送时,
// 由服务端在正文前拼【系统通知】一并送达(见 routes/messages.js)。
let pendingFiles = []; // { name, size, pct, status: 'up'|'ok'|'err', xhr? }
function renderAttach() {
const row = $('attach-row');
if (!row) return;
row.classList.toggle('hidden', !pendingFiles.length);
row.innerHTML = pendingFiles.map(function (f, i) {
const st = f.status === 'up' ? (f.pct + '%') : f.status === 'ok' ? '✓' : '失败';
return '' +
'' + esc(f.name) + ' ' + st + ' ' +
'× ';
}).join('');
// 输入框里的回形针图标在上传中换成总进度百分比
const lb = document.getElementById('attach-btn');
const pctEl = $('up-pct');
if (lb && pctEl) {
const ups = pendingFiles.filter(function (f) { return f.status === 'up'; });
lb.classList.toggle('uploading', ups.length > 0);
if (ups.length) {
let done = 0, tot = 0;
for (const f of pendingFiles) { if (f.status === 'err') continue; done += f.size * f.pct / 100; tot += f.size; }
pctEl.textContent = (tot ? Math.round(done / tot * 100) : 0) + '%';
}
}
}
function startUpload(file) {
if (!state.sessionId) return;
const item = { name: file.name, size: file.size, pct: 0, status: 'up' };
pendingFiles.push(item);
renderAttach();
const fd = new FormData();
fd.append('files', file);
const xhr = new XMLHttpRequest();
item.xhr = xhr;
xhr.open('POST', '/api/sessions/' + state.sessionId + '/files');
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) { item.pct = Math.min(99, Math.round(e.loaded / e.total * 100)); renderAttach(); }
};
xhr.onload = function () {
let r = {};
try { r = JSON.parse(xhr.responseText); } catch (_) {}
if (xhr.status === 200 && r.uploaded && r.uploaded[0]) {
item.name = r.uploaded[0].filename; // 以服务端清洗/重命名后的文件名为准
item.size = r.uploaded[0].size;
item.pct = 100;
item.status = 'ok';
} else {
item.status = 'err';
toast('上传失败:' + (r.error || xhr.status));
}
item.xhr = null;
renderAttach();
};
xhr.onerror = function () { item.status = 'err'; item.xhr = null; renderAttach(); toast('上传失败:网络错误'); };
xhr.send(fd);
}
function removeAttach(i) {
const f = pendingFiles[i];
if (!f) return;
if (f.xhr) { try { f.xhr.abort(); } catch (_) {} }
else if (f.status === 'ok' && state.sessionId) {
// 已传完成的附件被移除:连带删掉已落盘的文件,避免任务目录里残留孤儿文件
req('DELETE', '/api/sessions/' + state.sessionId + '/files?path=' + encodeURIComponent(f.name)).catch(function () {});
}
pendingFiles.splice(i, 1);
renderAttach();
}
// 历史消息里的【系统通知】行:展示层拆成附件胶囊行 + 用户原文
function parseUploadNotice(content) {
const m = /^【系统通知】用户上传了文件:([^\n]*)(?:\n([\s\S]*))?$/.exec(content || '');
if (!m) return { text: content || '', files: null };
const files = m[1].split('、').map(function (s) { return s.replace(/(大小[^)]*)$/, '').trim(); }).filter(Boolean);
return { text: m[2] || '', files: files };
}
function attachBubbleLine(names) {
return names && names.length ? '📎 ' + names.map(esc).join(' ') + '
' : '';
}
// ---------- 消息渲染 ----------
function md(text) {
if (typeof marked === 'undefined') return esc(text);
try { return marked.parse(text || ''); } catch (_) { return esc(text); }
}
function renderToolCard(id, name, argsStr) {
const div = document.createElement('div');
div.className = 'tool-card';
div.id = 'tool-' + id;
div.innerHTML =
'◌ ' +
'' + esc(name) + ' ' +
'' + esc(toolArgsSummary(name, argsStr)) + ' ' +
'' + esc(toolArgsFull(argsStr)) + ' ' +
'执行中… ';
return div;
}
function fillToolResult(id, content, isError) {
const card = document.getElementById('tool-' + id);
if (!card) return;
if (isError) card.classList.add('error');
card.querySelector('.spin').textContent = isError ? '✕' : '✓';
const pre = card.querySelector('.tool-result');
if (pre) pre.textContent = content || '(空)';
}
function msgNode(m, cardMap) {
if (m.role === 'tool') {
if (m.tool_call_id && cardMap && cardMap[m.tool_call_id]) {
fillToolResult(m.tool_call_id, m.content, false);
}
return null;
}
const wrap = document.createElement('div');
if (m.role === 'user') {
const p = parseUploadNotice(m.content);
wrap.className = 'msg me';
wrap.innerHTML = '我
' +
'' + attachBubbleLine(p.files) + esc(p.text) + '
' +
'' + fmtTime(m.created_at) + '
';
return wrap;
}
if (m.role === 'assistant') {
wrap.className = 'msg other';
const gray = state.status === 'queued' ? ' gray' : '';
let inner = ' AI' +
(m.model_tag ? ' · ' + esc(m.model_tag) : '') + '
';
if (m.content) inner += '' + md(m.content) + '
';
inner += '' + fmtTime(m.created_at) + '
';
wrap.innerHTML = inner;
return wrap;
}
return null;
}
function appendToolCardsFromAssistant(m, container) {
if (!m.tool_calls) return;
let calls;
try { calls = typeof m.tool_calls === 'string' ? JSON.parse(m.tool_calls) : m.tool_calls; } catch (_) { return; }
for (const c of calls) {
const id = c.id || ('c' + Math.random().toString(36).slice(2, 10));
if (state.toolCards[id]) continue; // tool_call 事件已经建过同一张卡,不重复创建
const card = renderToolCard(id, c.function.name, c.function.arguments);
container.appendChild(card);
state.toolCards[id] = card;
}
}
async function renderDetail(detail) {
const box = $('messages');
box.innerHTML = '';
removePendingBubble();
state.streamEl = null;
state.streamText = '';
state.toolCards = {};
const s = detail.session;
state.status = s.status;
updatePhaseUI({ model_id: s.model_id, queue_pos: detail.queue_pos });
$('chat-title').textContent = s.title || s.id;
for (const m of detail.messages) {
const node = msgNode(m, state.toolCards);
if (node) box.appendChild(node);
if (m.role === 'assistant') appendToolCardsFromAssistant(m, box);
}
if (!detail.messages.length) {
box.innerHTML = '描述你的需求,AI 会和你讨论并直接干活。
';
}
scrollBottom();
loadFiles();
}
function scrollBottom() {
const box = $('messages');
box.scrollTop = box.scrollHeight;
}
// ---------- AI 处理中占位 ----------
// 发送后立即挂一个「思考中 + 秒计时」占位气泡,首个增量/回复/工具卡到达时移除,
// 避免上游慢时长时间无反馈像卡死。
function addPendingBubble() {
removePendingBubble();
const wrap = document.createElement('div');
wrap.className = 'msg other';
const box = $('messages');
const tip = box.querySelector('.empty-tip');
if (tip) tip.remove();
wrap.innerHTML = ' AI
' +
'思考中 ' +
'0s
';
box.appendChild(wrap);
state.pendingEl = wrap;
state.pendingStart = Date.now();
state.pendingTimer = setInterval(() => {
const t = state.pendingEl && state.pendingEl.querySelector('.pending-timer');
if (t) t.textContent = Math.floor((Date.now() - state.pendingStart) / 1000) + 's';
}, 500);
scrollBottom();
}
function removePendingBubble() {
if (state.pendingTimer) { clearInterval(state.pendingTimer); state.pendingTimer = null; }
if (state.pendingEl) { state.pendingEl.remove(); state.pendingEl = null; }
}
// ---------- SSE ----------
function connectStream() {
if (state.es) { state.es.close(); state.es = null; }
const es = new EventSource('/api/sessions/' + state.sessionId + '/stream');
state.es = es;
es.addEventListener('status', ev => {
const d = JSON.parse(ev.data);
state.status = d.status;
updatePhaseUI(d);
});
es.addEventListener('assistant_delta', ev => {
const d = JSON.parse(ev.data);
removePendingBubble();
if (!state.streamEl) {
const wrap = document.createElement('div');
wrap.className = 'msg other';
wrap.innerHTML = ' AI
' +
'
';
state.streamEl = wrap.querySelector('.msg-bubble');
state.streamText = '';
$('messages').appendChild(wrap);
}
state.streamText += d.text;
state.streamEl.textContent = state.streamText;
scrollBottom();
});
es.addEventListener('assistant_message', ev => {
const d = JSON.parse(ev.data);
removePendingBubble();
if (state.streamEl) {
const bubble = state.streamEl;
bubble.innerHTML = md(d.content || '');
state.streamEl = null;
state.streamText = '';
} else if (d.content) {
const box = $('messages');
const wrap = document.createElement('div');
wrap.className = 'msg other';
wrap.innerHTML = ' AI
' +
'' + md(d.content) + '
';
box.appendChild(wrap);
}
if (d.tool_calls) {
appendToolCardsFromAssistant({ tool_calls: d.tool_calls }, $('messages'));
scrollBottom();
}
});
es.addEventListener('tool_call', ev => {
const d = JSON.parse(ev.data);
removePendingBubble(); // 工具卡出现也算即时反馈
if (state.toolCards[d.id]) return; // assistant_message 已建卡(含完整参数),不重复创建
const card = renderToolCard(d.id, d.name, d.arguments);
$('messages').appendChild(card);
state.toolCards[d.id] = card;
scrollBottom();
});
es.addEventListener('tool_result', ev => {
const d = JSON.parse(ev.data);
fillToolResult(d.tool_call_id, d.content, d.is_error);
scrollBottom();
});
es.addEventListener('done', ev => {
removePendingBubble(); // 本轮结束,占位兼终止(如模型报错无回复)
loadSessions();
});
es.addEventListener('error', ev => {
removePendingBubble();
try {
const d = JSON.parse(ev.data);
if (d && d.message) toast('错误:' + d.message);
} catch (_) { /* EventSource 连接错误,自动重连 */ }
});
}
// ---------- 任务状态 ----------
function updatePhaseUI(d) {
const pill = $('status-pill');
const stMap = { queued: '排队中', active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' };
let text = stMap[state.status] || state.status || '--';
if (d && d.queue_pos) text += '(第 ' + d.queue_pos + ' 位)';
// active/held 时附带当前占用的模型
if ((state.status === 'active' || state.status === 'held') && d && d.model_id) {
text += ' · ' + d.model_id;
}
pill.textContent = text;
// 状态胶囊配色:活跃中绿(执行中)、保持中黄(已答完、保持模型中)等;状态栏整体同步染色
pill.className = 'status-pill ' + (state.status || '');
$('phase-bar').className = 'phase-bar ' + (state.status || '');
// 活跃中提供「终止」;保持中改为「断开」(主动放弃保持租约,会话结为已完成)
const btn = $('stop-btn');
const actionable = state.status === 'active' || state.status === 'held';
btn.classList.toggle('hidden', !actionable);
btn.textContent = state.status === 'held' ? '断开' : '终止';
btn.classList.toggle('muted', state.status === 'held');
}
// ---------- 文件 ----------
// 下载:先换一枚短时效签名链接,再 window.location.href 交给浏览器原生下载。
// (fetch+blob 在移动端浏览器会被改名 uuid.bin;原生导航下载按服务端
// Content-Disposition 保留原名,同源自动携带登录 cookie。)
async function downloadFile(name) {
if (!state.sessionId) return;
try {
const r = await req('GET', '/api/sessions/' + state.sessionId + '/files/download-token?path=' + encodeURIComponent(name));
window.location.href = r.url;
} catch (e) {
toast('下载失败:' + e.message);
}
}
async function loadFiles() {
if (!state.sessionId) return;
try {
const files = await req('GET', '/api/sessions/' + state.sessionId + '/files');
const el = $('files-list');
if (!files.length) {
el.innerHTML = '还没有文件。上传文件或在对话中让 AI 生成。
';
return;
}
el.innerHTML = files.map(f => {
return '' + esc(f.filename.split('/').pop() || f.filename) + ' ' +
'' + fmtSize(f.size) + ' ' +
'下载 ' +
'删
';
}).join('');
} catch (e) { toast('读取文件失败:' + e.message); }
}
// ---------- 主逻辑 ----------
const ui = {
downloadFile(name) { return downloadFile(name); },
async openCreate() {
// 每次打开时刷新一次空闲模型列表
const sel = $('new-model');
try {
const rows = await req('GET', '/api/models');
const free = rows.filter(m => !m.is_busy);
sel.innerHTML = free.length
? '自动分配 ' + free.map(m =>
'' + esc(m.display_name || m.id) + ' ').join('')
: '排队等待 ';
} catch (_) { /* 保留默认选项 */ }
$('create-modal').classList.remove('hidden');
$('new-title').focus();
},
closeCreate() { $('create-modal').classList.add('hidden'); },
async createSession() {
try {
const title = $('new-title').value.trim();
const model_id = $('new-model') ? $('new-model').value : '';
const s = await req('POST', '/api/sessions', { title, model_id });
this.closeCreate();
$('new-title').value = '';
await loadSessions();
this.openSession(s.id);
} catch (e) { toast('创建失败:' + e.message); }
},
deleteSession(id) {
state.pendingDeleteId = id;
$('del-dir-check').checked = true;
$('delete-modal-text').textContent = '确定删除会话 ' + id + '?';
$('delete-modal').classList.remove('hidden');
},
closeDelete() {
$('delete-modal').classList.add('hidden');
state.pendingDeleteId = null;
},
async confirmDelete() {
const id = state.pendingDeleteId;
if (!id) { this.closeDelete(); return; }
const delDir = $('del-dir-check').checked;
this.closeDelete();
try {
await req('DELETE', '/api/sessions/' + id + '?delete_dir=' + (delDir ? 'true' : 'false'));
if (state.sessionId === id) this.backToList();
loadSessions();
} catch (e) { toast('删除失败:' + e.message); }
},
async openSession(id) {
state.sessionId = id;
// 待发送附件属于上一个会话的语境,切会话时清空展示(文件已落盘,可在文件面板查看)
pendingFiles = [];
renderAttach();
showChat();
try {
const detail = await req('GET', '/api/sessions/' + id);
await renderDetail(detail);
connectStream();
} catch (e) { toast('打开会话失败:' + e.message); }
},
backToList() {
if (state.es) { state.es.close(); state.es = null; }
removePendingBubble();
state.sessionId = null;
showList();
loadSessions();
},
async send() {
const ta = $('msg-input');
const content = ta.value.trim();
if (!state.sessionId) return;
if (pendingFiles.some(f => f.status === 'up')) { toast('附件上传中,请稍候'); return; }
const atts = pendingFiles.filter(f => f.status === 'ok').map(f => ({ name: f.name, size: f.size }));
if (!content && !atts.length) return;
ta.value = '';
ta.style.height = 'auto';
const box = $('messages');
const tip = box.querySelector('.empty-tip');
if (tip) tip.remove();
try {
const body = { content };
if (atts.length) body.attachments = atts;
const r = await req('POST', '/api/sessions/' + state.sessionId + '/messages', body);
const wrap = document.createElement('div');
wrap.className = 'msg me';
wrap.innerHTML = '我' + (r.delivered === 'queued' ? '(排队中,暂存)' : '') + '
' +
'' + attachBubbleLine(atts.map(a => a.name)) + esc(content) + '
';
box.appendChild(wrap);
// 发送成功后附件已随消息告知 AI;失败的保留,由用户决定重试或移除
pendingFiles = pendingFiles.filter(f => f.status === 'err');
renderAttach();
// 立即给出回馈:占位气泡 + 等待计时,首个增量/回复到达时移除并填充内容
if (r.delivered !== 'queued') addPendingBubble();
scrollBottom();
} catch (e) { toast('发送失败:' + e.message); }
},
toggleFiles(ev) {
// 阻断冒泡,避免开启面板的同一次点击被「点外部自动关闭」监听器立刻关掉
if (ev) ev.stopPropagation();
state.filePanelOpen = !state.filePanelOpen;
$('files-panel').classList.toggle('hidden', !state.filePanelOpen);
if (state.filePanelOpen) loadFiles();
},
async stopSession() {
if (!state.sessionId) return;
const held = state.status === 'held';
try {
if (held) {
await req('POST', '/api/sessions/' + state.sessionId + '/release');
toast('已断开,模型已释放');
} else {
await req('POST', '/api/sessions/' + state.sessionId + '/stop');
toast('已发送终止指令');
}
} catch (e) { toast((held ? '断开失败:' : '终止失败:') + e.message); }
},
async uploadFiles(ev) {
const input = ev.target;
// 必须先快照成数组再清空 input:input.files 是实时 FileList,
// input.value='' 会把它同步掏空(Chrome/Safari),直接 return 导致点了没反应。
const files = Array.prototype.slice.call(input.files || []);
input.value = '';
if (!files.length || !state.sessionId) return;
for (const f of files) startUpload(f); // 多个文件并行上传,进度在回形针图标上汇总
},
removeAttach(i) { removeAttach(i); },
async deleteFile(name) {
if (!await confirmModal('删除文件', '删除文件 ' + name + ' ?', '删除', true)) return;
try {
await req('DELETE', '/api/sessions/' + state.sessionId + '/files?path=' + encodeURIComponent(name));
loadFiles();
} catch (e) { toast('删除失败:' + e.message); }
},
logout() { location.href = '/logout'; },
toggleSearch() { toggleSearch(); },
doSearch() { doSearch(); },
loadMoreDone() { return loadMoreDone(); },
};
// 文件面板展开时,点击面板以外的区域自动关闭
document.addEventListener('click', e => {
if (!state.filePanelOpen) return;
if ($('files-panel').contains(e.target)) return;
state.filePanelOpen = false;
$('files-panel').classList.add('hidden');
});
// ---------- 输入框行为 ----------
document.addEventListener('input', e => {
if (e.target.id === 'msg-input') {
e.target.style.height = 'auto';
e.target.style.height = Math.min(e.target.scrollHeight, 120) + 'px';
}
});
document.addEventListener('keydown', e => {
if (e.target.id !== 'msg-input' || e.key !== 'Enter') return;
if (e.isComposing) return; // 中文输入法候选中,回车不拦截
// 桌面:Ctrl/⌘/⌥+Enter 发送;其余 Enter(含手机软键盘)保持默认换行,发送用右侧按钮
if (e.ctrlKey || e.metaKey || e.altKey) {
e.preventDefault();
ui.send();
}
});
// 搜索框:回车触发搜索;清空后退回普通列表
document.addEventListener('keydown', e => {
if (e.target.id === 'search-input' && e.key === 'Enter' && !e.isComposing) {
e.preventDefault();
doSearch();
}
});
document.addEventListener('input', e => {
if (e.target.id === 'search-input' && !e.target.value.trim()) loadSessions();
});
// ---------- Tab 注册 ----------
window.tabModules = window.tabModules || {};
tabModules.tasks = {
onShow() {
loadSessions();
},
};