会话标题可点击重命名
This commit is contained in:
@@ -716,6 +716,18 @@ function stop(sessionId) {
|
|||||||
return { ok: true };
|
return { ok: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重命名会话:标题必填,最长 100 字。
|
||||||
|
function renameSession(sessionId, title) {
|
||||||
|
const s = getSession(sessionId);
|
||||||
|
if (!s) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
|
||||||
|
const t = String(title || '').trim();
|
||||||
|
if (!t) throw Object.assign(new Error('名称不能为空'), { status_code: 400 });
|
||||||
|
if (t.length > 100) throw Object.assign(new Error('名称不能超过 100 字'), { status_code: 400 });
|
||||||
|
touch(sessionId, { title: t });
|
||||||
|
log.info('[task] ' + sessionId + ' 重命名为「' + t + '」');
|
||||||
|
return { ok: true, title: t };
|
||||||
|
}
|
||||||
|
|
||||||
function deleteSession(sessionId, deleteDir) {
|
function deleteSession(sessionId, deleteDir) {
|
||||||
const session = getSession(sessionId);
|
const session = getSession(sessionId);
|
||||||
if (!session) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
|
if (!session) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
|
||||||
@@ -745,6 +757,7 @@ module.exports = {
|
|||||||
startExecution,
|
startExecution,
|
||||||
stop,
|
stop,
|
||||||
releaseHold,
|
releaseHold,
|
||||||
|
renameSession,
|
||||||
deleteSession,
|
deleteSession,
|
||||||
getSession,
|
getSession,
|
||||||
getRun,
|
getRun,
|
||||||
|
|||||||
@@ -143,7 +143,7 @@
|
|||||||
<button class="icon-btn back-btn" onclick="ui.backToList()">
|
<button class="icon-btn back-btn" onclick="ui.backToList()">
|
||||||
<svg viewBox="0 0 24 24"><polyline points="15 18 9 12 15 6"></polyline></svg>
|
<svg viewBox="0 0 24 24"><polyline points="15 18 9 12 15 6"></polyline></svg>
|
||||||
</button>
|
</button>
|
||||||
<span class="chat-title" id="chat-title"></span>
|
<span class="chat-title" id="chat-title" onclick="ui.renameSession()" title="点击重命名" style="cursor:pointer"></span>
|
||||||
<div class="header-right">
|
<div class="header-right">
|
||||||
<button class="icon-btn" onclick="ui.toggleFiles(event)" title="文件">
|
<button class="icon-btn" onclick="ui.toggleFiles(event)" title="文件">
|
||||||
<svg viewBox="0 0 24 24"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>
|
<svg viewBox="0 0 24 24"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>
|
||||||
@@ -295,10 +295,10 @@
|
|||||||
<div class="toast hidden" id="toast"></div>
|
<div class="toast hidden" id="toast"></div>
|
||||||
|
|
||||||
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
|
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
|
||||||
<script src="/js/core.js?v=20260902c"></script>
|
<script src="/js/core.js?v=20260902d"></script>
|
||||||
<script src="/js/tasks.js?v=20260902c"></script>
|
<script src="/js/tasks.js?v=20260902d"></script>
|
||||||
<script src="/js/skills.js?v=20260902c"></script>
|
<script src="/js/skills.js?v=20260902d"></script>
|
||||||
<script src="/js/models.js?v=20260902c"></script>
|
<script src="/js/models.js?v=20260902d"></script>
|
||||||
<script src="/js/settings.js?v=20260902c"></script>
|
<script src="/js/settings.js?v=20260902d"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -538,6 +538,18 @@ const ui = {
|
|||||||
$('new-title').focus();
|
$('new-title').focus();
|
||||||
},
|
},
|
||||||
closeCreate() { $('create-modal').classList.add('hidden'); },
|
closeCreate() { $('create-modal').classList.add('hidden'); },
|
||||||
|
async renameSession() {
|
||||||
|
if (!state.sessionId) return;
|
||||||
|
const cur = $('chat-title').textContent;
|
||||||
|
const t = await promptModal('重命名会话', '输入新的会话名称', cur === state.sessionId ? '' : cur);
|
||||||
|
if (t === null) return; // 取消
|
||||||
|
try {
|
||||||
|
await req('PATCH', '/api/sessions/' + state.sessionId, { title: t });
|
||||||
|
toast('已重命名');
|
||||||
|
$('chat-title').textContent = t.trim();
|
||||||
|
loadSessions();
|
||||||
|
} catch (e) { toast('重命名失败:' + e.message); }
|
||||||
|
},
|
||||||
async openModelSwitch() {
|
async openModelSwitch() {
|
||||||
if (!state.sessionId) return;
|
if (!state.sessionId) return;
|
||||||
const list = $('bind-model-list');
|
const list = $('bind-model-list');
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ router.post('/:id/bind', wrap((req, res) => {
|
|||||||
res.json(engine.bindToSession(req.params.id, req.body && req.body.model_id));
|
res.json(engine.bindToSession(req.params.id, req.body && req.body.model_id));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
router.patch('/:id', wrap((req, res) => {
|
||||||
|
res.json(engine.renameSession(req.params.id, req.body && req.body.title));
|
||||||
|
}));
|
||||||
|
|
||||||
router.delete('/:id', wrap((req, res) => {
|
router.delete('/:id', wrap((req, res) => {
|
||||||
const delDir = req.query.delete_dir === 'true' || req.query.delete_dir === '';
|
const delDir = req.query.delete_dir === 'true' || req.query.delete_dir === '';
|
||||||
log.info('[task] ' + (req.user || '-') + ' 删除任务 ' + req.params.id + (delDir ? '(含任务目录)' : ''));
|
log.info('[task] ' + (req.user || '-') + ' 删除任务 ' + req.params.id + (delDir ? '(含任务目录)' : ''));
|
||||||
|
|||||||
Reference in New Issue
Block a user