agent-loft 0.2.98 → 0.2.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/package.json +2 -1
- package/src/agents/claude/session.ts +58 -6
- package/src/agents/codex/app-server.ts +2 -1
- package/src/agents/codex/protocol.ts +2 -1
- package/src/agents/codex/session.ts +65 -1
- package/src/agents/health.ts +73 -2
- package/src/agents/workbuddy/account.ts +98 -0
- package/src/agents/workbuddy/driver.ts +157 -0
- package/src/agents/workbuddy/errors.ts +34 -0
- package/src/agents/workbuddy/history.ts +237 -0
- package/src/agents/workbuddy/sdk.ts +156 -0
- package/src/agents/workbuddy/session.ts +484 -0
- package/src/channels/feishu/bot.ts +1 -1
- package/src/channels/feishu/cards.ts +9 -4
- package/src/channels/web/api.ts +40 -0
- package/src/channels/web/experts-api.ts +3 -1
- package/src/channels/weixin/bot.ts +2 -1
- package/src/channels/weixin/format.ts +5 -5
- package/src/core/builtin-agents.ts +48 -7
- package/src/core/command-catalog.ts +4 -2
- package/src/core/commands.ts +13 -1
- package/src/core/config.ts +20 -3
- package/src/core/experts.ts +5 -3
- package/src/core/hub.ts +62 -12
- package/src/core/interactions.ts +1 -1
- package/src/core/memory-curator.ts +2 -2
- package/src/core/memory.ts +2 -2
- package/src/core/permission.ts +20 -2
- package/src/core/store.ts +5 -0
- package/src/core/types.ts +14 -0
- package/src/core/users.ts +1 -1
- package/src/main.ts +6 -2
- package/web/css/composer.css +15 -0
- package/web/lib/dom.js +2 -0
- package/web/lib/permission.js +23 -4
- package/web/settings/agents.js +107 -13
- package/web/settings/commands.js +1 -1
- package/web/settings/experts.js +1 -1
- package/web/settings/memory.js +2 -1
- package/web/state.js +4 -0
- package/web/views/composer.js +5 -4
- package/web/views/conv-actions.js +24 -4
- package/web/views/interaction.js +9 -5
- package/web/views/sidebar.js +2 -1
- package/web/views/tasks.js +2 -2
- package/web/views/topbar.js +16 -11
package/web/css/composer.css
CHANGED
|
@@ -520,6 +520,21 @@ textarea.sending {
|
|
|
520
520
|
min-width: 260px;
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
+
/* 计划模式那一行:开关只显示状态,点的是整行 */
|
|
524
|
+
.perm-pop .perm-plan .switch {
|
|
525
|
+
flex-shrink: 0;
|
|
526
|
+
pointer-events: none;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.perm-plan-tag {
|
|
530
|
+
padding: 0 6px;
|
|
531
|
+
border-radius: 999px;
|
|
532
|
+
font-size: 11px;
|
|
533
|
+
line-height: 18px;
|
|
534
|
+
background: color-mix(in srgb, var(--accent) 12%, transparent);
|
|
535
|
+
color: var(--accent);
|
|
536
|
+
}
|
|
537
|
+
|
|
523
538
|
@media (max-width: 480px) {
|
|
524
539
|
/* 窄屏只留盾牌,把地方让给模型按钮;完全允许仍然保留文字 */
|
|
525
540
|
.perm-pill:not(.danger) .perm-name {
|
package/web/lib/dom.js
CHANGED
|
@@ -87,6 +87,8 @@ export const ICON = {
|
|
|
87
87
|
ICON.claude = '<svg viewBox="0 0 640 640"><path fill="#D97757" fill-rule="evenodd" d="M173 2C168 3 167 4 158 17C146 32 146 32 151 52C155 66 155 66 164 81C188 118 252 233 250 235C248 238 246 237 241 233C238 230 221 218 203 204C185 191 156 169 138 156C94 122 96 123 92 122C90 122 84 121 77 120L66 120 58 129L49 139 51 152C52 159 53 165 53 165C53 168 65 179 74 186C80 190 92 199 101 205C110 211 129 225 144 235C185 262 247 304 252 307C254 310 255 311 254 312C253 315 246 315 212 311C196 309 170 307 153 306C114 304 35 298 24 297L14 296 8 301C2 305 1 305 1 310C0 314 0 314 7 323L14 333 21 334C31 337 103 341 170 342C230 344 251 345 252 347C253 347 253 349 253 351C252 355 251 355 190 390C136 420 124 427 102 442C68 465 69 464 68 477L67 486 74 493C79 498 81 499 83 498C84 498 91 497 98 496L110 495 194 440C240 410 279 386 280 385C281 385 281 386 281 387C281 389 277 394 269 404C262 411 248 429 238 442C227 456 204 486 186 509C143 564 143 563 143 574L142 583 152 588L161 593 167 590C172 588 174 586 196 563C220 536 230 524 295 435C308 416 315 408 316 408C318 408 318 408 316 417C315 421 312 436 310 450C306 475 295 533 284 584L279 608 283 618C287 628 287 628 296 634L304 640 313 636C321 633 323 632 327 628L331 623 340 526C348 445 349 429 351 428C353 427 353 426 369 454C395 498 454 586 459 588C461 588 465 589 469 590C476 591 476 591 484 588C492 586 492 585 494 581L496 576 495 562L493 547 456 492C436 461 419 435 419 434C419 433 420 432 421 432C423 432 460 463 486 486C501 499 553 538 557 539C563 541 564 540 569 534L573 528 571 520C570 514 569 512 566 509C556 500 502 450 478 429C447 401 420 374 420 372C420 370 424 371 443 375C453 378 493 388 533 397L606 414 622 406L638 398 639 392L640 385 634 377C628 369 626 367 617 361L606 354 574 351C553 350 528 349 502 348C464 347 425 344 423 342C422 341 419 342 472 329C496 323 531 316 549 312C568 308 594 302 606 299L629 294 633 283C638 273 638 272 637 267L636 262 625 257L613 251 591 255C548 262 523 267 486 275C439 285 443 284 441 283C440 281 441 278 450 263C463 241 486 209 540 142C547 133 547 132 551 118C553 110 555 103 555 102C555 101 551 94 545 86L536 72 521 72L507 72 499 79C480 94 436 145 396 199C381 219 375 226 371 226C370 226 369 225 369 225C369 223 376 184 386 133C390 114 395 83 398 66L403 35 396 26C390 18 389 17 383 13C379 12 375 10 375 10C374 10 369 13 364 16L354 23 349 35C343 49 344 45 339 105C337 125 335 152 333 167C331 181 329 202 329 212C326 245 326 244 324 244C322 244 321 241 317 229C313 216 311 211 286 162C261 113 248 87 226 35C212 4 212 4 181 1C179 0 175 1 173 2"/></svg>';
|
|
88
88
|
/** OpenAI 的标志,也是内置专家 Codex 的头像。跟着文字颜色(深色模式下是白的) */
|
|
89
89
|
ICON.codex = '<svg viewBox="0 0 640 640"><path fill="currentColor" fill-rule="evenodd" d="M253 1C193 8 141 51 122 109C120 115 118 121 117 123C117 127 117 127 108 130C31 154 -16 240 6 321C12 346 26 370 45 391L53 399 52 407C43 448 51 491 75 527C83 539 104 560 116 569C156 596 205 604 250 591L257 589 264 595C284 613 307 624 335 631C351 635 382 635 399 631C461 618 506 575 523 511C523 508 524 508 534 504C587 485 625 442 637 384C640 369 640 341 637 325C631 293 616 266 594 244L587 236 588 228C606 142 552 60 466 41C442 36 412 37 390 44L384 46 375 38C340 9 297 -4 253 1M259 39C258 39 253 39 249 40C206 46 169 78 156 119C150 137 150 139 150 224L150 302 153 305C156 308 206 338 207 338C208 338 208 296 208 245C208 181 208 150 209 148C211 140 215 138 280 100C314 80 343 64 343 63C345 61 322 48 308 44C293 39 272 37 259 39M405 78C385 82 385 82 309 126C271 148 249 161 248 163C246 166 245 168 245 198C245 220 245 230 246 230C247 230 283 209 326 184C412 134 410 135 416 135C422 135 421 135 489 174C524 195 552 211 553 211C554 209 554 196 553 186C547 133 512 92 462 79C448 76 418 75 405 78M103 173C62 194 36 238 38 284C40 316 53 346 75 368C86 379 88 380 145 413C171 428 199 444 206 448C217 454 221 456 224 456C227 456 281 427 281 425C281 425 245 403 201 378C157 353 120 331 119 329C112 323 113 327 112 244L112 169 103 173M385 194C370 202 358 209 358 209C358 210 394 231 438 256C482 281 519 303 521 305C522 306 525 309 526 311C528 316 528 316 528 390C528 444 528 465 529 465C531 465 547 456 554 451C612 407 618 321 566 267C554 256 553 255 497 222C416 176 420 178 416 178C413 178 406 181 385 194M282 252L246 273 246 317L246 362 282 382C303 394 320 403 320 403C321 403 388 365 393 362L395 361 395 317L394 273 358 252C337 240 320 231 320 231C320 231 303 240 282 252M432 389C432 453 432 484 431 486C429 494 425 497 360 535C325 554 297 571 297 571C295 572 307 580 317 585C336 593 353 597 374 596C432 593 475 558 489 502C491 490 492 336 489 331C488 328 483 325 460 312C445 303 433 296 432 296C432 296 432 338 432 389M376 414C367 419 331 440 297 460C230 498 228 500 222 499C217 498 220 500 150 459C117 440 89 424 88 424C87 424 86 440 87 450C91 492 115 527 153 545C183 561 223 563 254 551C264 547 388 476 391 472L394 469 394 436C394 419 394 404 394 404C394 404 386 408 376 414"/></svg>';
|
|
90
|
+
// WorkBuddy:自己画的简单标记(蓝底白色 W),不是官方 logo
|
|
91
|
+
ICON.workbuddy = '<svg viewBox="0 0 24 24"><rect x="1.5" y="1.5" width="21" height="21" rx="6" fill="#2F6BFF"/><path d="M6 8l2.6 8 3.4-6.2 3.4 6.2L18 8" fill="none" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
90
92
|
|
|
91
93
|
/**
|
|
92
94
|
* 星星加载动画(回复末尾、打开会话时用)。开屏那个带台面的完整 logo 动画直接写在 index.html 里。
|
package/web/lib/permission.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// 权限级别的显示文案和上限换算(级别的含义见服务端 core/permission.ts)
|
|
2
|
-
export const PERMISSION_ORDER = ["ask", "edit", "full"];
|
|
2
|
+
export const PERMISSION_ORDER = ["ask", "edit", "auto", "full"];
|
|
3
3
|
|
|
4
4
|
export const PERMISSIONS = {
|
|
5
5
|
ask: { label: "逐次询问", short: "询问", desc: "改文件、跑命令都先问你" },
|
|
6
6
|
edit: { label: "自动改文件", short: "自动改文件", desc: "工作目录内改文件不再询问,其余照常问" },
|
|
7
|
+
auto: { label: "自动判断", short: "自动判断", desc: "Claude 逐个判断安不安全,安全的直接做,拿不准再问你" },
|
|
7
8
|
full: { label: "完全允许", short: "完全允许", desc: "不再询问,可以跑任意命令、改任意文件" },
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
/** 能设成默认的级别(完全允许只对一次任务说,不能默认) */
|
|
12
|
+
export const DEFAULT_LEVELS = ["ask", "edit", "auto"];
|
|
13
|
+
|
|
14
|
+
export const PLAN_INFO = { label: "计划模式", desc: "先只读、出方案,你批准了再按上面的权限动手" };
|
|
15
|
+
|
|
10
16
|
/** 专家的权限 → 最高能选到哪一级 */
|
|
11
17
|
export function capOfAccess(access) {
|
|
12
18
|
return !access || access === "exec" ? "full" : access === "edit" ? "edit" : "ask";
|
|
@@ -16,9 +22,22 @@ export function minPermission(a, b) {
|
|
|
16
22
|
return PERMISSION_ORDER[Math.min(PERMISSION_ORDER.indexOf(a), PERMISSION_ORDER.indexOf(b))];
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
/**
|
|
20
|
-
export function
|
|
21
|
-
return
|
|
25
|
+
/** 自动判断只有 Claude 有 */
|
|
26
|
+
export function engineSupports(agent, level) {
|
|
27
|
+
return level !== "auto" || agent === "claude";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 不超过 max、这个引擎认的级别。agent 不给就不按引擎筛 */
|
|
31
|
+
export function permissionsUpTo(max, agent) {
|
|
32
|
+
return PERMISSION_ORDER.slice(0, PERMISSION_ORDER.indexOf(max) + 1).filter((l) => !agent || engineSupports(agent, l));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 新对话没选级别时按哪一级:设置里定的默认,封顶后引擎不认就降到自动改文件(和服务端 hub.effectivePermission 一致) */
|
|
36
|
+
export function defaultPermissionFor(agent, max, defaults) {
|
|
37
|
+
const wanted = defaults?.[agent];
|
|
38
|
+
if (!wanted || !PERMISSIONS[wanted]) return null;
|
|
39
|
+
const capped = minPermission(wanted, max);
|
|
40
|
+
return engineSupports(agent, capped) ? capped : "edit";
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
export const FULL_WARNING = {
|
package/web/settings/agents.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { fill, h, icon, toast } from "../lib/dom.js";
|
|
2
2
|
import { api } from "../lib/api.js";
|
|
3
3
|
import { copyText } from "../lib/markdown.js";
|
|
4
|
-
import { desktopQuota, S } from "../state.js";
|
|
5
|
-
import { defaultEntryName, usableAgents } from "../views/topbar.js";
|
|
4
|
+
import { desktopQuota, isAdmin, S } from "../state.js";
|
|
5
|
+
import { defaultEntryName, renderContext, usableAgents } from "../views/topbar.js";
|
|
6
|
+
import { DEFAULT_LEVELS, engineSupports, PERMISSIONS } from "../lib/permission.js";
|
|
6
7
|
import { renderEmpty } from "../views/messages.js";
|
|
7
8
|
import { field, saveButton, saveConfig } from "./common.js";
|
|
8
9
|
import { modelPicker } from "./commands.js";
|
|
9
10
|
|
|
11
|
+
const ENGINE_LABEL = { claude: "Claude Code", codex: "Codex", workbuddy: "WorkBuddy" };
|
|
12
|
+
const ENGINES = Object.keys(ENGINE_LABEL);
|
|
13
|
+
/** 设置里的默认权限「跟随」时实际是什么 */
|
|
14
|
+
const FOLLOW_LABEL = { claude: "跟随 Claude Code(逐次询问)", codex: "跟随沙箱设置", workbuddy: "跟随 WorkBuddy(逐次询问)" };
|
|
15
|
+
const WORKBUDDY_SITES = [
|
|
16
|
+
["workbuddy", "WorkBuddy(www.workbuddy.cn,用本机的 WorkBuddy 桌面版)"],
|
|
17
|
+
["internal", "CodeBuddy 国内版(copilot.tencent.com)"],
|
|
18
|
+
["external", "CodeBuddy 国际版(codebuddy.ai)"],
|
|
19
|
+
["ioa", "腾讯 iOA"],
|
|
20
|
+
];
|
|
21
|
+
|
|
10
22
|
/**
|
|
11
23
|
* 设置 → Agent:勾选哪些模型出现在输入框的模型列表里。
|
|
12
24
|
* 全部勾上存成空数组 = 「全部显示」,以后 agent 新增的模型也会自动出现;
|
|
@@ -114,13 +126,16 @@ function agentHealthSection() {
|
|
|
114
126
|
? h(
|
|
115
127
|
"div",
|
|
116
128
|
{ class: "health-fix" },
|
|
117
|
-
|
|
129
|
+
a.fix.web || !a.fix.commands.length
|
|
130
|
+
? h("div", {}, `${a.fix.title}:`)
|
|
131
|
+
: h("div", {}, `${a.fix.title}:在运行 agent-loft 的机器上打开终端执行${a.fix.commands.length > 1 ? "(任选一条)" : ""}`),
|
|
118
132
|
a.fix.commands.map((cmd) => {
|
|
119
133
|
const copy = h("button", { class: "btn small", onclick: () => copyText(cmd, copy) }, "复制");
|
|
120
134
|
return h("div", { class: "health-cmd" }, h("code", {}, cmd), copy);
|
|
121
135
|
}),
|
|
122
136
|
a.fix.note ? h("small", {}, a.fix.note) : null,
|
|
123
137
|
a.id === "codex" && a.fix.action === "install" ? installCodexButton(() => load(true)) : null,
|
|
138
|
+
a.id === "workbuddy" && a.fix.web ? workbuddyLoginButton(() => load(true)) : null,
|
|
124
139
|
)
|
|
125
140
|
: null,
|
|
126
141
|
);
|
|
@@ -156,6 +171,57 @@ function installCodexButton(after) {
|
|
|
156
171
|
return h("div", {}, btn);
|
|
157
172
|
}
|
|
158
173
|
|
|
174
|
+
/**
|
|
175
|
+
* WorkBuddy 网页登录:服务端拿到登录链接,在新标签页里打开(用的是你自己的浏览器,不是服务器的),
|
|
176
|
+
* 登录完这边轮询到结果就重新检查。弹窗被拦时把链接留在按钮下面,手动点
|
|
177
|
+
*/
|
|
178
|
+
function workbuddyLoginButton(after) {
|
|
179
|
+
const status = h("small", {});
|
|
180
|
+
const btn = h(
|
|
181
|
+
"button",
|
|
182
|
+
{
|
|
183
|
+
class: "btn small primary",
|
|
184
|
+
onclick: async () => {
|
|
185
|
+
// 先开空白页再填地址:等接口回来再 window.open 会被浏览器当成弹窗拦掉
|
|
186
|
+
const tab = window.open("", "_blank");
|
|
187
|
+
btn.disabled = true;
|
|
188
|
+
btn.textContent = "正在获取登录链接…";
|
|
189
|
+
try {
|
|
190
|
+
const { url } = await api("/api/agents/workbuddy/login", { method: "POST" });
|
|
191
|
+
if (tab) tab.location.href = url;
|
|
192
|
+
fill(status, "请在 1 分钟内在打开的页面里登录(超时要重新点),完成后这里会自动刷新。没弹出来的话点这里:", h("a", { href: url, target: "_blank", rel: "noopener" }, "打开登录页"));
|
|
193
|
+
btn.textContent = "等待登录…";
|
|
194
|
+
const started = Date.now();
|
|
195
|
+
const poll = async () => {
|
|
196
|
+
if (!btn.isConnected) return;
|
|
197
|
+
const st = await api("/api/agents/workbuddy/login").catch(() => null);
|
|
198
|
+
if (st?.status === "done") {
|
|
199
|
+
toast(`WorkBuddy 已登录:${st.user}`);
|
|
200
|
+
after();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (st?.status === "failed" || Date.now() - started > 3 * 60_000) {
|
|
204
|
+
fill(status, `登录没有完成:${st?.error ?? "超时"}。点「重新登录」再来一次,拿到链接后尽快登录`);
|
|
205
|
+
btn.disabled = false;
|
|
206
|
+
btn.textContent = "重新登录";
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
setTimeout(poll, 2000);
|
|
210
|
+
};
|
|
211
|
+
setTimeout(poll, 2000);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
tab?.close();
|
|
214
|
+
toast(err.message, 6000);
|
|
215
|
+
btn.disabled = false;
|
|
216
|
+
btn.textContent = "登录 WorkBuddy";
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
"登录 WorkBuddy",
|
|
221
|
+
);
|
|
222
|
+
return h("div", {}, btn, status);
|
|
223
|
+
}
|
|
224
|
+
|
|
159
225
|
/** 个人默认工具单独保存,避免改服务器配置时覆盖尚未保存的个人选择。 */
|
|
160
226
|
function builtinDefaultsSections(targets) {
|
|
161
227
|
const load = async () => {
|
|
@@ -188,21 +254,30 @@ function builtinDefaultsSections(targets) {
|
|
|
188
254
|
if (section.parentElement?.dataset.personal) section.parentElement.hidden = true;
|
|
189
255
|
continue;
|
|
190
256
|
}
|
|
191
|
-
const label = engine
|
|
257
|
+
const label = ENGINE_LABEL[engine] ?? engine;
|
|
192
258
|
const skills = picker(`${label} 技能`, data.skills, prefs.skills, "全部已启用的个人技能(含以后新增)");
|
|
193
259
|
const machine = (data.machineMcp?.[engine] ?? []).map((name) => ({ id: `${data.machinePrefix}${name}`, name: `${name}(本机)` }));
|
|
194
260
|
const mcp = picker(`${label} MCP`, [...data.mcp, ...machine], prefs.mcp, data.machineMcp ? "沿用机器上的 MCP 配置" : null);
|
|
195
261
|
const machineSkills = h("input", { type: "checkbox", checked: prefs.machineSkills });
|
|
196
|
-
|
|
262
|
+
// 成员最高到自动改文件;自动判断只有 Claude 有
|
|
263
|
+
const levels = DEFAULT_LEVELS.filter((l) => engineSupports(engine, l) && (l !== "auto" || isAdmin()));
|
|
264
|
+
const permission = h("select", { "aria-label": `${label} 默认权限` },
|
|
265
|
+
h("option", { value: "", selected: !prefs.permission }, FOLLOW_LABEL[engine] ?? "跟随默认"),
|
|
266
|
+
levels.map((l) => h("option", { value: l, selected: l === prefs.permission }, `${PERMISSIONS[l].label}:${PERMISSIONS[l].desc}`)));
|
|
267
|
+
fill(section, h("h4", {}, "默认权限"),
|
|
268
|
+
field("新对话的权限", permission, "没单独选过权限的对话都按这一级(输入框里的盾牌按钮可以随时改)。自定义专家也按它,但不会超过专家自己的权限;定时任务按任务里选的。「完全允许」不能设成默认。"),
|
|
269
|
+
h("h4", {}, "默认加载"),
|
|
197
270
|
h("p", { class: "skill-note" }, "仅影响你当前账号使用的这个内置 Agent,自定义专家使用各自的配置。保存后,下次发消息生效。"),
|
|
198
271
|
skills.el,
|
|
199
272
|
data.machineMcp ? h("label", { class: "check-item" }, machineSkills, "同时加载机器上的技能") : null,
|
|
200
273
|
mcp.el,
|
|
201
274
|
h("small", {}, "技能和 MCP 可分别全部取消。记忆、定时任务、技能管理等系统工具仍按功能设置提供。"),
|
|
202
275
|
h("div", { class: "row" }, saveButton(async () => {
|
|
203
|
-
await api("/api/agents/defaults", { method: "PUT", body: { agents: { [engine]: { skills: skills.value(), machineSkills: machineSkills.checked, mcp: mcp.value() } } } });
|
|
276
|
+
const res = await api("/api/agents/defaults", { method: "PUT", body: { agents: { [engine]: { permission: permission.value || null, skills: skills.value(), machineSkills: machineSkills.checked, mcp: mcp.value() } } } });
|
|
277
|
+
S.defaultPermission = { ...S.defaultPermission, [engine]: res.agents?.[engine]?.permission ?? null };
|
|
278
|
+
renderContext();
|
|
204
279
|
toast("已保存,下次发消息生效");
|
|
205
|
-
}, `保存 ${label}
|
|
280
|
+
}, `保存 ${label} 默认设置`)));
|
|
206
281
|
}
|
|
207
282
|
if (!Object.keys(data.agents).length) {
|
|
208
283
|
const section = Object.values(targets)[0];
|
|
@@ -217,19 +292,20 @@ function builtinDefaultsSections(targets) {
|
|
|
217
292
|
}
|
|
218
293
|
|
|
219
294
|
export function agentsTab(cfg, page) {
|
|
220
|
-
const targets = Object.fromEntries(
|
|
295
|
+
const targets = Object.fromEntries(ENGINES.map((engine) => [engine, h("div", { class: "builtin-agent-defaults", "data-form": "" }, h("span", { class: "spinner" }))]));
|
|
221
296
|
if (!cfg) {
|
|
222
|
-
for (const [engine, target] of Object.entries(targets)) page.append(h("div", { class: "section", "data-personal": "true", "data-agent": engine }, h("h4", {}, engine
|
|
297
|
+
for (const [engine, target] of Object.entries(targets)) page.append(h("div", { class: "section", "data-personal": "true", "data-agent": engine }, h("h4", {}, ENGINE_LABEL[engine]), target));
|
|
223
298
|
builtinDefaultsSections(targets);
|
|
224
299
|
return;
|
|
225
300
|
}
|
|
226
301
|
page.append(agentHealthSection());
|
|
227
302
|
const a = structuredClone(cfg.agents);
|
|
228
|
-
for (const engine of
|
|
229
|
-
const label = engine
|
|
303
|
+
for (const engine of ENGINES) {
|
|
304
|
+
const label = ENGINE_LABEL[engine];
|
|
230
305
|
const settings = a[engine];
|
|
306
|
+
if (!settings) continue;
|
|
231
307
|
const on = h("input", { type: "checkbox", checked: settings.enabled });
|
|
232
|
-
const pick = modelPicker(engine, settings.defaultModel, settings.defaultEffort, engine === "claude" ? "跟随 Claude Code 默认" : "跟随 config.toml");
|
|
308
|
+
const pick = modelPicker(engine, settings.defaultModel, settings.defaultEffort, engine === "claude" ? "跟随 Claude Code 默认" : engine === "workbuddy" ? "跟随 WorkBuddy 默认" : "跟随 config.toml");
|
|
233
309
|
const models = modelChecklist(engine, settings.models ?? []);
|
|
234
310
|
const config = h("div", { class: "agent-config", "data-form": "" },
|
|
235
311
|
h("h4", {}, label, h("span", { class: "grow" }), h("label", { class: "check" }, on, "启用")));
|
|
@@ -247,7 +323,24 @@ export function agentsTab(cfg, page) {
|
|
|
247
323
|
codex = { path, home, sandbox, titleOn, titlePick, titleModel };
|
|
248
324
|
config.append(field("codex 可执行文件", path, "以系统服务运行时 PATH 很短,建议写绝对路径"), field("CODEX_HOME", home), field("沙箱", sandbox, "workspace-write:目录内可读写,越界才弹授权。danger-full-access 等于关掉沙箱"));
|
|
249
325
|
}
|
|
250
|
-
|
|
326
|
+
let site = null;
|
|
327
|
+
let cliPath = null;
|
|
328
|
+
if (engine === "workbuddy") {
|
|
329
|
+
site = h("select", {}, WORKBUDDY_SITES.map(([value, name]) => h("option", { value, selected: value === (settings.environment || "workbuddy") }, name)));
|
|
330
|
+
cliPath = h("input", { value: settings.cliPath ?? "", placeholder: "留空自动找(如 /opt/WorkBuddy/resources/app.asar.unpacked/cli/bin/codebuddy)" });
|
|
331
|
+
const cliField = field("WorkBuddy CLI 路径", cliPath, "WorkBuddy 桌面版里自带的 CLI,装在常见位置时不用填");
|
|
332
|
+
const syncSite = () => { cliField.hidden = site.value !== "workbuddy"; };
|
|
333
|
+
site.addEventListener("change", syncSite);
|
|
334
|
+
syncSite();
|
|
335
|
+
config.append(
|
|
336
|
+
h("p", { class: "muted" }, "腾讯 WorkBuddy:调用这台服务器上 WorkBuddy 桌面版自带的 CLI;也可以改用 CodeBuddy 的账号(用 agent-loft 自带的 CLI)。启用并保存后,到上面「运行环境」里登录——桌面版里登录过也要在这里再登一次,同一个账号就行。暂不支持自定义专家和分叉。"),
|
|
337
|
+
field("账号站点", site, "登录和对话都走这个站点。换了站点要重新登录"),
|
|
338
|
+
cliField,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
config.append(field("默认模型", pick.modelEl));
|
|
342
|
+
if (engine !== "workbuddy") config.append(field("默认思考程度", pick.effortEl));
|
|
343
|
+
config.append(h("div", { class: "field" }, h("span", {}, "输入框可选模型"), models.el));
|
|
251
344
|
if (codex) config.append(h("div", { class: "row title-row" }, h("label", { class: "check" }, codex.titleOn, "自动生成会话名称"), codex.titleModel));
|
|
252
345
|
config.append(h("div", { class: "row" }, saveButton(() => {
|
|
253
346
|
const selected = models.value();
|
|
@@ -257,6 +350,7 @@ export function agentsTab(cfg, page) {
|
|
|
257
350
|
}
|
|
258
351
|
return saveConfig(cfg, { agents: { [engine]: {
|
|
259
352
|
enabled: on.checked, defaultModel: pick.model(), defaultEffort: pick.effort(), models: selected,
|
|
353
|
+
...(site ? { environment: site.value, cliPath: cliPath.value.trim() } : {}),
|
|
260
354
|
...(codex ? { path: codex.path.value.trim() || "codex", home: codex.home.value.trim(), sandbox: codex.sandbox.value, autoTitle: codex.titleOn.checked, titleModel: codex.titlePick.model() } : {}),
|
|
261
355
|
} } });
|
|
262
356
|
}, `保存 ${label} 设置`)));
|
package/web/settings/commands.js
CHANGED
|
@@ -75,7 +75,7 @@ export function modelPicker(agent, model, effort, defaultLabel) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/** agent-loft 内置命令名(和服务端 BUILTIN_COMMANDS 一致),自定义命令不能用 */
|
|
78
|
-
const BUILTIN_NAMES = ["new", "status", "stop", "model", "effort", "sessions", "resume", "fork", "agent", "claude", "codex", "cd", "pwd", "permission", "autoedit", "web", "detach", "approve", "help"];
|
|
78
|
+
const BUILTIN_NAMES = ["new", "status", "stop", "model", "effort", "sessions", "resume", "fork", "agent", "claude", "codex", "workbuddy", "cd", "pwd", "permission", "planmode", "autoedit", "web", "detach", "approve", "help"];
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* 添加 / 编辑一条自定义命令。onSave 返回 true 才关窗;失败(比如服务端校验没过)留着让用户改。
|
package/web/settings/experts.js
CHANGED
|
@@ -10,7 +10,7 @@ import { changeCwd } from "../views/conv-actions.js";
|
|
|
10
10
|
// 专家 = 一份配置:引擎、提示词、权限、技能、MCP、子智能体。新建对话、定时任务时选,对话中途不能换。
|
|
11
11
|
// 内置的 Claude Code / Codex 不在这里改(就是 agent 原装的样子)。
|
|
12
12
|
|
|
13
|
-
const ENGINE_LABEL = { claude: "Claude", codex: "Codex" };
|
|
13
|
+
const ENGINE_LABEL = { claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy" };
|
|
14
14
|
/** 权限的几项勾选。读文件 → 改文件 → 跑命令一级包含一级(跑命令就等于能改任何文件) */
|
|
15
15
|
const PERMS = [
|
|
16
16
|
{ id: "webSearch", label: "联网搜索", hint: "用搜索引擎查资料" },
|
package/web/settings/memory.js
CHANGED
|
@@ -519,6 +519,7 @@ function curateSection(mem, reload) {
|
|
|
519
519
|
["auto", "自动:有 Claude 就用 Claude,否则 Codex"],
|
|
520
520
|
["claude", "Claude Code"],
|
|
521
521
|
["codex", "Codex"],
|
|
522
|
+
["workbuddy", "WorkBuddy"],
|
|
522
523
|
],
|
|
523
524
|
(v) => save({ agent: v, model: "" }),
|
|
524
525
|
);
|
|
@@ -526,7 +527,7 @@ function curateSection(mem, reload) {
|
|
|
526
527
|
c.agent === "auto"
|
|
527
528
|
? null
|
|
528
529
|
: (() => {
|
|
529
|
-
const sel = h("select", { onchange: (e) => save({ model: e.target.value }) }, h("option", { value: "" }, c.agent === "claude" ? "默认:Haiku(最省)" : "默认模型,思考程度 low(最省)"));
|
|
530
|
+
const sel = h("select", { onchange: (e) => save({ model: e.target.value }) }, h("option", { value: "" }, c.agent === "claude" ? "默认:Haiku(最省)" : c.agent === "workbuddy" ? "默认模型" : "默认模型,思考程度 low(最省)"));
|
|
530
531
|
if (c.model) sel.append(h("option", { value: c.model, selected: true }, c.model));
|
|
531
532
|
agentCatalog(c.agent)
|
|
532
533
|
.then((models) => {
|
package/web/state.js
CHANGED
|
@@ -7,6 +7,10 @@ export const S = {
|
|
|
7
7
|
pending: new Map(),
|
|
8
8
|
/** 侧栏菜单的显示和顺序,随账号保存;null 使用默认配置。 */
|
|
9
9
|
sidebarNav: null,
|
|
10
|
+
/** 设置 → Agent 里定的默认权限,按引擎:{ claude: "edit", codex: null } */
|
|
11
|
+
defaultPermission: null,
|
|
12
|
+
/** 新对话里打开的计划模式(和 draftPermission 一样,建好对话后带过去) */
|
|
13
|
+
draftPlan: false,
|
|
10
14
|
current: null,
|
|
11
15
|
/** 新对话的引擎(claude / codex),跟着选的专家走 */
|
|
12
16
|
draftAgent: localStorage.getItem("aim.agent") || null,
|
package/web/views/composer.js
CHANGED
|
@@ -226,10 +226,11 @@ export async function ensureConversation() {
|
|
|
226
226
|
S.draftCwdPicked = false;
|
|
227
227
|
// 新对话里选过模型 / 思考程度:建好会话后先切过去再发消息
|
|
228
228
|
// 权限只对这一条新对话有效,不留给下一条(不放进按专家记住的 draftPick)
|
|
229
|
-
const pick = { ...draftPick(), permission: S.draftPermission };
|
|
229
|
+
const pick = { ...draftPick(), permission: S.draftPermission, plan: S.draftPlan ? "on" : null };
|
|
230
230
|
S.draftPermission = null;
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
S.draftPlan = false;
|
|
232
|
+
const FAILED = { model: "切换模型", effort: "切换思考程度", permission: "设置权限", plan: "打开计划模式" };
|
|
233
|
+
for (const [action, value] of [["model", pick.model], ["effort", pick.effort], ["permission", pick.permission], ["plan", pick.plan]]) {
|
|
233
234
|
if (!value) continue;
|
|
234
235
|
try {
|
|
235
236
|
const res = await api(`/api/conversations/${encodeURIComponent(info.key)}/action`, { method: "POST", body: { action, value } });
|
|
@@ -358,7 +359,7 @@ export async function sendMessage() {
|
|
|
358
359
|
}
|
|
359
360
|
|
|
360
361
|
/** 会改变当前会话(换会话、换目录、换 agent)的命令,执行完要重拉一遍 */
|
|
361
|
-
const RELOADING_COMMANDS = new Set(["new", "fork", "resume", "agent", "claude", "codex", "cd"]);
|
|
362
|
+
const RELOADING_COMMANDS = new Set(["new", "fork", "resume", "agent", "claude", "codex", "workbuddy", "cd"]);
|
|
362
363
|
|
|
363
364
|
/** agent-loft 命令的结果:只显示给发命令的这个页面,不进会话记录 */
|
|
364
365
|
async function showCommandReply(text, reply, info) {
|
|
@@ -8,7 +8,7 @@ import { closeMenu, confirmDialog, modal, placePopover, showPopover } from "../l
|
|
|
8
8
|
import { newDraft, openConversation, renderEmpty } from "./messages.js";
|
|
9
9
|
import { setDraftExpert } from "./experts.js";
|
|
10
10
|
import { preloadCommands } from "./slash.js";
|
|
11
|
-
import { FULL_WARNING, PERMISSIONS, permissionsUpTo } from "../lib/permission.js";
|
|
11
|
+
import { FULL_WARNING, PERMISSIONS, permissionsUpTo, PLAN_INFO } from "../lib/permission.js";
|
|
12
12
|
|
|
13
13
|
// ---------- 会话操作 ----------
|
|
14
14
|
|
|
@@ -169,8 +169,11 @@ export async function openModelPicker(anchor = ui.modelSlot) {
|
|
|
169
169
|
render();
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
/**
|
|
173
|
-
|
|
172
|
+
/**
|
|
173
|
+
* 权限级别 + 计划模式开关:已有对话直接切,新对话先记下,建好对话后带过去。
|
|
174
|
+
* max、current、agent、plan 由输入框上的按钮算好传进来(自动判断只有 Claude 有)
|
|
175
|
+
*/
|
|
176
|
+
export function openPermissionPicker(anchor, { current, max, agent, plan }) {
|
|
174
177
|
if (ui.menu?.dataset.for === "permission") return closeMenu();
|
|
175
178
|
const pop = showPopover(anchor, { align: "left" });
|
|
176
179
|
pop.dataset.for = "permission";
|
|
@@ -186,10 +189,19 @@ export function openPermissionPicker(anchor, { current, max }) {
|
|
|
186
189
|
renderContext();
|
|
187
190
|
}
|
|
188
191
|
};
|
|
192
|
+
const togglePlan = async (on) => {
|
|
193
|
+
closeMenu();
|
|
194
|
+
if (S.current) {
|
|
195
|
+
await doAction("plan", on ? "on" : "off");
|
|
196
|
+
} else {
|
|
197
|
+
S.draftPlan = on;
|
|
198
|
+
renderContext();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
189
201
|
fill(
|
|
190
202
|
pop,
|
|
191
203
|
h("div", { class: "pop-head" }, "权限"),
|
|
192
|
-
permissionsUpTo(max).map((level) =>
|
|
204
|
+
permissionsUpTo(max, agent).map((level) =>
|
|
193
205
|
h(
|
|
194
206
|
"button",
|
|
195
207
|
{ class: `pop-item${level === current ? " on" : ""}`, onclick: () => void choose(level) },
|
|
@@ -197,6 +209,14 @@ export function openPermissionPicker(anchor, { current, max }) {
|
|
|
197
209
|
level === current ? h("span", { class: "check" }, "✓") : null,
|
|
198
210
|
),
|
|
199
211
|
),
|
|
212
|
+
h("div", { class: "sep" }),
|
|
213
|
+
// 整行是一个按钮,开关只是显示状态
|
|
214
|
+
h(
|
|
215
|
+
"button",
|
|
216
|
+
{ class: "pop-item perm-plan", role: "switch", "aria-checked": String(!!plan), onclick: () => void togglePlan(!plan) },
|
|
217
|
+
h("span", { class: "grow" }, h("span", { class: "t" }, PLAN_INFO.label), h("span", { class: "s" }, PLAN_INFO.desc)),
|
|
218
|
+
h("span", { class: "switch", "aria-hidden": "true" }, h("input", { type: "checkbox", checked: !!plan, tabindex: -1 }), h("span", { class: "slider" })),
|
|
219
|
+
),
|
|
200
220
|
);
|
|
201
221
|
placePopover(pop, anchor);
|
|
202
222
|
}
|
package/web/views/interaction.js
CHANGED
|
@@ -45,7 +45,11 @@ export function insertCard(ix) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** 已处理:「已回答 · 已在 Web 处理」。从会话记录里还原的不知道是谁处理的,只写结果 */
|
|
48
|
-
const settledText = (s
|
|
48
|
+
const settledText = (s, spec) => {
|
|
49
|
+
// 换过按钮文字的卡(批准方案)按按钮上的说法回显
|
|
50
|
+
const custom = s.settlement === "allow-once" ? spec?.allowLabel : s.settlement === "deny" ? spec?.denyLabel : undefined;
|
|
51
|
+
return [custom ? `已选「${custom}」` : (SETTLE_LABEL[s.settlement] ?? s.settlement), s.by].filter(Boolean).join(" · ");
|
|
52
|
+
};
|
|
49
53
|
|
|
50
54
|
function notifyIfHidden(ix) {
|
|
51
55
|
// 桌面端由服务端的 notice 统一弹,这里再弹就重复了
|
|
@@ -87,22 +91,22 @@ export function renderInteraction(item) {
|
|
|
87
91
|
return h(
|
|
88
92
|
"div",
|
|
89
93
|
{ class: `ix-card${settled ? " settled" : ""}` },
|
|
90
|
-
h("div", { class: "ix-title" }, settled ? "" : "⚠️", spec.title),
|
|
94
|
+
h("div", { class: "ix-title" }, settled ? "" : spec.allowLabel ? "📋" : "⚠️", spec.title),
|
|
91
95
|
h("div", { class: "ix-detail" }, renderMarkdown(spec.detail)),
|
|
92
96
|
settled
|
|
93
|
-
? h("div", { class: "ix-meta" }, settledText(settled))
|
|
97
|
+
? h("div", { class: "ix-meta" }, settledText(settled, spec))
|
|
94
98
|
: h(
|
|
95
99
|
"div",
|
|
96
100
|
{ class: "ix-buttons" },
|
|
97
101
|
spec.allowSession
|
|
98
102
|
? h("button", { class: "btn primary", onclick: () => ixOp(ix.id, "decide", { decision: "allow-session" }) }, "本会话全部允许")
|
|
99
103
|
: null,
|
|
100
|
-
h("button", { class: `btn${spec.allowSession ? "" : "
|
|
104
|
+
h("button", { class: `btn${spec.allowSession ? "" : " primary"}`, onclick: () => ixOp(ix.id, "decide", { decision: "allow-once" }) }, spec.allowLabel ?? "允许一次"),
|
|
101
105
|
// 会落盘、对所有人生效的「总是允许」只给管理员
|
|
102
106
|
spec.alwaysLabel && (!spec.alwaysGlobal || isAdmin())
|
|
103
107
|
? h("button", { class: "btn", onclick: () => ixOp(ix.id, "decide", { decision: "allow-always" }) }, spec.alwaysLabel)
|
|
104
108
|
: null,
|
|
105
|
-
h("button", { class:
|
|
109
|
+
h("button", { class: `btn${spec.denyLabel ? "" : " danger"}`, onclick: () => ixOp(ix.id, "decide", { decision: "deny" }) }, spec.denyLabel ?? "拒绝"),
|
|
106
110
|
),
|
|
107
111
|
);
|
|
108
112
|
}
|
package/web/views/sidebar.js
CHANGED
|
@@ -238,7 +238,7 @@ function convExpertMark(c) {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
function agentShort(id) {
|
|
241
|
-
return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id;
|
|
241
|
+
return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id === "workbuddy" ? "WorkBuddy" : id;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/** 侧栏状态:order 混排目录路径和渠道分组,兼容原有的顺序。 */
|
|
@@ -446,6 +446,7 @@ export function bootstrapQuery() {
|
|
|
446
446
|
|
|
447
447
|
export function applyBootstrap(data) {
|
|
448
448
|
S.sidebarNav = data.sidebarNav ?? null;
|
|
449
|
+
S.defaultPermission = data.defaultPermission ?? null;
|
|
449
450
|
S.convs = new Map(data.conversations.map((c) => [c.key, c]));
|
|
450
451
|
pages.full = !data.sidebar;
|
|
451
452
|
// bootstrap 只带 IM 分组最近/当前的一条;展开的列表需要重新补齐。
|
package/web/views/tasks.js
CHANGED
|
@@ -456,7 +456,7 @@ export function openTaskForm(task, preset) {
|
|
|
456
456
|
let permissionValue = src.permission ?? "";
|
|
457
457
|
const syncPermission = () => {
|
|
458
458
|
const max = minPermission(isAdmin() ? "full" : "edit", capOfAccess(findExpert(expert.value)?.access));
|
|
459
|
-
const levels = permissionsUpTo(max);
|
|
459
|
+
const levels = permissionsUpTo(max, findExpert(expert.value)?.engine);
|
|
460
460
|
// 已经存着的级别高过现在的上限(被降级了、换了专家):不留着,免得显示的和实际跑的不一样
|
|
461
461
|
if (permissionValue && !levels.includes(permissionValue)) permissionValue = "";
|
|
462
462
|
fill(
|
|
@@ -486,7 +486,7 @@ export function openTaskForm(task, preset) {
|
|
|
486
486
|
const info = target.value === "dedicated" ? null : convTargetInfo(target.value, task);
|
|
487
487
|
if (!info) return fill(convBox);
|
|
488
488
|
const label = PERMISSIONS[info.permission]?.label ?? "默认";
|
|
489
|
-
const levels = info.max ? permissionsUpTo(info.max) : [];
|
|
489
|
+
const levels = info.max ? permissionsUpTo(info.max, info.expert?.engine) : [];
|
|
490
490
|
if (!info.locked && levels.length > 1) {
|
|
491
491
|
convPermission = h("select", { class: "task-conv-permission" }, levels.map((l) => h("option", { value: l, selected: l === info.permission }, `${PERMISSIONS[l].label}:${PERMISSIONS[l].desc}`)));
|
|
492
492
|
}
|
package/web/views/topbar.js
CHANGED
|
@@ -8,7 +8,7 @@ import { closeMenu, modal, placePopover, showMenu, showPopover, submenuButton }
|
|
|
8
8
|
import { openConversation } from "./messages.js";
|
|
9
9
|
import { openSchedule } from "./schedule.js";
|
|
10
10
|
import { changeCwd, deleteConv, doAction, forkConversation, handoffConversation, openModelPicker, openPermissionPicker, renameConv, switchAgent } from "./conv-actions.js";
|
|
11
|
-
import { capOfAccess, minPermission,
|
|
11
|
+
import { capOfAccess, defaultPermissionFor, minPermission, permissionsUpTo, PERMISSIONS } from "../lib/permission.js";
|
|
12
12
|
import { canSeeChanges, syncWorkspace, toggleWorkspace, workspaceButtons, workspaceStats } from "./workspace-entry.js";
|
|
13
13
|
|
|
14
14
|
// ---------- 顶栏 ----------
|
|
@@ -48,7 +48,7 @@ export function renderTopbar() {
|
|
|
48
48
|
// ---------- 顶栏的专家头像和信息卡 ----------
|
|
49
49
|
|
|
50
50
|
const ACCESS_LABEL = { web: "只能联网", read: "能读文件", edit: "能改文件", exec: "能跑命令" };
|
|
51
|
-
const ENGINE_LABEL = { claude: "Claude", codex: "Codex" };
|
|
51
|
+
const ENGINE_LABEL = { claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy" };
|
|
52
52
|
/** 鼠标停多久才弹、离开多久才收(从头像挪到卡片上的那一下不能收) */
|
|
53
53
|
const HOVER_OPEN_MS = 250;
|
|
54
54
|
const HOVER_CLOSE_MS = 200;
|
|
@@ -429,26 +429,31 @@ export function renderContext() {
|
|
|
429
429
|
);
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
/**
|
|
432
|
+
/** 输入框里的权限按钮(级别 + 计划模式)。只有一级可选(只能联网、只能读文件的专家)时不显示 */
|
|
433
433
|
function renderPermission(c, expert) {
|
|
434
434
|
if (!ui.permSlot) return;
|
|
435
|
+
const agent = c ? c.agent : S.draftAgent;
|
|
435
436
|
const max = c ? c.permissionMax : minPermission(isAdmin() ? "full" : "edit", capOfAccess(expert?.access));
|
|
436
|
-
//
|
|
437
|
-
if (!c && S.draftPermission &&
|
|
438
|
-
|
|
439
|
-
|
|
437
|
+
// 新对话选好后换了个权限低的专家、或换到了没有这一级的引擎:选的不再算数
|
|
438
|
+
if (!c && S.draftPermission && !permissionsUpTo(max, agent).includes(S.draftPermission)) S.draftPermission = null;
|
|
439
|
+
// 没选过就按设置里的默认权限(已有对话由服务端算好)
|
|
440
|
+
const current = c ? c.permission : (S.draftPermission ?? defaultPermissionFor(agent, max, S.defaultPermission));
|
|
441
|
+
const plan = c ? !!c.plan : !!S.draftPlan;
|
|
442
|
+
if (max === "ask" && (!current || current === "ask") && !plan) return fill(ui.permSlot);
|
|
440
443
|
const locked = !!c?.taskId;
|
|
444
|
+
const name = current ? PERMISSIONS[current].short : "默认权限";
|
|
441
445
|
fill(
|
|
442
446
|
ui.permSlot,
|
|
443
447
|
h(
|
|
444
448
|
"button",
|
|
445
449
|
{
|
|
446
|
-
class: `perm-pill${current === "full" ? " danger" : ""}`,
|
|
447
|
-
title: locked ? "定时任务的专用对话:权限在任务设置里改" : `权限:${current ? PERMISSIONS[current].label : "默认"},点击切换`,
|
|
448
|
-
onclick: (e) => (locked ? toast("这是定时任务的专用对话,权限在任务设置里改") : openPermissionPicker(e.currentTarget, { current, max })),
|
|
450
|
+
class: `perm-pill${current === "full" ? " danger" : ""}${plan ? " plan" : ""}`,
|
|
451
|
+
title: locked ? "定时任务的专用对话:权限在任务设置里改" : `权限:${current ? PERMISSIONS[current].label : "默认"}${plan ? ",计划模式开着" : ""},点击切换`,
|
|
452
|
+
onclick: (e) => (locked ? toast("这是定时任务的专用对话,权限在任务设置里改") : openPermissionPicker(e.currentTarget, { current, max, agent, plan })),
|
|
449
453
|
},
|
|
450
454
|
icon("shield"),
|
|
451
|
-
h("span", { class: "perm-name" },
|
|
455
|
+
h("span", { class: "perm-name" }, name),
|
|
456
|
+
plan ? h("span", { class: "perm-plan-tag" }, "计划") : null,
|
|
452
457
|
locked ? null : icon("down"),
|
|
453
458
|
),
|
|
454
459
|
);
|