feat(engine): 会话目录改为首次调工具时才建,纯文本对话不再留空目录
建目录原来在 createSession 里,纯文本会话也照建,磁盘上越积越多(线上 119 个 会话目录里 39 个是空的)。改成在 executeTool 入口懒建:会话只算路径,第一次 真正用到工具(含技能递归调用)才 mkdir;上传/写文件本来就自带 mkdir,只读路径 (文件树、下载、公链、预览)维持「不存在即空/404」。
This commit is contained in:
@@ -1238,11 +1238,10 @@ function createSession(title, preferModelId, assistantType, user, workDir) {
|
||||
if (!modelId) throw Object.assign(new Error('无可用模型:请检查配置并重启服务'), { status_code: 503 });
|
||||
}
|
||||
const id = genTaskId();
|
||||
// 手选目录:直接当作会话工作目录(不建 task-* 子目录);未选 = 老行为,在 workspace_root 下按 id 建档。
|
||||
// 手选目录:直接当作会话工作目录(不建 task-* 子目录);未选 = 沿用 workspace_root/<会话id>。
|
||||
// 选中的目录必须已存在(normalizeWorkDir 已校验),绝不在用户目录里替它 mkdir。
|
||||
// 两种情况下目录都由工具执行时懒建(见 tools/executor.js 的 executeTool),纯文本对话不留空目录。
|
||||
const wd = normalizeWorkDir(workDir);
|
||||
const dir = wd || path.join(cfg.workspace_root, id);
|
||||
if (!wd) fs.mkdirSync(dir, { recursive: true });
|
||||
db.prepare(
|
||||
"INSERT INTO sessions (id, title, status, model_id, model_slot, last_model_id, held_at, assistant_type, user, work_dir, created_at, updated_at) VALUES (?,?,'held',?,?,?,?,?,?,?,?,?)"
|
||||
).run(id, title || '', modelId, key.id, modelId, now(), assistantType || 'secretary', user || '', wd, now(), now());
|
||||
|
||||
@@ -1798,6 +1798,8 @@ const HANDLERS = {
|
||||
// (见 imageReceipt),image_rel 缺省表示本次不投递像素。
|
||||
// 内置工具优先;未命中时交给 MCP 注册表(启动时发现的服务工具)。
|
||||
async function executeTool(baseCtx, name, args) {
|
||||
// 会话目录懒建:会话创建时不再占坑,第一次真用到工具才建(纯文本对话不留空目录)。
|
||||
try { if (baseCtx && baseCtx.taskDir) fs.mkdirSync(baseCtx.taskDir, { recursive: true }); } catch (_) {}
|
||||
const handler = HANDLERS[name];
|
||||
if (handler) return handler(baseCtx, args || {});
|
||||
if (mcp.hasTool(name)) return mcp.callTool(name, args || {}, baseCtx); // baseCtx.taskDir → X-Session-Dir 头下发给 MCP 服务
|
||||
|
||||
Reference in New Issue
Block a user