agent-loft 0.2.97 → 0.2.98

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.
@@ -522,7 +522,11 @@ export async function mcpTab(panel) {
522
522
  await load();
523
523
  }
524
524
 
525
+ /** 这个账号能不能添加本机进程(stdio)MCP:只有管理员 */
526
+ let canStdio = true;
527
+
525
528
  function renderMcp(box, data, reload) {
529
+ canStdio = data.stdio !== false;
526
530
  fill(
527
531
  box,
528
532
  h(
@@ -531,7 +535,8 @@ function renderMcp(box, data, reload) {
531
535
  h(
532
536
  "p",
533
537
  { class: "skill-note" },
534
- "MCP 服务提供查数据、调接口等工具,只供你自己的账号使用。这里加好后,自定义专家在「专家」里勾选;内置的 Claude Code / Codex 在「Agent」各自卡片的「默认加载」中选择。",
538
+ "MCP 服务提供查数据、调接口等工具。这里加好后,自定义专家在「专家」里勾选;内置的 Claude Code / Codex 在「Agent」各自卡片的「默认加载」中选择。可以把自己的 MCP 共享给所有账号:别人拿到的是地址、命令这些设置,标成密钥的项各自填自己的值,你的密钥不会给出去;别人用共享的 MCP 时,调用工具前都会先询问。" +
539
+ (canStdio ? "" : "本机进程(stdio)会在服务器上直接执行命令,只有管理员能添加。"),
535
540
  ),
536
541
  h("div", { class: "skill-head-btns" }, h("button", { class: "btn primary", onclick: () => openMcpEditor(null, reload) }, icon("plus"), "添加")),
537
542
  ),
@@ -540,23 +545,30 @@ function renderMcp(box, data, reload) {
540
545
  "div",
541
546
  { class: "task-list" },
542
547
  data.servers.map((s) => {
548
+ const secrets = [...(s.env ?? []), ...(s.headers ?? [])].filter((p) => p.secret);
549
+ const open = () => (s.mine ? openMcpEditor(s, reload) : secrets.length ? openMcpValues(s, secrets, reload) : null);
543
550
  const more = h("button", { class: "icon-btn", title: "更多" }, icon("more"));
544
551
  more.onclick = () =>
545
- showMenu(more, [
546
- { label: "编辑…", onclick: () => openMcpEditor(s, reload) },
547
- "sep",
548
- { label: "删除", danger: true, onclick: () => removeMcp(s, reload) },
549
- ]);
552
+ showMenu(
553
+ more,
554
+ s.mine
555
+ ? [{ label: "编辑…", onclick: () => openMcpEditor(s, reload) }, "sep", { label: "删除", danger: true, onclick: () => removeMcp(s, reload) }]
556
+ : [{ label: secrets.length ? "填写我的密钥…" : "不需要填写密钥", onclick: () => secrets.length && openMcpValues(s, secrets, reload) }],
557
+ );
558
+ const missing = !s.mine && secrets.some((p) => !p.set);
550
559
  return h(
551
560
  "div",
552
561
  { class: "task-card skill-card" },
553
- h("div", { class: "task-top" }, h("button", { class: "task-title skill-name", onclick: () => openMcpEditor(s, reload) }, s.name), more),
562
+ h("div", { class: "task-top" }, h("button", { class: "task-title skill-name", onclick: open }, s.name), more),
554
563
  h(
555
564
  "div",
556
565
  { class: "task-meta" },
566
+ s.mine ? (s.shared ? h("span", {}, "已共享给所有人") : null) : h("span", {}, `${s.ownerName} 共享`),
557
567
  h("span", {}, s.type === "http" ? "HTTP" : "本机进程"),
558
568
  h("span", { class: "mono" }, s.type === "http" ? s.url : [s.command, ...s.args].join(" ")),
559
- s.ask ? h("span", {}, "调用前询问") : null,
569
+ !s.runnable ? h("span", { class: "skill-warn" }, "已停用:本机进程只有管理员能用,请改用 HTTP 或删除") : null,
570
+ missing ? h("span", { class: "skill-warn" }, "密钥没填") : null,
571
+ s.ask || !s.mine ? h("span", {}, "调用前询问") : null,
560
572
  h("span", {}, s.usedBy.length ? `${s.usedBy.join("、")} 在用` : "还没有专家用它"),
561
573
  ),
562
574
  s.description ? h("div", { class: "task-prompt" }, s.description) : null,
@@ -567,6 +579,40 @@ function renderMcp(box, data, reload) {
567
579
  );
568
580
  }
569
581
 
582
+ /** 别人共享的 MCP:填自己的密钥(作者的不会给你) */
583
+ function openMcpValues(s, secrets, reload) {
584
+ const rows = secrets.map((p) => {
585
+ const input = h("input", { type: "password", autocomplete: "off", spellcheck: "false", placeholder: p.set ? "已填写(不显示),留空不改" : "填你自己的值" });
586
+ const clear = p.set ? h("button", { type: "button", class: "btn ghost", onclick: () => ((input.dataset.clear = "1"), (input.value = ""), (clear.hidden = true)) }, "清除") : null;
587
+ return { p, input, el: h("div", { class: "field" }, h("span", {}, h("code", {}, p.name)), h("div", { class: "skill-var-row" }, input, clear)) };
588
+ });
589
+ const save = h("button", { class: "btn primary" }, "保存");
590
+ const close = modal({
591
+ title: `${s.name} 的密钥`,
592
+ body: h("div", { class: "modal-body task-form" }, h("p", { class: "skill-note" }, `${s.ownerName} 共享的 MCP。这些值只给你自己的会话用,作者看不到;不填就不带这一项。`), rows.map((r) => r.el)),
593
+ foot: h("div", { class: "modal-foot" }, save),
594
+ });
595
+ rows[0]?.input.focus();
596
+ save.onclick = async () => {
597
+ const values = {};
598
+ for (const r of rows) {
599
+ if (r.input.value) values[r.p.name] = r.input.value;
600
+ else if (r.input.dataset.clear === "1") values[r.p.name] = null;
601
+ }
602
+ if (!Object.keys(values).length) return close();
603
+ save.disabled = true;
604
+ try {
605
+ await api(`/api/mcp/${s.id}/values`, { method: "PUT", body: { values } });
606
+ close();
607
+ toast("已保存,新消息起生效");
608
+ void reload();
609
+ } catch (err) {
610
+ save.disabled = false;
611
+ toast(err.message);
612
+ }
613
+ };
614
+ }
615
+
570
616
  async function removeMcp(s, reload) {
571
617
  const sure = await confirmDialog({
572
618
  title: `删除 MCP「${s.name}」?`,
@@ -611,8 +657,8 @@ function openMcpEditor(s, reload) {
611
657
  const type = h(
612
658
  "select",
613
659
  { disabled: !!s },
614
- h("option", { value: "stdio", selected: (s?.type ?? "stdio") === "stdio" }, "本机进程(stdio)"),
615
- h("option", { value: "http", selected: s?.type === "http" }, "HTTP 地址"),
660
+ canStdio || s?.type === "stdio" ? h("option", { value: "stdio", selected: (s?.type ?? (canStdio ? "stdio" : "http")) === "stdio" }, "本机进程(stdio)") : null,
661
+ h("option", { value: "http", selected: (s?.type ?? (canStdio ? "stdio" : "http")) === "http" }, "HTTP 地址"),
616
662
  );
617
663
  const command = h("input", { value: s?.command ?? "", placeholder: "比如 npx、python、/usr/local/bin/xxx-mcp", spellcheck: "false" });
618
664
  const args = h("textarea", { rows: 3, placeholder: "一行一个参数,比如:\n-y\n@modelcontextprotocol/server-fetch", spellcheck: "false" });
@@ -621,6 +667,7 @@ function openMcpEditor(s, reload) {
621
667
  const env = pairsEditor(s?.env, "env");
622
668
  const headers = pairsEditor(s?.headers, "header");
623
669
  const ask = h("input", { type: "checkbox", checked: !!s?.ask });
670
+ const shared = h("input", { type: "checkbox", checked: !!s?.shared });
624
671
  const stdioPart = h("div", { class: "field-group" }, field("命令", command), field("参数", args), field("环境变量", env.el, "比如 API 密钥。标成密钥的网页上不回显,只交给这个 MCP 进程,agent 看不到"));
625
672
  const httpPart = h("div", { class: "field-group" }, field("地址", url), field("请求头", headers.el, "比如 Authorization: Bearer xxx。标成密钥的网页上不回显"));
626
673
  const sync = () => {
@@ -638,6 +685,11 @@ function openMcpEditor(s, reload) {
638
685
  stdioPart,
639
686
  httpPart,
640
687
  field("授权", h("label", { class: "check-item" }, ask, h("span", {}, "调用它的工具前先问我(不勾就直接用:这是你自己给专家挂的)"))),
688
+ field(
689
+ "共享",
690
+ h("label", { class: "check-item" }, shared, h("span", {}, "共享给所有账号")),
691
+ "别人拿到命令、地址和普通的环境变量 / 请求头;标成「密钥」的项各自填自己的值,你填的不会给出去。取消共享后别人填的值一起删掉",
692
+ ),
641
693
  );
642
694
  const save = h("button", { class: "btn primary" }, s ? "保存" : "添加");
643
695
  const close = modal({ title: s ? `编辑 ${s.name}` : "添加 MCP", wide: true, body, foot: h("div", { class: "modal-foot" }, save) });
@@ -646,6 +698,7 @@ function openMcpEditor(s, reload) {
646
698
  const payload = {
647
699
  description: desc.value,
648
700
  ask: ask.checked,
701
+ shared: shared.checked,
649
702
  ...(type.value === "stdio"
650
703
  ? {
651
704
  command: command.value,
@@ -121,7 +121,7 @@ function renderList() {
121
121
  if (K.tab === "shared") {
122
122
  const list = shared().filter(matches);
123
123
  return [
124
- h("p", { class: "skill-note" }, "这里是其他用户共享给你的技能。安装前可点开查看说明和附带文件;安装后跟随作者更新,撤回共享后将无法再用。变量和密钥使用你自己填写的值。"),
124
+ h("p", { class: "skill-note" }, "这里是其他用户共享给你的技能。安装前可点开查看说明和附带文件;作者改了内容后,要你看过并确认新版才会继续加载,撤回共享后将无法再用。变量和密钥使用你自己填写的值。"),
125
125
  list.length ? h("div", { class: "task-list" }, list.map(sharedCard)) : h("div", { class: "skill-empty" }, K.query ? "没有找到" : "还没有别人共享给你的技能"),
126
126
  ];
127
127
  }
@@ -142,7 +142,7 @@ function renderList() {
142
142
  function varsState(s) {
143
143
  if (!s.vars.length) return null;
144
144
  const missing = s.vars.filter((v) => v.required && !K.data.vars[v.name]?.set);
145
- const pending = s.vars.filter((v) => K.data.vars[v.name]?.pending);
145
+ const pending = s.vars.filter((v) => s.hosts?.[v.name]?.pending?.length);
146
146
  if (missing.length) return h("span", { class: "skill-warn" }, `${missing.length} 个变量没填`);
147
147
  if (pending.length) return h("span", { class: "skill-warn" }, "密钥的发送地址待确认");
148
148
  return h("span", {}, `${s.vars.length} 个变量`);
@@ -150,7 +150,7 @@ function varsState(s) {
150
150
 
151
151
  /** 要去「填写变量」处理的:必填的没填,或者受保护密钥的地址待确认 */
152
152
  function varsNeedAttention(s) {
153
- return s.vars.some((v) => (v.required && !K.data.vars[v.name]?.set) || K.data.vars[v.name]?.pending);
153
+ return s.vars.some((v) => (v.required && !K.data.vars[v.name]?.set) || s.hosts?.[v.name]?.pending?.length);
154
154
  }
155
155
 
156
156
  function mineCard(s) {
@@ -199,26 +199,29 @@ function mineCard(s) {
199
199
  s.mine && SHARED[s.visibility] ? h("span", {}, SHARED[s.visibility]) : null,
200
200
  s.mine && s.installs ? h("span", {}, `${s.installs} 人安装`) : null,
201
201
  s.source === "agent" ? h("span", {}, "agent 生成") : null,
202
+ s.updatePending ? h("span", { class: "skill-warn" }, "作者已更新,待确认") : null,
202
203
  varsState(s),
203
204
  ),
204
205
  h("div", { class: "task-prompt" }, s.description),
205
- varsNeedAttention(s)
206
+ s.updatePending
207
+ ? h("button", { class: "task-run", onclick: () => openDetail(s) }, "作者更新了内容,查看并确认后才会继续加载 →")
208
+ : varsNeedAttention(s)
206
209
  ? h("button", { class: "task-run", onclick: () => openVars(s) }, s.vars.some((v) => v.required && !K.data.vars[v.name]?.set) ? "填写变量后才能正常使用 →" : "确认密钥的发送地址 →")
207
210
  : null,
208
211
  );
209
212
  }
210
213
 
211
214
  function sharedCard(s) {
212
- const install = h("button", { class: "btn primary", onclick: () => installShared(s, install) }, "安装");
215
+ const install = s.canInstall ? h("button", { class: "btn primary", onclick: () => installShared(s, install) }, "安装") : null;
213
216
  return h(
214
217
  "div",
215
218
  { class: "task-card skill-card" },
216
219
  h("div", { class: "task-top" },
217
220
  h("button", { class: "task-title skill-name", title: "查看", onclick: () => openDetail(s) }, s.name),
218
- s.installed ? h("span", { class: "badge" }, s.enabled ? "已安装" : "已安装 · 已停用") : install,
221
+ s.installed ? h("span", { class: "badge" }, s.updatePending ? "已安装 · 有更新待确认" : s.enabled ? "已安装" : "已安装 · 已停用") : install,
219
222
  s.canDelete ? h("button", { class: "btn", onclick: () => removeSkill(s) }, "下架") : null,
220
223
  ),
221
- h("div", { class: "task-meta" }, h("span", {}, `${s.ownerName} 建的`), h("span", {}, SHARED[s.visibility]), s.vars.length ? h("span", {}, `${s.vars.length} 个变量`) : null),
224
+ h("div", { class: "task-meta" }, h("span", {}, `${s.ownerName} 建的`), h("span", {}, s.canInstall ? SHARED[s.visibility] : "分享给了别人(管理员可查看、下架)"), s.vars.length ? h("span", {}, `${s.vars.length} 个变量`) : null),
222
225
  h("div", { class: "task-prompt" }, s.description),
223
226
  );
224
227
  }
@@ -298,7 +301,23 @@ async function openDetail(s) {
298
301
  return;
299
302
  }
300
303
  if (d.mine) foot.append(h("button", { class: "btn", onclick: () => (close(), openSharing(d)) }, "共享…"));
301
- else if (!d.installed) {
304
+ else if (d.updatePending) {
305
+ const accept = h("button", { class: "btn primary" }, "确认使用新版");
306
+ accept.onclick = async () => {
307
+ accept.disabled = true;
308
+ try {
309
+ const next = await api(`/api/skills/${d.id}/accept`, { method: "POST", body: {} });
310
+ toast("已确认,新消息起加载新版");
311
+ close();
312
+ await reload();
313
+ if (varsNeedAttention(next)) openVars(next);
314
+ } catch (err) {
315
+ accept.disabled = false;
316
+ toast(err.message);
317
+ }
318
+ };
319
+ foot.append(accept);
320
+ } else if (!d.installed && d.canInstall) {
302
321
  const install = h("button", { class: "btn primary", onclick: async () => { if (await installShared(d, install)) close(); } }, "安装");
303
322
  foot.append(install);
304
323
  }
@@ -312,6 +331,9 @@ async function openDetail(s) {
312
331
  h("span", {}, SHARED[d.visibility]),
313
332
  h("span", {}, `更新于 ${new Date(d.updatedAt).toLocaleString()}`),
314
333
  ),
334
+ d.updatePending
335
+ ? h("p", { class: "skill-pending" }, "作者在你安装之后改过这个技能(说明、附带文件或变量)。下面是现在的内容,看过没问题再点「确认使用新版」;确认之前你的会话不会加载它。")
336
+ : null,
315
337
  h("p", { class: "skill-desc" }, d.description),
316
338
  d.vars.length
317
339
  ? h(
@@ -400,15 +422,18 @@ function openVars(s) {
400
422
  });
401
423
  const clear = cur?.set ? h("button", { type: "button", class: "btn ghost", onclick: () => ((input.value = ""), (input.dataset.clear = "1"), (clear.hidden = true)) }, "清除") : null;
402
424
  // 受保护的密钥:agent 看不到值,只能经 agent-loft 发往这些地址;作者改了地址要这里再确认
425
+ const hosts = s.hosts?.[v.name];
403
426
  const guard = v.secret && v.hosts?.length
404
- ? h("small", { class: "skill-guard" }, `受保护:agent 看不到这个值,只能通过 agent-loft 代发请求,发往 ${(cur?.hosts?.length ? cur.hosts : v.hosts).join("、")}。填写即表示同意发往这些地址。`)
405
- : null;
427
+ ? h("small", { class: "skill-guard" }, `受保护:agent 看不到这个值,只能通过 agent-loft 代发请求。${cur?.set && hosts?.allowed?.length ? `这个技能可以发往 ${hosts.allowed.join("、")}。` : `填写即表示同意这个技能发往 ${v.hosts.join("、")}(别的技能声明的地址要在各自的变量页里另外确认)。`}`)
428
+ : cur?.guarded
429
+ ? h("small", { class: "skill-guard" }, "这个值是按受保护的密钥填的,不会作为环境变量交给 agent。要当普通变量用,请在这里重新填写。")
430
+ : null;
406
431
  const r = { v, input, approve: false };
407
- const pending = cur?.pending?.length
432
+ const pending = hosts?.pending?.length
408
433
  ? h(
409
434
  "div",
410
435
  { class: "skill-pending" },
411
- `作者新加了发送地址:${cur.pending.join("、")}。确认之前,这个密钥不会发往新地址。`,
436
+ `这个技能要把 ${v.name} 发往还没确认过的地址:${hosts.pending.join("、")}。确认之前,不会发往这些地址。`,
412
437
  h("button", { type: "button", class: "btn small", onclick: (e) => ((r.approve = true), (e.currentTarget.textContent = "保存后生效"), (e.currentTarget.disabled = true)) }, "确认"),
413
438
  )
414
439
  : null;
@@ -446,7 +471,7 @@ function openVars(s) {
446
471
  if (!Object.keys(values).length && !approve.length) return close();
447
472
  save.disabled = true;
448
473
  try {
449
- await api("/api/skills/vars", { method: "PUT", body: { values, approve } });
474
+ await api("/api/skills/vars", { method: "PUT", body: { values, approve, skill: s.id } });
450
475
  close();
451
476
  toast("已保存,新消息起生效");
452
477
  void reload();