加入会话创建者字段:建档时记录 req.user,列表按当前用户过滤(未启用认证不过滤)
This commit is contained in:
@@ -18,6 +18,7 @@ function initDb(dbPath) {
|
||||
model_id TEXT,
|
||||
last_model_id TEXT,
|
||||
assistant_type TEXT DEFAULT 'secretary',
|
||||
user TEXT DEFAULT '',
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
completed_at INTEGER,
|
||||
@@ -100,6 +101,11 @@ function initDb(dbPath) {
|
||||
if (!cols.some(c => c.name === 'assistant_type')) {
|
||||
db.exec("ALTER TABLE sessions ADD COLUMN assistant_type TEXT DEFAULT 'secretary'");
|
||||
}
|
||||
// 迁移:user 记录建档时的登录用户,列表接口据此按用户隔离;
|
||||
// 存量老会话与未启用认证时建的会话为空串(见 routes/sessions.js 列表过滤)
|
||||
if (!cols.some(c => c.name === 'user')) {
|
||||
db.exec("ALTER TABLE sessions ADD COLUMN user TEXT DEFAULT ''");
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
@@ -681,13 +681,13 @@ function loadHistoryForModel(sessionId) {
|
||||
.concat(rows.filter(r => r.name !== SESSION_CONTEXT_NAME));
|
||||
}
|
||||
|
||||
function createSession(title, preferModelId, assistantType) {
|
||||
function createSession(title, preferModelId, assistantType, user) {
|
||||
const id = genTaskId();
|
||||
const dir = taskDirOf(id);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
db.prepare(
|
||||
"INSERT INTO sessions (id, title, status, phase, model_id, assistant_type, created_at, updated_at) VALUES (?,?,'queued','planning',NULL,?,?,?)"
|
||||
).run(id, title || '', assistantType || 'secretary', now(), now());
|
||||
"INSERT INTO sessions (id, title, status, phase, model_id, assistant_type, user, created_at, updated_at) VALUES (?,?,'queued','planning',NULL,?,?,?,?)"
|
||||
).run(id, title || '', assistantType || 'secretary', user || '', now(), now());
|
||||
// 指定了模型且它恰好空闲 → 直接绑定,跳过排队;否则回退到 FIFO 队列
|
||||
const prefer = preferModelId
|
||||
? db.prepare('SELECT * FROM model_pool WHERE id = ? AND is_busy = 0').get(preferModelId)
|
||||
|
||||
@@ -51,7 +51,9 @@ router.post('/', wrap((req, res) => {
|
||||
const modelId = (req.body && req.body.model_id || '').trim();
|
||||
// 助手类型建档时锁定,后续不可变更;缺省按文秘助理
|
||||
const assistantType = String((req.body && req.body.assistant_type) || 'secretary').trim().slice(0, 32) || 'secretary';
|
||||
const session = engine.createSession(title, modelId, assistantType);
|
||||
// 创建者取认证中间件的 req.user(不信客户端传参);未启用认证时为空串
|
||||
const user = String(req.user || '').trim().slice(0, 64);
|
||||
const session = engine.createSession(title, modelId, assistantType, user);
|
||||
log.info('[task] ' + (req.user || '-') + ' 新建任务 ' + session.id + '「' + (session.title || '未命名') + '」model=' + (modelId || '自动') + ' type=' + (session.assistant_type || 'secretary'));
|
||||
res.json(session);
|
||||
}));
|
||||
@@ -72,6 +74,9 @@ router.get('/', wrap((req, res) => {
|
||||
|
||||
const where = [];
|
||||
const args = [];
|
||||
// 按创建者隔离:已登录只列自己的会话;未启用认证(req.user 空)不过滤,保持自用场景全可见
|
||||
const me = String(req.user || '').trim();
|
||||
if (me) { where.push('user = ?'); args.push(me); }
|
||||
if (status === 'active') where.push("status IN ('queued','active','held')");
|
||||
else if (status === 'done') where.push("status IN ('completed','cancelled')");
|
||||
if (q) {
|
||||
|
||||
Reference in New Issue
Block a user