加入日志功能
This commit is contained in:
@@ -76,6 +76,12 @@ function saveMessage(sessionId, msg) {
|
||||
).run(sessionId, msg.role, msg.content || null,
|
||||
msg.tool_calls ? JSON.stringify(msg.tool_calls) : null,
|
||||
msg.tool_call_id || null, msg.name || null, now());
|
||||
// 关键动作日志:AI 每轮回复落库(含纯工具调用轮)
|
||||
if (msg.role === 'assistant') {
|
||||
const nTools = msg.tool_calls ? msg.tool_calls.length : 0;
|
||||
console.log('[msg] ' + sessionId + ' AI 回复:文本 ' + String(msg.content || '').length + ' 字' +
|
||||
(nTools ? ',工具调用 ×' + nTools : ''));
|
||||
}
|
||||
return info.lastInsertRowid;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ body {
|
||||
/* ---- 顶部栏 ---- */
|
||||
.header {
|
||||
display: flex; align-items: center;
|
||||
background: linear-gradient(135deg, #1e3c72, #2a5299);
|
||||
background: linear-gradient(135deg, #3964FE, #4D74FF);
|
||||
color: #fff; padding: 12px 12px;
|
||||
padding-top: calc(12px + env(safe-area-inset-top));
|
||||
gap: 8px;
|
||||
@@ -63,7 +63,7 @@ body {
|
||||
.session-meta { font-size: 12px; color: #888; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
.badge { font-size: 11px; padding: 1px 7px; border-radius: 8px; white-space: nowrap; }
|
||||
.badge.active { background: #e3f2e6; color: #217a34; }
|
||||
.badge.queued { background: #e8eefc; color: #4a5f87; }
|
||||
.badge.queued { background: #e9edff; color: #3964FE; }
|
||||
.badge.completed { background: #eceff5; color: #5c6674; }
|
||||
.badge.held { background: #fff4dc; color: #a06a00; }
|
||||
.badge.cancelled { background: #fdecea; color: #b3382c; }
|
||||
@@ -74,8 +74,8 @@ body {
|
||||
flex: 1; border: 1px solid #dde1ea; border-radius: 18px; padding: 8px 14px;
|
||||
font-size: 14px; background: #fff; outline: none; color: #222; appearance: none;
|
||||
}
|
||||
.search-bar input:focus { border-color: #2a5299; }
|
||||
.search-cancel { background: none; border: none; color: #2a5299; font-size: 14px; padding: 6px 4px; cursor: pointer; flex: none; }
|
||||
.search-bar input:focus { border-color: #3964FE; }
|
||||
.search-cancel { background: none; border: none; color: #3964FE; font-size: 14px; padding: 6px 4px; cursor: pointer; flex: none; }
|
||||
.search-tip { color: #8891a5; font-size: 12px; padding: 2px 4px 8px; }
|
||||
.load-more {
|
||||
width: 100%; background: #f2f3f7; color: #445;
|
||||
@@ -106,7 +106,7 @@ body {
|
||||
.status-pill.active { background: #e3f2e6; color: #1c7a2e; }
|
||||
.status-pill.active::before { animation: pill-pulse 1.2s ease-in-out infinite; }
|
||||
.status-pill.held { background: #fff4dc; color: #8a6400; }
|
||||
.status-pill.queued { background: #e8eefc; color: #4a5f87; }
|
||||
.status-pill.queued { background: #e9edff; color: #3964FE; }
|
||||
.status-pill.cancelled { background: #fdecea; color: #b3382c; }
|
||||
@keyframes pill-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
|
||||
.stop-link {
|
||||
@@ -128,7 +128,7 @@ body {
|
||||
.msg-user { font-size: 11px; color: #98a; margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
|
||||
.ai-avatar {
|
||||
width: 18px; height: 18px; border-radius: 50%;
|
||||
background: linear-gradient(135deg, #2a5299, #4d7fd6);
|
||||
background: linear-gradient(135deg, #3964FE, #6E8BFF);
|
||||
display: inline-block;
|
||||
}
|
||||
.ai-avatar.gray { background: #b9bec9; filter: grayscale(); }
|
||||
@@ -137,7 +137,7 @@ body {
|
||||
word-break: break-word; overflow-wrap: break-word; font-size: 14.5px;
|
||||
background: #fff; box-shadow: 0 1px 3px rgba(30,40,90,0.07);
|
||||
}
|
||||
.msg.me .msg-bubble { background: #d7e7ff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
|
||||
.msg.me .msg-bubble { background: #e3eaff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
|
||||
.msg.other .msg-bubble { border-bottom-left-radius: 4px; }
|
||||
.msg-bubble pre {
|
||||
background: #f0f2f6; padding: 8px 10px; border-radius: 8px;
|
||||
@@ -202,7 +202,7 @@ body {
|
||||
.file-row:active { background: #f4f5f9; }
|
||||
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.file-size { color: #99a; font-size: 12px; }
|
||||
.file-act { color: #2a5299; text-decoration: none; font-size: 13px; padding: 2px 6px; background: none; border: none; cursor: pointer; }
|
||||
.file-act { color: #3964FE; text-decoration: none; font-size: 13px; padding: 2px 6px; background: none; border: none; cursor: pointer; }
|
||||
.file-act.del { color: #c33; }
|
||||
.empty-tip { color: #99a; text-align: center; padding: 18px; font-size: 13px; }
|
||||
|
||||
@@ -210,16 +210,16 @@ body {
|
||||
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 6px; }
|
||||
.attach-chip {
|
||||
display: flex; align-items: center; gap: 6px; max-width: 100%;
|
||||
background: #fff; border: 1px solid #d5deee; border-radius: 14px;
|
||||
background: #fff; border: 1px solid #dbe4ff; border-radius: 14px;
|
||||
padding: 4px 10px; font-size: 12px; color: #334;
|
||||
}
|
||||
.attach-chip .nm { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.attach-chip .st { color: #2a5299; flex: none; }
|
||||
.attach-chip .st { color: #3964FE; flex: none; }
|
||||
.attach-chip.err { border-color: #eac2bd; color: #c0392b; }
|
||||
.attach-chip.err .st { color: #c0392b; }
|
||||
.attach-chip .x { color: #99a; background: none; border: none; font-size: 14px; line-height: 1; padding: 0 2px; cursor: pointer; }
|
||||
.file-upload-btn.uploading svg { display: none; }
|
||||
.up-pct { font-size: 11px; font-weight: 600; color: #2a5299; }
|
||||
.up-pct { font-size: 11px; font-weight: 600; color: #3964FE; }
|
||||
/* 消息气泡内的附件行 */
|
||||
.msg-files { font-size: 12px; opacity: 0.85; margin-bottom: 4px; word-break: break-all; }
|
||||
|
||||
@@ -244,7 +244,7 @@ body {
|
||||
.file-upload-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.send-btn {
|
||||
width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
|
||||
background: linear-gradient(135deg, #2a5299, #4d7fd6);
|
||||
background: linear-gradient(135deg, #3964FE, #6E8BFF);
|
||||
display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
|
||||
}
|
||||
.send-btn:active { opacity: 0.8; }
|
||||
@@ -264,14 +264,14 @@ body {
|
||||
width: 1; border: 1px solid #dde; border-radius: 8px;
|
||||
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
|
||||
}
|
||||
.modal input:focus { border-color: #2a5299; }
|
||||
.modal input:focus { border-color: #3964FE; }
|
||||
.modal input:disabled { background: #f2f3f7; color: #99a; }
|
||||
.modal select {
|
||||
width: 100%; border: 1px solid #dde; border-radius: 8px;
|
||||
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
|
||||
background: #fff; color: #334; appearance: none;
|
||||
}
|
||||
.modal select:focus { border-color: #2a5299; }
|
||||
.modal select:focus { border-color: #3964FE; }
|
||||
.modal-close-btn {
|
||||
position: absolute; right: 10px; top: 10px;
|
||||
background: none; border: none; cursor: pointer; color: #99a;
|
||||
@@ -279,7 +279,7 @@ body {
|
||||
}
|
||||
.modal-close-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
|
||||
.primary-btn {
|
||||
width: 1; background: linear-gradient(135deg, #1e3c72, #2a5299);
|
||||
width: 1; background: linear-gradient(135deg, #3964FE, #4D74FF);
|
||||
color: #fff; border: none; border-radius: 10px; padding: 11px;
|
||||
font-size: 15px; font-weight: 600; cursor: pointer;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ body {
|
||||
-webkit-tap-highlight-color: transparent; user-select: none;
|
||||
}
|
||||
.tab-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.tab-item.active { color: #2a5299; font-weight: 600; }
|
||||
.tab-item.active { color: #3964FE; font-weight: 600; }
|
||||
.tab-item:active { opacity: 0.7; }
|
||||
|
||||
/* Tab 内容页:占满除底部导航外的区域(导航隐藏时被聊天页盖住,无影响) */
|
||||
@@ -377,7 +377,7 @@ body {
|
||||
/* 列表卡右侧操作钮 */
|
||||
.card-acts { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; flex-shrink: 0; }
|
||||
.card-act {
|
||||
background: #eef3fc; color: #2a5299; border: none; border-radius: 8px;
|
||||
background: #eaefff; color: #3964FE; border: none; border-radius: 8px;
|
||||
font-size: 12px; padding: 5px 10px; cursor: pointer;
|
||||
}
|
||||
.card-act.del { background: #fdecea; color: #c0392b; }
|
||||
@@ -398,7 +398,7 @@ body {
|
||||
background: #f2f3f7; color: #8a93a6; font-size: 11px;
|
||||
padding: 2px 8px; border-radius: 9px; flex-shrink: 0;
|
||||
}
|
||||
.skill-files .file-act { background: #eef3fc; border-radius: 7px; padding: 4px 9px; flex-shrink: 0; }
|
||||
.skill-files .file-act { background: #eaefff; border-radius: 7px; padding: 4px 9px; flex-shrink: 0; }
|
||||
.skill-files .file-act.del { background: #fdecea; color: #c0392b; }
|
||||
/* 代码/配置编辑器:全屏覆盖所在 Tab(盖住列表/详情与顶栏,不遮底部导航) */
|
||||
#skill-editor, #cfg-editor {
|
||||
@@ -438,7 +438,7 @@ body {
|
||||
padding: 6px 10px; outline: none; font-variant-numeric: tabular-nums; font-family: inherit;
|
||||
-webkit-appearance: none; appearance: none;
|
||||
}
|
||||
.cfg-input:focus { border-color: #2a5299; background: #fff; }
|
||||
.cfg-input:focus { border-color: #3964FE; background: #fff; }
|
||||
.cfg-input::-webkit-outer-spin-button, .cfg-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
/* 改了但还没保存的项标红 */
|
||||
.cfg-input.cfg-dirty { color: #c0392b; border-color: #e8b4b0; background: #fdf3f2; }
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>Agent 任务台</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<meta name="theme-color" content="#1e3c72">
|
||||
<meta name="theme-color" content="#3964FE">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
@@ -282,10 +282,10 @@
|
||||
<div class="toast hidden" id="toast"></div>
|
||||
|
||||
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
|
||||
<script src="/js/core.js?v=20260901r"></script>
|
||||
<script src="/js/tasks.js?v=20260901r"></script>
|
||||
<script src="/js/skills.js?v=20260901r"></script>
|
||||
<script src="/js/models.js?v=20260901r"></script>
|
||||
<script src="/js/settings.js?v=20260901r"></script>
|
||||
<script src="/js/core.js?v=20260902b"></script>
|
||||
<script src="/js/tasks.js?v=20260902b"></script>
|
||||
<script src="/js/skills.js?v=20260902b"></script>
|
||||
<script src="/js/models.js?v=20260902b"></script>
|
||||
<script src="/js/settings.js?v=20260902b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -277,8 +277,7 @@ function msgNode(m, cardMap) {
|
||||
const p = parseUploadNotice(m.content);
|
||||
wrap.className = 'msg me';
|
||||
wrap.innerHTML = '<div class="msg-user">我</div>' +
|
||||
'<div class="msg-bubble">' + attachBubbleLine(p.files) + esc(p.text) + '</div>';
|
||||
} else if (m.role === 'assistant' && (m.content || !m.tool_calls)) {
|
||||
'<div class="msg-bubble">' + attachBubbleLine(p.files) + esc(p.text) + '</div>' +
|
||||
'<div class="msg-time">' + fmtTime(m.created_at) + '</div>';
|
||||
return wrap;
|
||||
}
|
||||
@@ -612,9 +611,11 @@ const ui = {
|
||||
},
|
||||
async uploadFiles(ev) {
|
||||
const input = ev.target;
|
||||
const files = input.files;
|
||||
// 必须先快照成数组再清空 input:input.files 是实时 FileList,
|
||||
// input.value='' 会把它同步掏空(Chrome/Safari),直接 return 导致点了没反应。
|
||||
const files = Array.prototype.slice.call(input.files || []);
|
||||
input.value = '';
|
||||
if (!files || !files.length || !state.sessionId) return;
|
||||
if (!files.length || !state.sessionId) return;
|
||||
for (const f of files) startUpload(f); // 多个文件并行上传,进度在回形针图标上汇总
|
||||
},
|
||||
removeAttach(i) { removeAttach(i); },
|
||||
|
||||
@@ -61,6 +61,7 @@ router.put('/', wrap((req, res) => {
|
||||
let next;
|
||||
try { next = loadConfigFromText(text, cfg.config_path); } catch (e) { return badRequest(res, e); }
|
||||
writeConfigText(cfg, text);
|
||||
console.log('[config] ' + (req.user || '-') + ' 整文件保存配置,变更段:' + (diffTop(cfg, next).join(',') || '无'));
|
||||
res.json({ ok: true, changed: diffTop(cfg, next), restart_required: true });
|
||||
}));
|
||||
|
||||
@@ -83,6 +84,7 @@ router.patch('/', wrap((req, res) => {
|
||||
let next;
|
||||
try { next = loadConfigFromText(nextText, cfg.config_path); } catch (e) { return badRequest(res, e); }
|
||||
writeConfigText(cfg, nextText);
|
||||
console.log('[config] ' + (req.user || '-') + ' 修改配置项 ' + pathArr.join('.') + (body.op === 'delete' ? '(删除)' : '') + ',变更段:' + (diffTop(cfg, next).join(',') || '无'));
|
||||
res.json({ ok: true, changed: diffTop(cfg, next), restart_required: true });
|
||||
}));
|
||||
|
||||
|
||||
@@ -64,6 +64,10 @@ router.post('/:id/files', upload.array('files', 10), function (req, res) {
|
||||
.run(req.params.id, f.filename, f.size, Date.now());
|
||||
}
|
||||
// 不再自动通知 AI:附件随用户下一条消息统一告知(见 routes/messages.js 的 attachments)
|
||||
if (uploaded.length) {
|
||||
console.log('[file] ' + (req.user || '-') + ' ' + req.params.id + ' 上传 ' + uploaded.length + ' 个文件:' +
|
||||
uploaded.map(f => f.filename + '(' + f.size + 'B)').join('、'));
|
||||
}
|
||||
res.json({ uploaded });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: String(err && err.message || err) });
|
||||
@@ -159,6 +163,7 @@ router.delete('/:id/files', function (req, res) {
|
||||
fs.rmSync(abs, { recursive: true, force: true });
|
||||
engine.getDb().prepare('DELETE FROM files WHERE session_id = ? AND filename = ?')
|
||||
.run(req.params.id, rel);
|
||||
console.log('[file] ' + (req.user || '-') + ' ' + req.params.id + ' 删除文件 ' + rel);
|
||||
res.json({ ok: true });
|
||||
} catch (err) {
|
||||
res.status(404).json({ error: '文件不存在' });
|
||||
|
||||
@@ -41,6 +41,8 @@ router.post('/:id/messages', wrap((req, res) => {
|
||||
);
|
||||
if (!content) return res.status(400).json({ error: 'content 不能为空' });
|
||||
const r = engine.postUserMessage(req.params.id, content);
|
||||
console.log('[msg] ' + (req.user || '-') + ' ' + req.params.id + ' 用户消息(' + (r && r.delivered || '?') + '):' +
|
||||
content.slice(0, 60).replace(/\s+/g, ' '));
|
||||
res.json(r);
|
||||
}));
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ router.post('/', wrap((req, res) => {
|
||||
const title = (req.body && req.body.title || '').trim();
|
||||
const modelId = (req.body && req.body.model_id || '').trim();
|
||||
const session = engine.createSession(title, modelId);
|
||||
console.log('[task] ' + (req.user || '-') + ' 新建任务 ' + session.id + '「' + (session.title || '未命名') + '」model=' + (modelId || '自动'));
|
||||
res.json(session);
|
||||
}));
|
||||
|
||||
@@ -120,6 +121,7 @@ router.get('/:id', wrap((req, res) => {
|
||||
|
||||
router.delete('/:id', wrap((req, res) => {
|
||||
const delDir = req.query.delete_dir === 'true' || req.query.delete_dir === '';
|
||||
console.log('[task] ' + (req.user || '-') + ' 删除任务 ' + req.params.id + (delDir ? '(含任务目录)' : ''));
|
||||
res.json(engine.deleteSession(req.params.id, delDir));
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user