feat(local): 新建会话可手选工作目录,AI 直接在所选目录干活
- 后端核心只动 taskDirOf:sessions.work_dir 非空即会话工作目录,不建 task-* 子目录;空串行为与旧版一致(服务器形态恒为空) - db 幂等迁移加 work_dir 列 - createSession 校验并接受手选目录(必须已存在、拒绝根目录与平台数据目录);deleteSession 绝不删用户所选目录 - fsRoot 优先 ctx.workDir;@会话 按目标会话 work_dir 解析 - 新增 routes/local.js:osascript/zenity/kdialog 原生选目录,仅 AGENT_LOCAL_PICK=1 时挂载 - 欢迎页加工作目录 chip:选择只暂存前端,建档时随 POST /api/sessions 提交 - local/start.sh 注入 AGENT_LOCAL_PICK=1;同步 AGENTS/README/docs
This commit is contained in:
@@ -127,6 +127,61 @@ main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
/* 本地端:新建会话手选工作目录(服务器形态由 JS 整块隐藏)。 */
|
||||
.welcome-dir {
|
||||
margin-top: 18px;
|
||||
max-width: min(90vw, 560px);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 999px;
|
||||
background: var(--surface);
|
||||
font-size: 13px;
|
||||
color: var(--ink);
|
||||
}
|
||||
.welcome-dir-cap { flex: 0 0 auto; opacity: .6; }
|
||||
.welcome-dir-pick {
|
||||
min-width: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.welcome-dir-pick:disabled { opacity: .6; cursor: default; }
|
||||
.welcome-dir-pick .ic { flex: 0 0 auto; color: var(--active); }
|
||||
.welcome-dir-path {
|
||||
max-width: 44ch;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.welcome-dir.is-set .welcome-dir-path { color: var(--active); }
|
||||
.welcome-dir-clear {
|
||||
flex: 0 0 auto;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: none;
|
||||
color: var(--ink);
|
||||
opacity: .5;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.welcome-dir-clear:hover { opacity: 1; background: var(--border); }
|
||||
.welcome-dir-clear .ic { width: 12px; height: 12px; }
|
||||
|
||||
/* ---------- 对话状态:对话内容区 ---------- */
|
||||
/* overflow-x 显式 hidden:overflow-y:auto 会把 visible 的 overflow-x 计算成 auto,
|
||||
宽代码块/表格自带横向滚动,不该再让消息流整体横向溢出 */
|
||||
|
||||
@@ -151,6 +151,18 @@
|
||||
</div>
|
||||
<div class="welcome-slogan">随时开始吧</div>
|
||||
</div>
|
||||
<!-- 本地端:新建会话时手选工作目录(服务器形态由 JS 整块隐藏)。
|
||||
只暂存在前端,真正建档时随 POST /api/sessions 提交一次;不选 = 老行为。 -->
|
||||
<div class="welcome-dir hidden" id="welcome-dir">
|
||||
<span class="welcome-dir-cap">工作目录</span>
|
||||
<button type="button" class="welcome-dir-pick" id="welcome-dir-pick" title="选择本会话的工作目录">
|
||||
<svg class="ic sm" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path></svg>
|
||||
<span class="welcome-dir-path" id="welcome-dir-path">默认</span>
|
||||
</button>
|
||||
<button type="button" class="welcome-dir-clear hidden" id="welcome-dir-clear" title="恢复默认目录" aria-label="恢复默认目录">
|
||||
<svg class="ic sm" viewBox="0 0 24 24"><line x1="6" y1="6" x2="18" y2="18"></line><line x1="18" y1="6" x2="6" y2="18"></line></svg>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ================= 对话状态:对话内容区 ================= -->
|
||||
|
||||
@@ -231,7 +231,7 @@
|
||||
// welcome 经弹窗预选的模型在这里兑现:model_id 建档透传。
|
||||
async function ensureSession() {
|
||||
if (state.sessionId) return state.sessionId;
|
||||
const s = await req('POST', '/api/sessions', { title: '', model_id: state.pendingModel || '', assistant_type: state.mode });
|
||||
const s = await req('POST', '/api/sessions', { title: '', model_id: state.pendingModel || '', assistant_type: state.mode, work_dir: pendingWorkDir || undefined });
|
||||
state.sessionId = s.id;
|
||||
state.sessionTitle = (s && s.title) || '';
|
||||
state.sessionType = (s && s.assistant_type) || state.mode;
|
||||
@@ -243,6 +243,49 @@
|
||||
return s.id;
|
||||
}
|
||||
|
||||
// ---------- 本地端:新建会话时手选工作目录 ----------
|
||||
// 只在 local/ 启动器(AGENT_LOCAL_PICK=1)下可用:探测 /api/local/info,拿不到就把整条
|
||||
// chip 隐藏,服务器形态完全看不见这个入口。选择只暂存在前端,真正建档时随
|
||||
// POST /api/sessions 提交一次;不选 = work_dir 空串 = 老行为(workspace_root/<会话id>)。
|
||||
let pendingWorkDir = '';
|
||||
|
||||
function renderWelcomeDir() {
|
||||
const pathEl = $('welcome-dir-path');
|
||||
if (!pathEl) return;
|
||||
const chip = $('welcome-dir');
|
||||
pathEl.textContent = pendingWorkDir || '默认(工作区内)';
|
||||
pathEl.title = pendingWorkDir || '默认:每个会话在系统工作目录下单独建档';
|
||||
chip.classList.toggle('is-set', !!pendingWorkDir);
|
||||
$('welcome-dir-clear').classList.toggle('hidden', !pendingWorkDir);
|
||||
}
|
||||
|
||||
async function pickWelcomeDir() {
|
||||
const btn = $('welcome-dir-pick');
|
||||
if (btn.disabled) return;
|
||||
btn.disabled = true;
|
||||
try {
|
||||
// 超时给足 130s:后端对话框上限 120s,这里多留余量,别让前端先断
|
||||
const r = await req('POST', '/api/local/pick-dir', {}, false, 130000);
|
||||
if (r && r.path) { pendingWorkDir = r.path; renderWelcomeDir(); }
|
||||
} catch (e) {
|
||||
toast('选择目录失败:' + e.message);
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
(function initWelcomeDir() {
|
||||
const chip = $('welcome-dir');
|
||||
if (!chip) return;
|
||||
req('GET', '/api/local/info').then(info => {
|
||||
if (!info || !info.enabled) return;
|
||||
chip.classList.remove('hidden');
|
||||
renderWelcomeDir();
|
||||
}).catch(() => { /* 服务器形态:接口 404,整条隐藏 */ });
|
||||
$('welcome-dir-pick').addEventListener('click', pickWelcomeDir);
|
||||
$('welcome-dir-clear').addEventListener('click', () => { pendingWorkDir = ''; renderWelcomeDir(); });
|
||||
})();
|
||||
|
||||
function newChat() {
|
||||
closeStream();
|
||||
removeTyping();
|
||||
@@ -257,6 +300,8 @@
|
||||
renderSendQueue();
|
||||
state.pendingModel = '';
|
||||
state.attachments = [];
|
||||
pendingWorkDir = ''; // 新建会话把上次手选的工作目录也归零(回到默认)
|
||||
renderWelcomeDir();
|
||||
if (typeof clearEditState === 'function') clearEditState();
|
||||
state.streamEl = null;
|
||||
state.streamText = '';
|
||||
|
||||
Reference in New Issue
Block a user