agent-loft 0.2.104 → 0.2.106
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 +3 -1
- package/src/agents/health.ts +60 -3
- package/src/agents/pi/constants.ts +2 -0
- package/src/agents/pi/custom.ts +146 -0
- package/src/agents/pi/driver.ts +150 -0
- package/src/agents/pi/errors.ts +37 -0
- package/src/agents/pi/history.ts +217 -0
- package/src/agents/pi/oauth.ts +190 -0
- package/src/agents/pi/sdk.ts +201 -0
- package/src/agents/pi/session.ts +681 -0
- package/src/agents/pi/steps.ts +21 -0
- package/src/channels/feishu/bot.ts +1 -1
- package/src/channels/web/api.ts +109 -0
- package/src/channels/web/experts-api.ts +1 -1
- package/src/core/builtin-agents.ts +1 -1
- package/src/core/command-catalog.ts +2 -1
- package/src/core/commands.ts +2 -1
- package/src/core/config.ts +17 -3
- package/src/core/experts.ts +11 -9
- package/src/core/hub.ts +1 -1
- package/src/core/memory-curator.ts +2 -2
- package/src/core/memory.ts +2 -2
- package/src/core/permission.ts +1 -1
- package/src/core/users.ts +1 -1
- package/src/main.ts +6 -2
- package/web/lib/dom.js +2 -0
- package/web/settings/agents.js +279 -3
- package/web/settings/commands.js +1 -1
- package/web/settings/experts.js +11 -4
- package/web/settings/memory.js +2 -1
- package/web/views/composer.js +1 -1
- package/web/views/sidebar.js +1 -1
- package/web/views/topbar.js +1 -1
package/web/settings/agents.js
CHANGED
|
@@ -8,10 +8,10 @@ import { renderEmpty } from "../views/messages.js";
|
|
|
8
8
|
import { field, saveButton, saveConfig } from "./common.js";
|
|
9
9
|
import { modelPicker } from "./commands.js";
|
|
10
10
|
|
|
11
|
-
const ENGINE_LABEL = { claude: "Claude Code", codex: "Codex", workbuddy: "WorkBuddy" };
|
|
11
|
+
const ENGINE_LABEL = { claude: "Claude Code", codex: "Codex", workbuddy: "WorkBuddy", pi: "pi" };
|
|
12
12
|
const ENGINES = Object.keys(ENGINE_LABEL);
|
|
13
13
|
/** 设置里的默认权限「跟随」时实际是什么 */
|
|
14
|
-
const FOLLOW_LABEL = { claude: "跟随 Claude Code(逐次询问)", codex: "跟随沙箱设置", workbuddy: "跟随 WorkBuddy(逐次询问)" };
|
|
14
|
+
const FOLLOW_LABEL = { claude: "跟随 Claude Code(逐次询问)", codex: "跟随沙箱设置", workbuddy: "跟随 WorkBuddy(逐次询问)", pi: "跟随 pi(逐次询问)" };
|
|
15
15
|
const WORKBUDDY_SITES = [
|
|
16
16
|
["workbuddy", "WorkBuddy(www.workbuddy.cn,用本机的 WorkBuddy 桌面版)"],
|
|
17
17
|
["internal", "CodeBuddy 国内版(copilot.tencent.com)"],
|
|
@@ -305,7 +305,7 @@ export function agentsTab(cfg, page) {
|
|
|
305
305
|
const settings = a[engine];
|
|
306
306
|
if (!settings) continue;
|
|
307
307
|
const on = h("input", { type: "checkbox", checked: settings.enabled });
|
|
308
|
-
const pick = modelPicker(engine, settings.defaultModel, settings.defaultEffort, engine === "claude" ? "跟随 Claude Code 默认" : engine === "workbuddy" ? "跟随 WorkBuddy 默认" : "跟随 config.toml");
|
|
308
|
+
const pick = modelPicker(engine, settings.defaultModel, settings.defaultEffort, engine === "claude" ? "跟随 Claude Code 默认" : engine === "workbuddy" ? "跟随 WorkBuddy 默认" : engine === "pi" ? "pi 自动挑一个能用的" : "跟随 config.toml");
|
|
309
309
|
const models = modelChecklist(engine, settings.models ?? []);
|
|
310
310
|
const config = h("div", { class: "agent-config", "data-form": "" },
|
|
311
311
|
h("h4", {}, label, h("span", { class: "grow" }), h("label", { class: "check" }, on, "启用")));
|
|
@@ -338,6 +338,13 @@ export function agentsTab(cfg, page) {
|
|
|
338
338
|
cliField,
|
|
339
339
|
);
|
|
340
340
|
}
|
|
341
|
+
if (engine === "pi") {
|
|
342
|
+
config.append(
|
|
343
|
+
h("p", { class: "muted" }, "pi(pi.dev):开源的编程 agent,用官方 SDK 在 agent-loft 进程里运行。不用登录账号,按模型服务商填 API Key(DeepSeek、智谱、Kimi、通义、MiniMax、OpenRouter……),整台服务器共用。凭据和会话记录都存在 agent-loft 的 data/pi/ 下,不读机器上的 ~/.pi。pi 本身没有权限系统,授权卡、计划模式、提问卡是 agent-loft 补上的;跑命令(bash)没有沙箱。暂不支持自定义专家。"),
|
|
344
|
+
piProvidersSection(),
|
|
345
|
+
piCustomSection(),
|
|
346
|
+
);
|
|
347
|
+
}
|
|
341
348
|
config.append(field("默认模型", pick.modelEl));
|
|
342
349
|
if (engine !== "workbuddy") config.append(field("默认思考程度", pick.effortEl));
|
|
343
350
|
config.append(h("div", { class: "field" }, h("span", {}, "输入框可选模型"), models.el));
|
|
@@ -360,6 +367,275 @@ export function agentsTab(cfg, page) {
|
|
|
360
367
|
builtinDefaultsSections(targets);
|
|
361
368
|
}
|
|
362
369
|
|
|
370
|
+
/** 常用的排前面:国内能直接用的几家、再是 OpenRouter 和海外几家 */
|
|
371
|
+
const PI_PROVIDER_ORDER = ["deepseek", "zai-coding-cn", "kimi-coding", "moonshotai-cn", "qwen-token-plan-cn", "minimax-cn", "xiaomi-token-plan-cn", "openrouter", "anthropic", "openai", "google"];
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* pi 的模型服务商:哪些能用了(存了 Key,或服务进程有环境变量),填 / 换 / 删 API Key。
|
|
375
|
+
* Key 只往服务端写,不回显;存在 data/pi/auth.json(0600)
|
|
376
|
+
*/
|
|
377
|
+
function piProvidersSection() {
|
|
378
|
+
const box = h("div", { class: "field pi-providers", "data-nodirty": "" }, h("span", {}, "模型服务商"), h("small", {}, "正在读取…"));
|
|
379
|
+
const load = async () => {
|
|
380
|
+
let data;
|
|
381
|
+
try {
|
|
382
|
+
data = await api("/api/agents/pi/providers");
|
|
383
|
+
} catch (err) {
|
|
384
|
+
fill(box, h("span", {}, "模型服务商"), h("div", { class: "error-text" }, err.message), h("button", { class: "btn small", onclick: load }, "重试"));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const rank = (p) => {
|
|
388
|
+
const i = PI_PROVIDER_ORDER.indexOf(p.id);
|
|
389
|
+
return i < 0 ? PI_PROVIDER_ORDER.length : i;
|
|
390
|
+
};
|
|
391
|
+
const providers = [...data.providers].sort((a, b) => rank(a) - rank(b) || a.name.localeCompare(b.name));
|
|
392
|
+
const ready = providers.filter((p) => p.configured && !p.custom);
|
|
393
|
+
const rows = ready.map((p) => {
|
|
394
|
+
const remove = p.stored
|
|
395
|
+
? h("button", {
|
|
396
|
+
class: "btn small",
|
|
397
|
+
onclick: async () => {
|
|
398
|
+
if (!confirm(`删除 ${p.name} 的凭据?用它的模型的对话会用不了。`)) return;
|
|
399
|
+
remove.disabled = true;
|
|
400
|
+
try {
|
|
401
|
+
await api(`/api/agents/pi/providers/${encodeURIComponent(p.id)}`, { method: "DELETE" });
|
|
402
|
+
toast(`已删除 ${p.name} 的凭据`);
|
|
403
|
+
} catch (err) {
|
|
404
|
+
toast(`删除失败:${err.message}`, 5000);
|
|
405
|
+
}
|
|
406
|
+
void load();
|
|
407
|
+
},
|
|
408
|
+
}, "删除")
|
|
409
|
+
: null;
|
|
410
|
+
const where = p.stored === "oauth" ? "已登录(OAuth)" : p.stored ? "API Key 已保存" : "来自服务的环境变量 / 云凭据";
|
|
411
|
+
return h("div", { class: "health-row" }, h("div", { class: "health-head" }, h("span", { class: "health-dot ok" }), h("b", {}, p.name), h("span", { class: "health-state" }, `${where} · ${p.models} 个模型`), h("span", { class: "grow" }), remove));
|
|
412
|
+
});
|
|
413
|
+
const keyable = providers.filter((p) => p.apiKey && !p.custom);
|
|
414
|
+
const sel = h("select", { "aria-label": "服务商" }, keyable.map((p) => h("option", { value: p.id }, `${p.name}${p.configured ? "(已配置,填了就替换)" : ""}`)));
|
|
415
|
+
const key = h("input", { type: "password", autocomplete: "off", placeholder: "粘贴 API Key", "aria-label": "API Key" });
|
|
416
|
+
const save = h("button", {
|
|
417
|
+
class: "btn small primary",
|
|
418
|
+
onclick: async () => {
|
|
419
|
+
const value = key.value.trim();
|
|
420
|
+
if (!value) {
|
|
421
|
+
toast("先粘贴 API Key");
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
save.disabled = true;
|
|
425
|
+
try {
|
|
426
|
+
await api(`/api/agents/pi/providers/${encodeURIComponent(sel.value)}`, { method: "PUT", body: { key: value } });
|
|
427
|
+
key.value = "";
|
|
428
|
+
toast("已保存。模型列表一分钟内刷新,刷新设置页就能在下拉框里选", 5000);
|
|
429
|
+
} catch (err) {
|
|
430
|
+
toast(`保存失败:${err.message}`, 6000);
|
|
431
|
+
}
|
|
432
|
+
save.disabled = false;
|
|
433
|
+
void load();
|
|
434
|
+
},
|
|
435
|
+
}, "保存 Key");
|
|
436
|
+
const oauthable = providers.filter((p) => p.oauth);
|
|
437
|
+
const oauthSel = h("select", { "aria-label": "订阅账号" }, oauthable.map((p) => h("option", { value: p.id }, `${p.oauth}${p.stored === "oauth" ? "(已登录,重新登录)" : ""}`)));
|
|
438
|
+
const panel = h("div", { class: "pi-oauth" });
|
|
439
|
+
const loginBtn = h("button", { class: "btn small", onclick: () => piOAuthFlow(panel, oauthSel.value, load) }, "登录");
|
|
440
|
+
fill(
|
|
441
|
+
box,
|
|
442
|
+
h("span", {}, "模型服务商"),
|
|
443
|
+
rows.length ? rows : h("small", {}, "还没有能用的服务商:在下面选一家、填上 API Key,或者登录订阅账号。"),
|
|
444
|
+
h("div", { class: "row" }, sel, key, save),
|
|
445
|
+
oauthable.length ? h("div", { class: "row" }, oauthSel, loginBtn) : null,
|
|
446
|
+
oauthable.length ? h("small", {}, "订阅账号(Claude Pro/Max、ChatGPT Plus/Pro、GitHub Copilot、Kimi Code……)在你自己的浏览器里登录,整台服务器共用。订阅能不能用在第三方工具里,以各家的条款为准。") : null,
|
|
447
|
+
panel,
|
|
448
|
+
h("small", {}, "Key 只存在这台服务器上(data/pi/auth.json),网页上不会再显示。也可以给 agent-loft 服务设环境变量(如 DEEPSEEK_API_KEY),重启后自动识别。"),
|
|
449
|
+
);
|
|
450
|
+
};
|
|
451
|
+
void load();
|
|
452
|
+
return box;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const PI_API_LABEL = {
|
|
456
|
+
"openai-completions": "OpenAI 兼容(/chat/completions,Ollama、LM Studio、vLLM、one-api 等)",
|
|
457
|
+
"openai-responses": "OpenAI Responses(/responses)",
|
|
458
|
+
"anthropic-messages": "Anthropic 兼容(/messages)",
|
|
459
|
+
"google-generative-ai": "Google Gemini 兼容",
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 自定义服务商:写 data/pi/models.json。本地模型、OpenAI 兼容网关都在这里加。
|
|
464
|
+
* 模型的能力(思考、图片、上下文)按整个服务商统一设,够用;要细调可以直接改文件。
|
|
465
|
+
*/
|
|
466
|
+
function piCustomSection() {
|
|
467
|
+
const box = h("div", { class: "field pi-custom", "data-nodirty": "" }, h("span", {}, "自定义服务商"), h("small", {}, "正在读取…"));
|
|
468
|
+
const load = async () => {
|
|
469
|
+
let data;
|
|
470
|
+
try {
|
|
471
|
+
data = await api("/api/agents/pi/custom");
|
|
472
|
+
} catch (err) {
|
|
473
|
+
fill(box, h("span", {}, "自定义服务商"), h("div", { class: "error-text" }, err.message), h("button", { class: "btn small", onclick: load }, "重试"));
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const formSlot = h("div");
|
|
477
|
+
const rows = data.providers.map((p) => {
|
|
478
|
+
const del = h("button", { class: "btn small", onclick: async () => {
|
|
479
|
+
if (!confirm(`删除自定义服务商 ${p.name}?用它的模型的对话会用不了。`)) return;
|
|
480
|
+
try {
|
|
481
|
+
await api(`/api/agents/pi/custom/${encodeURIComponent(p.id)}`, { method: "DELETE" });
|
|
482
|
+
toast(`已删除 ${p.name}`);
|
|
483
|
+
} catch (err) {
|
|
484
|
+
toast(`删除失败:${err.message}`, 5000);
|
|
485
|
+
}
|
|
486
|
+
void load();
|
|
487
|
+
} }, "删除");
|
|
488
|
+
const edit = h("button", { class: "btn small", onclick: () => fill(formSlot, customForm(data.apis, p, () => { formSlot.replaceChildren(); void load(); })) }, "编辑");
|
|
489
|
+
return h("div", { class: "health-row" },
|
|
490
|
+
h("div", { class: "health-head" }, h("b", {}, p.name), h("span", { class: "health-state" }, `${p.models.length} 个模型${p.hasKey ? " · 有 Key" : ""}`), h("span", { class: "grow" }), edit, del),
|
|
491
|
+
h("div", { class: "health-meta" }, `${p.id} · ${p.baseUrl}`));
|
|
492
|
+
});
|
|
493
|
+
const add = h("button", { class: "btn small", onclick: () => fill(formSlot, customForm(data.apis, null, () => { formSlot.replaceChildren(); void load(); })) }, "添加自定义服务商");
|
|
494
|
+
fill(box, h("span", {}, "自定义服务商"), rows, h("div", { class: "row" }, add), formSlot,
|
|
495
|
+
h("small", {}, "本地的 Ollama(http://localhost:11434/v1)、LM Studio、vLLM、llama.cpp,或 one-api 之类的 OpenAI 兼容网关。存在 data/pi/models.json。"));
|
|
496
|
+
};
|
|
497
|
+
void load();
|
|
498
|
+
return box;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function customForm(apis, src, done) {
|
|
502
|
+
const first = src?.models?.[0] ?? {};
|
|
503
|
+
const id = h("input", { value: src?.id ?? "", placeholder: "如 ollama、my-gateway", disabled: !!src });
|
|
504
|
+
const name = h("input", { value: src?.name ?? "", placeholder: "显示名称,留空用 id" });
|
|
505
|
+
const baseUrl = h("input", { value: src?.baseUrl ?? "", placeholder: "如 http://localhost:11434/v1" });
|
|
506
|
+
const apiSel = h("select", {}, apis.map((a) => h("option", { value: a, selected: a === (src?.api || "openai-completions") }, PI_API_LABEL[a] ?? a)));
|
|
507
|
+
const key = h("input", { type: "password", autocomplete: "off", placeholder: src?.hasKey ? "留空沿用已保存的" : "本地服务不用填" });
|
|
508
|
+
const clearKey = h("input", { type: "checkbox" });
|
|
509
|
+
const models = h("textarea", { rows: 4, placeholder: "一行一个模型 id,如 qwen2.5-coder:7b" }, (src?.models ?? []).map((m) => m.id).join("\n"));
|
|
510
|
+
const reasoning = h("input", { type: "checkbox", checked: !!first.reasoning });
|
|
511
|
+
const image = h("input", { type: "checkbox", checked: (first.input ?? []).includes("image") });
|
|
512
|
+
const ctx = h("input", { type: "number", min: 1024, step: 1024, value: first.contextWindow ?? "", placeholder: "128000" });
|
|
513
|
+
const discover = h("button", { class: "btn small", onclick: async () => {
|
|
514
|
+
discover.disabled = true;
|
|
515
|
+
try {
|
|
516
|
+
const r = await api("/api/agents/pi/custom-discover", { method: "POST", body: { baseUrl: baseUrl.value, api: apiSel.value, apiKey: key.value, ...(src ? { id: src.id } : {}) } });
|
|
517
|
+
if (!r.models.length) toast("服务没有返回模型");
|
|
518
|
+
else {
|
|
519
|
+
models.value = r.models.join("\n");
|
|
520
|
+
toast(`读到 ${r.models.length} 个模型,删掉不要的再保存`);
|
|
521
|
+
}
|
|
522
|
+
} catch (err) {
|
|
523
|
+
toast(err.message, 6000);
|
|
524
|
+
}
|
|
525
|
+
discover.disabled = false;
|
|
526
|
+
} }, "从服务读取模型列表");
|
|
527
|
+
const save = h("button", { class: "btn small primary", onclick: async () => {
|
|
528
|
+
const ids = models.value.split(/\n+/).map((x) => x.trim()).filter(Boolean);
|
|
529
|
+
const contextWindow = Number(ctx.value) || undefined;
|
|
530
|
+
const body = {
|
|
531
|
+
name: name.value.trim(),
|
|
532
|
+
baseUrl: baseUrl.value.trim(),
|
|
533
|
+
api: apiSel.value,
|
|
534
|
+
models: ids.map((m) => ({ id: m, reasoning: reasoning.checked, image: image.checked, ...(contextWindow ? { contextWindow } : {}) })),
|
|
535
|
+
...(key.value.trim() ? { apiKey: key.value.trim() } : clearKey.checked || !src ? { apiKey: "" } : {}),
|
|
536
|
+
};
|
|
537
|
+
save.disabled = true;
|
|
538
|
+
try {
|
|
539
|
+
await api(`/api/agents/pi/custom/${encodeURIComponent(src?.id ?? id.value.trim())}`, { method: "PUT", body });
|
|
540
|
+
toast("已保存。刷新设置页后可以在默认模型里选");
|
|
541
|
+
done();
|
|
542
|
+
} catch (err) {
|
|
543
|
+
toast(`保存失败:${err.message}`, 6000);
|
|
544
|
+
save.disabled = false;
|
|
545
|
+
}
|
|
546
|
+
} }, "保存");
|
|
547
|
+
return h("div", { class: "health-fix" },
|
|
548
|
+
h("div", { class: "row-fields" }, field("id", id, src ? "建好后不能改" : "小写字母、数字和 -"), field("名称", name)),
|
|
549
|
+
field("地址(baseUrl)", baseUrl),
|
|
550
|
+
field("接口类型", apiSel),
|
|
551
|
+
field("API Key", key, "只存在服务器上,不会再显示"),
|
|
552
|
+
src?.hasKey ? h("label", { class: "check-item" }, clearKey, "清除已保存的 Key") : null,
|
|
553
|
+
field("模型", models),
|
|
554
|
+
h("div", { class: "row" }, discover),
|
|
555
|
+
h("div", { class: "row" }, h("label", { class: "check" }, reasoning, "支持思考"), h("label", { class: "check" }, image, "支持图片"), field("上下文长度(token)", ctx)),
|
|
556
|
+
h("div", { class: "row" }, save, h("button", { class: "btn small", onclick: done }, "取消")));
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* 订阅账号登录:服务端在后台跑 pi 的登录流程,这里每 1.5 秒拉一次状态,
|
|
561
|
+
* 把登录链接、设备码显示出来,pi 要问的(登录方式、企业域名、回调地址)就地作答。
|
|
562
|
+
*/
|
|
563
|
+
async function piOAuthFlow(panel, provider, after) {
|
|
564
|
+
let timer = null;
|
|
565
|
+
let shownPrompt = null;
|
|
566
|
+
const stop = () => {
|
|
567
|
+
clearTimeout(timer);
|
|
568
|
+
timer = null;
|
|
569
|
+
};
|
|
570
|
+
const cancel = h("button", { class: "btn small", onclick: async () => {
|
|
571
|
+
stop();
|
|
572
|
+
await api("/api/agents/pi/oauth", { method: "DELETE" }).catch(() => {});
|
|
573
|
+
panel.replaceChildren();
|
|
574
|
+
} }, "取消");
|
|
575
|
+
const answer = async (id, value) => {
|
|
576
|
+
try {
|
|
577
|
+
render((await api("/api/agents/pi/oauth/answer", { method: "POST", body: { id, value } })).state);
|
|
578
|
+
} catch (err) {
|
|
579
|
+
toast(err.message, 5000);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
const promptEl = (pr) => {
|
|
583
|
+
if (pr.type === "select") {
|
|
584
|
+
return h("div", { class: "field" }, h("span", {}, pr.message), h("div", { class: "row" }, pr.options.map((o) => h("button", { class: "btn small", title: o.description ?? "", onclick: () => answer(pr.id, o.id) }, o.label))));
|
|
585
|
+
}
|
|
586
|
+
const input = h("input", { type: pr.type === "secret" ? "password" : "text", autocomplete: "off", placeholder: pr.placeholder ?? (pr.type === "manual_code" ? "粘贴浏览器最后跳到的地址,或者授权码" : "") });
|
|
587
|
+
const submit = h("button", { class: "btn small primary", onclick: () => answer(pr.id, input.value) }, "提交");
|
|
588
|
+
input.addEventListener("keydown", (e) => e.key === "Enter" && submit.click());
|
|
589
|
+
return h("div", { class: "field" }, h("span", {}, pr.message), h("div", { class: "row" }, input, submit),
|
|
590
|
+
pr.type === "manual_code" ? h("small", {}, "浏览器在别的机器上时,登录完会跳到一个打不开的 127.0.0.1 / localhost 地址:把地址栏里的整个地址复制过来就行。") : null);
|
|
591
|
+
};
|
|
592
|
+
const noticeEl = (n) => {
|
|
593
|
+
if (n.type === "auth_url") return h("div", {}, h("a", { href: n.url, target: "_blank", rel: "noopener noreferrer", class: "btn small primary" }, "打开登录页"), n.instructions ? h("small", {}, ` ${n.instructions}`) : null);
|
|
594
|
+
if (n.type === "device_code") {
|
|
595
|
+
const copy = h("button", { class: "btn small", onclick: () => copyText(n.userCode, copy) }, "复制");
|
|
596
|
+
return h("div", {}, h("div", { class: "health-cmd" }, h("code", {}, n.userCode), copy), h("small", {}, "到 ", h("a", { href: n.verificationUri, target: "_blank", rel: "noopener noreferrer" }, n.verificationUri), " 输入上面的代码"));
|
|
597
|
+
}
|
|
598
|
+
return h("small", { class: "muted" }, n.message, ...(n.links ?? []).map((l) => [" ", h("a", { href: l.url, target: "_blank", rel: "noopener noreferrer" }, l.label ?? l.url)]));
|
|
599
|
+
};
|
|
600
|
+
const render = (st) => {
|
|
601
|
+
if (!st) {
|
|
602
|
+
stop();
|
|
603
|
+
panel.replaceChildren();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (st.status === "done") {
|
|
607
|
+
stop();
|
|
608
|
+
panel.replaceChildren();
|
|
609
|
+
toast("订阅账号已登录。模型列表一分钟内刷新", 5000);
|
|
610
|
+
after();
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (st.status !== "running") {
|
|
614
|
+
stop();
|
|
615
|
+
fill(panel, h("div", { class: "error-text" }, st.status === "cancelled" ? "登录已取消" : `登录失败:${st.error ?? "未知原因"}`));
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
// 输入框里正在打字:问题没变就别重画
|
|
619
|
+
if (st.prompt && shownPrompt === st.prompt.id && panel.contains(document.activeElement)) return;
|
|
620
|
+
shownPrompt = st.prompt?.id ?? null;
|
|
621
|
+
fill(panel, h("div", { class: "health-fix" }, st.notices.map(noticeEl), st.prompt ? promptEl(st.prompt) : h("small", {}, "等你在浏览器里完成登录…"), h("div", { class: "row" }, cancel)));
|
|
622
|
+
};
|
|
623
|
+
const poll = async () => {
|
|
624
|
+
try {
|
|
625
|
+
render((await api("/api/agents/pi/oauth")).state);
|
|
626
|
+
} catch {
|
|
627
|
+
// 网络抖一下,下次再拉
|
|
628
|
+
}
|
|
629
|
+
if (timer !== null) timer = setTimeout(poll, 1500);
|
|
630
|
+
};
|
|
631
|
+
try {
|
|
632
|
+
render((await api("/api/agents/pi/oauth", { method: "POST", body: { provider } })).state);
|
|
633
|
+
timer = setTimeout(poll, 1500);
|
|
634
|
+
} catch (err) {
|
|
635
|
+
toast(`登录失败:${err.message}`, 6000);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
363
639
|
/** 账号额度:侧栏底部、/status、桌面端显示的 Claude / Codex 订阅额度,查不查、多久查一次 */
|
|
364
640
|
function quotaSection(cfg) {
|
|
365
641
|
const quotaOn = h("input", { type: "checkbox", checked: cfg.web?.quotaEnabled !== false });
|
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", "workbuddy", "cd", "pwd", "permission", "planmode", "autoedit", "web", "detach", "approve", "help"];
|
|
78
|
+
const BUILTIN_NAMES = ["new", "status", "stop", "model", "effort", "sessions", "resume", "fork", "agent", "claude", "codex", "workbuddy", "pi", "cd", "pwd", "permission", "planmode", "autoedit", "web", "detach", "approve", "help"];
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* 添加 / 编辑一条自定义命令。onSave 返回 true 才关窗;失败(比如服务端校验没过)留着让用户改。
|
package/web/settings/experts.js
CHANGED
|
@@ -10,10 +10,10 @@ 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", workbuddy: "WorkBuddy" };
|
|
13
|
+
const ENGINE_LABEL = { claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy", pi: "pi" };
|
|
14
14
|
/** 权限的几项勾选。读文件 → 改文件 → 跑命令一级包含一级(跑命令就等于能改任何文件) */
|
|
15
15
|
const PERMS = [
|
|
16
|
-
{ id: "webSearch", label: "联网搜索", hint: "用搜索引擎查资料" },
|
|
16
|
+
{ id: "webSearch", label: "联网搜索", hint: "用搜索引擎查资料", engines: ["claude", "codex"] },
|
|
17
17
|
{ id: "webFetch", label: "读网页", hint: "打开网址读内容", claudeOnly: true },
|
|
18
18
|
{ id: "read", label: "读文件", hint: "读工作目录里的文件,不能改" },
|
|
19
19
|
{ id: "edit", label: "改文件", hint: "读写工作目录里的文件,不能跑命令(Codex 改文件也要跑命令,只能改工作目录里的)" },
|
|
@@ -193,6 +193,11 @@ function openEditor(data, e, reload, preset) {
|
|
|
193
193
|
h("option", { value: "lean", selected: (src.basePrompt ?? "lean") === "lean" }, "只用上面的提示词(省 token,推荐)"),
|
|
194
194
|
h("option", { value: "claude_code", selected: src.basePrompt === "claude_code" }, "追加在 Claude Code 原装提示词后面(写代码、干活更稳,每轮多约 1.6 万 token)"),
|
|
195
195
|
);
|
|
196
|
+
// 「追加在原装后面」的说法跟着引擎变:pi 的原装提示词很短
|
|
197
|
+
const BASE_LABEL = {
|
|
198
|
+
claude: "追加在 Claude Code 原装提示词后面(写代码、干活更稳,每轮多约 1.6 万 token)",
|
|
199
|
+
pi: "追加在 pi 原装提示词后面(带上 pi 的工具用法和规则,每轮多约 600 token)",
|
|
200
|
+
};
|
|
196
201
|
const perms = permChecks(src);
|
|
197
202
|
let cwd = src.cwd ?? "";
|
|
198
203
|
const cwdBtn = h("button", { type: "button", class: "btn task-cwd" });
|
|
@@ -243,7 +248,8 @@ function openEditor(data, e, reload, preset) {
|
|
|
243
248
|
);
|
|
244
249
|
fill(subBox, subs.el);
|
|
245
250
|
subField.hidden = eng !== "claude";
|
|
246
|
-
baseField.hidden = eng !== "claude";
|
|
251
|
+
baseField.hidden = eng !== "claude" && eng !== "pi";
|
|
252
|
+
if (BASE_LABEL[eng]) basePrompt.options[1].textContent = BASE_LABEL[eng];
|
|
247
253
|
perms.setEngine(eng);
|
|
248
254
|
void models.load(eng);
|
|
249
255
|
};
|
|
@@ -353,7 +359,8 @@ function permChecks(src) {
|
|
|
353
359
|
checked: (id) => boxes.get(id).checked,
|
|
354
360
|
access: () => [...FILE_LEVELS].reverse().find((id) => boxes.get(id).checked) ?? "web",
|
|
355
361
|
setEngine: (engine) => {
|
|
356
|
-
|
|
362
|
+
// pi 没有自带的联网工具:要联网就给专家挂一个搜索 MCP
|
|
363
|
+
for (const x of items) x.el.hidden = (!!x.p.claudeOnly && engine !== "claude") || (!!x.p.engines && !x.p.engines.includes(engine));
|
|
357
364
|
},
|
|
358
365
|
});
|
|
359
366
|
}
|
package/web/settings/memory.js
CHANGED
|
@@ -520,6 +520,7 @@ function curateSection(mem, reload) {
|
|
|
520
520
|
["claude", "Claude Code"],
|
|
521
521
|
["codex", "Codex"],
|
|
522
522
|
["workbuddy", "WorkBuddy"],
|
|
523
|
+
["pi", "pi"],
|
|
523
524
|
],
|
|
524
525
|
(v) => save({ agent: v, model: "" }),
|
|
525
526
|
);
|
|
@@ -527,7 +528,7 @@ function curateSection(mem, reload) {
|
|
|
527
528
|
c.agent === "auto"
|
|
528
529
|
? null
|
|
529
530
|
: (() => {
|
|
530
|
-
const sel = h("select", { onchange: (e) => save({ model: e.target.value }) }, h("option", { value: "" }, c.agent === "claude" ? "默认:Haiku(最省)" : c.agent === "workbuddy" ? "默认模型" : "默认模型,思考程度 low(最省)"));
|
|
531
|
+
const sel = h("select", { onchange: (e) => save({ model: e.target.value }) }, h("option", { value: "" }, c.agent === "claude" ? "默认:Haiku(最省)" : c.agent === "workbuddy" ? "默认模型" : c.agent === "pi" ? "默认模型(思考程度 minimal)" : "默认模型,思考程度 low(最省)"));
|
|
531
532
|
if (c.model) sel.append(h("option", { value: c.model, selected: true }, c.model));
|
|
532
533
|
agentCatalog(c.agent)
|
|
533
534
|
.then((models) => {
|
package/web/views/composer.js
CHANGED
|
@@ -359,7 +359,7 @@ export async function sendMessage() {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
/** 会改变当前会话(换会话、换目录、换 agent)的命令,执行完要重拉一遍 */
|
|
362
|
-
const RELOADING_COMMANDS = new Set(["new", "fork", "resume", "agent", "claude", "codex", "workbuddy", "cd"]);
|
|
362
|
+
const RELOADING_COMMANDS = new Set(["new", "fork", "resume", "agent", "claude", "codex", "workbuddy", "pi", "cd"]);
|
|
363
363
|
|
|
364
364
|
/** agent-loft 命令的结果:只显示给发命令的这个页面,不进会话记录 */
|
|
365
365
|
async function showCommandReply(text, reply, info) {
|
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 === "workbuddy" ? "WorkBuddy" : id;
|
|
241
|
+
return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id === "workbuddy" ? "WorkBuddy" : id === "pi" ? "pi" : id;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/** 侧栏状态:order 混排目录路径和渠道分组,兼容原有的顺序。 */
|
package/web/views/topbar.js
CHANGED
|
@@ -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", workbuddy: "WorkBuddy" };
|
|
51
|
+
const ENGINE_LABEL = { claude: "Claude", codex: "Codex", workbuddy: "WorkBuddy", pi: "pi" };
|
|
52
52
|
/** 鼠标停多久才弹、离开多久才收(从头像挪到卡片上的那一下不能收) */
|
|
53
53
|
const HOVER_OPEN_MS = 250;
|
|
54
54
|
const HOVER_CLOSE_MS = 200;
|