dsh-wecom-bot 1.0.0 → 1.2.0

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 CHANGED
@@ -10,7 +10,7 @@
10
10
  | --- | --- | --- |
11
11
  | 谁在说话 | 你自己(管理员) | 同事、群聊 |
12
12
  | 会话 | 任意会话,`/sessions` + `/use` 切换 | 每人一个会话;一个群共享一个 |
13
- | 关键配置 | 管理员 + 通知范围 | 用户分组(工作区 / 模型 / Agent 预设)+ 成员 |
13
+ | 关键配置 | 管理员 + 通知范围 | 用户分组(工作区 / 模型 / Agent 预设 / 工作区权限)+ 成员 |
14
14
 
15
15
  - **遥控自己的 DSH**:把自己加为管理员,手机上就能查看、切换、推进任意会话,审批工具调用;引用一条通知即可继续那条会话。
16
16
  - **分享给团队**:先在 DSH 里准备好工作区、MCP、skills 和 Agent 预设,再建一个指向它的分组,把同事或群聊加进去。不同团队用不同分组即可。
@@ -30,7 +30,7 @@
30
30
 
31
31
  - **连接**:在线状态、Bot ID / Secret、本次启动以来的收发统计;「编辑」展开表单。
32
32
  - **待授权**:被拒绝的发信人及其最后一条消息(只在内存里,重启清空);「加入分组」即授权,可顺手填备注。
33
- - **用户分组**:每个分组一张卡片,标题下列出它的工作区、模型、推理等级、Agent 预设;展开看成员表——会话状态、模型、推理等级、上下文占用。点成员名查看/修改备注、切换分组、移出分组;点会话状态查看会话详情,在那里「打开会话」或「归档会话」。「编辑」在卡片内修改分组,删除分组也在这里。
33
+ - **用户分组**:每个分组一张卡片,标题下列出它的工作区、模型、推理等级、Agent 预设、工作区权限;展开看成员表——会话状态、模型、推理等级、工作区权限、上下文占用。点成员名查看/修改备注、切换分组、移出分组;点会话状态查看会话详情(含会话的工作区权限,可直接修改),在那里「打开会话」或「归档会话」。「编辑」在卡片内修改分组,删除分组也在这里。
34
34
  - **管理员**:添加/移除管理员,设置「通知范围」(默认全部工作区)。
35
35
  - **高级设置**(默认折叠):私有化部署的 WebSocket 地址(保存会重连)与对话日志。
36
36
 
@@ -39,9 +39,11 @@
39
39
  ## 规则
40
40
 
41
41
  - **授权 = 加入分组**。不在任何分组的人只会收到一条「用户未授权」;删除分组会取消其成员的授权(不会把他们挪进默认分组)。
42
+ - **工作区权限**(与 DSH 会话里的权限选项一致:仅可查看 / 工作区内修改 / 完全权限)由分组决定,**默认「仅可查看」**——远程聊天不会不声不响地获得写权限。新建的会话先被设成分组的权限才会交给成员;改分组的权限会立即应用到组内已有的会话(包括单独改过权限的成员)。成员行或会话详情里改权限只影响该会话。选「完全权限」时会像 DSH 一样先出风险提示,勾选「我已了解风险」才能确认。权限写在 DSH 会话本身,页面读取的永远是会话当前的实际值。已有分组升级后显示为「仅可查看」,但它们**已存在**的会话保持原样,直到你在分组里保存一次权限。
42
43
  - **分组决定新会话的工作区、模型(含推理等级)和 Agent 预设**;成员行里改模型只影响该成员当前会话。Agent 预设只在新建会话时生效;改分组的工作区会让成员在下一条消息时新建会话。切回原分组时会恢复之前的会话(仍可用的话)。
43
44
  - **会话**:私聊一人一个、群聊整群共享一个;标题为 `wecom-bot-<userid 或 chatid>`。归档(页面或 `/delete`)后,下一条消息新建会话;DSH 没有删除会话的 API,记录仍在「已归档」里。
44
45
  - **管理员**可以在单聊里切换会话、新建会话、审批工具调用,并接收通知范围内所有会话的通知。管理员命令在群聊里一律拒绝;工具审批只发给管理员。
46
+ - **工具审批是一张卡片**:点「批准 / 拒绝」即可,不必再抄 `/approve <验证码>`;处理完卡片会变成「已批准 / 已拒绝」且不再有按钮。企微没有「禁用按钮」这种状态,所以是换卡片而不是置灰按钮;卡片发不出去时自动退回带验证码的文字。已在别处(DSH 页面、文字指令)处理或超时的卡片,管理员再点一次会被换成「已失效」。
45
47
  - **备注属于人**,不随移出分组而丢失。
46
48
 
47
49
  ## 企业微信指令
@@ -53,7 +55,7 @@
53
55
  | `/cancel` | 停止正在运行的回合 | 所有人 |
54
56
  | `/answer <验证码> <选项或文字>` | 回答 DSH 的提问 | 所有人 |
55
57
  | `/compact`、`/delete`(再 `/delete confirm`) | 压缩上下文;归档当前会话 | 所有人(群聊需管理员) |
56
- | `/approve <验证码>`、`/deny <验证码>` | 审批工具调用(与 DSH 页面同时可处理,先到先得) | 管理员,单聊 |
58
+ | `/approve <验证码>`、`/deny <验证码>` | 审批工具调用(与 DSH 页面同时可处理,先到先得);审批请求本身是一张带「批准 / 拒绝」按钮的卡片,按钮和验证码等价 | 管理员,单聊 |
57
59
  | `/sessions`、`/use <序号或 ID 前缀>`、`/reset` | 列出、切换会话;回到自己的会话 | 管理员,单聊 |
58
60
  | `/workspaces [序号]`、`/new` | 选择默认工作区;在其中新建会话 | 管理员,单聊 |
59
61
  | 引用一条通知 | 之后的消息落到那条通知的会话 | 管理员,单聊 |
package/dist/client.js CHANGED
@@ -49,6 +49,7 @@ window.__ModuleLoader__.load({
49
49
  var MIN_LOG_RETENTION_DAYS = 1;
50
50
  var MAX_LOG_RETENTION_DAYS = 365;
51
51
  var DEFAULT_LOG_RETENTION_DAYS = 14;
52
+ var FULL_ACCESS_MODE = "danger-full-access";
52
53
 
53
54
  // src/client/components/SettingsPage.tsx
54
55
  var import_react9 = require("react");
@@ -272,6 +273,24 @@ window.__ModuleLoader__.load({
272
273
  if (member.sessionRunning) return "运行中";
273
274
  return member.sessionState === "blank" ? "待使用" : "空闲";
274
275
  }
276
+ var PERMISSION_LABEL = {
277
+ "read-only": "仅可查看",
278
+ "workspace-write": "工作区内修改",
279
+ "danger-full-access": "完全权限",
280
+ auto: "自动审查(实验)",
281
+ custom: "自定义"
282
+ };
283
+ function permissionLabel(value) {
284
+ return value ? PERMISSION_LABEL[value] ?? value : "—";
285
+ }
286
+ var PERMISSION_HINT = {
287
+ "read-only": "只能读取工作区;修改文件或执行有副作用的命令需要审批。",
288
+ "workspace-write": "可以在工作区内修改文件;超出工作区的操作需要审批。",
289
+ "danger-full-access": "不受沙箱限制,也不再询问审批。"
290
+ };
291
+ function needsRiskAcknowledgement(mode) {
292
+ return mode === FULL_ACCESS_MODE;
293
+ }
275
294
  function groupFacts(group, catalog, presets) {
276
295
  const effort = group.reasoningEffort ? effortLabel(catalog, {
277
296
  provider: group.effectiveProvider,
@@ -282,7 +301,8 @@ window.__ModuleLoader__.load({
282
301
  { key: "workspace", label: "工作区", value: group.workspaceTitle, title: group.workspacePath },
283
302
  { key: "model", label: "模型", value: groupModelSummary(catalog, group) },
284
303
  { key: "effort", label: "推理等级", value: effort },
285
- { key: "preset", label: "Agent 预设", value: presetSummaryLabel(presets, group.preset) }
304
+ { key: "preset", label: "Agent 预设", value: presetSummaryLabel(presets, group.preset) },
305
+ { key: "permission", label: "工作区权限", value: permissionLabel(group.permission) }
286
306
  ];
287
307
  }
288
308
  function scopeSummary(stored, total) {
@@ -337,6 +357,9 @@ window.__ModuleLoader__.load({
337
357
  function setMemberModel(key, sessionId, selection) {
338
358
  return { op: "member.model", key, sessionId, selection };
339
359
  }
360
+ function setMemberPermission(key, sessionId, permission) {
361
+ return { op: "member.permission", key, sessionId, permission };
362
+ }
340
363
  function archiveMember(key) {
341
364
  return { op: "member.archive", key };
342
365
  }
@@ -627,6 +650,81 @@ window.__ModuleLoader__.load({
627
650
  function Dialog({ open, onClose, title, children, footer }) {
628
651
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.Modal, { open, onClose, title, closeLabel: "关闭", className: "wcb-dialog", footer, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "wcb-dialog-body", children }) });
629
652
  }
653
+ function RiskDialog({ open, scope, busy, onCancel, onConfirm }) {
654
+ const [acknowledged, setAcknowledged] = (0, import_react2.useState)(false);
655
+ (0, import_react2.useEffect)(() => {
656
+ if (!open) setAcknowledged(false);
657
+ }, [open]);
658
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
659
+ Dialog,
660
+ {
661
+ open,
662
+ onClose: onCancel,
663
+ title: "确认启用完全权限?",
664
+ footer: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
665
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.Button, { variant: "outline", size: "sm", disabled: busy, onClick: onCancel, children: "取消" }),
666
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives.Button, { variant: "primary", size: "sm", className: "wcb-danger-solid", disabled: busy || !acknowledged, onClick: onConfirm, children: "启用完全权限" })
667
+ ] }),
668
+ children: [
669
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Notice, { tone: "warning", children: [
670
+ "启用完全权限后,",
671
+ scope,
672
+ "将减少确认步骤,并且可以直接执行更多操作,包括敏感操作、文件修改或外部命令。企业微信里的消息也会以这个权限运行。仅建议在你信任这些任务时使用。"
673
+ ] }),
674
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "wcb-check", children: [
675
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "checkbox", checked: acknowledged, disabled: busy, onChange: (event) => setAcknowledged(event.target.checked) }),
676
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "我已了解风险,并愿意继续" })
677
+ ] })
678
+ ]
679
+ }
680
+ );
681
+ }
682
+ function PermissionSelect({ value, catalog, scope, disabled, compact, label, title, onChange, onAskRisk }) {
683
+ const [asking, setAsking] = (0, import_react2.useState)();
684
+ const modes = catalog?.modes ?? [];
685
+ const known = value !== void 0 && modes.includes(value);
686
+ const choose = (next) => {
687
+ const mode = modes.find((item) => item === next);
688
+ if (!mode || mode === value) return;
689
+ if (!needsRiskAcknowledgement(mode)) onChange(mode);
690
+ else if (onAskRisk) onAskRisk(mode);
691
+ else setAsking(mode);
692
+ };
693
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
694
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
695
+ Select,
696
+ {
697
+ compact,
698
+ value: value ?? "",
699
+ disabled: disabled || !catalog?.available || !modes.length,
700
+ "aria-label": label,
701
+ title: catalog && !catalog.available ? "当前 DSH 没有权限模式服务,无法设置" : title,
702
+ onChange: (event) => choose(event.target.value),
703
+ children: [
704
+ !value && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", disabled: true, children: "未知" }),
705
+ value && !known && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value, disabled: true, children: [
706
+ permissionLabel(value),
707
+ "(当前)"
708
+ ] }),
709
+ modes.map((mode) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: mode, children: permissionLabel(mode) }, mode))
710
+ ]
711
+ }
712
+ ),
713
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
714
+ RiskDialog,
715
+ {
716
+ open: asking === FULL_ACCESS_MODE,
717
+ scope,
718
+ onCancel: () => setAsking(void 0),
719
+ onConfirm: () => {
720
+ const mode = asking;
721
+ setAsking(void 0);
722
+ if (mode) onChange(mode);
723
+ }
724
+ }
725
+ )
726
+ ] });
727
+ }
630
728
  function FactRow({ label, mono, children }) {
631
729
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
632
730
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: label }),
@@ -689,6 +787,7 @@ window.__ModuleLoader__.load({
689
787
  running,
690
788
  blank,
691
789
  preset,
790
+ permission,
692
791
  context,
693
792
  disabled,
694
793
  error,
@@ -696,12 +795,31 @@ window.__ModuleLoader__.load({
696
795
  onArchive
697
796
  }) {
698
797
  const [confirming, setConfirming] = (0, import_react2.useState)(false);
798
+ const [risk, setRisk] = (0, import_react2.useState)();
699
799
  (0, import_react2.useEffect)(() => {
700
- if (!open) setConfirming(false);
800
+ if (!open) {
801
+ setConfirming(false);
802
+ setRisk(void 0);
803
+ }
701
804
  }, [open]);
702
805
  const archive = async () => {
703
806
  if (await onArchive()) setConfirming(false);
704
807
  };
808
+ if (risk) {
809
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
810
+ RiskDialog,
811
+ {
812
+ open,
813
+ scope: "这个会话",
814
+ busy: disabled,
815
+ onCancel: () => setRisk(void 0),
816
+ onConfirm: () => {
817
+ permission.onChange(risk);
818
+ setRisk(void 0);
819
+ }
820
+ }
821
+ );
822
+ }
705
823
  if (confirming) {
706
824
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
707
825
  Dialog,
@@ -755,6 +873,18 @@ window.__ModuleLoader__.load({
755
873
  blank ? "待使用(还没有开始)" : running ? "运行中" : "空闲"
756
874
  ] }),
757
875
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FactRow, { label: "Agent 预设", children: preset }),
876
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FactRow, { label: "工作区权限", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
877
+ PermissionSelect,
878
+ {
879
+ value: permission.value,
880
+ catalog: permission.catalog,
881
+ scope: "这个会话",
882
+ disabled,
883
+ label: permission.label,
884
+ onChange: permission.onChange,
885
+ onAskRisk: setRisk
886
+ }
887
+ ) }),
758
888
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FactRow, { label: "上下文", children: contextLabel(context) || "—" }),
759
889
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(FactRow, { label: "会话 ID", mono: true, children: [
760
890
  id,
@@ -1320,7 +1450,7 @@ window.__ModuleLoader__.load({
1320
1450
  var import_react6 = require("react");
1321
1451
  var import_dsh_client_ui_primitives5 = require("@deepseek-ai/dsh-client-ui-primitives");
1322
1452
  var import_jsx_runtime6 = require("react/jsx-runtime");
1323
- var COLUMNS = ["成员", "会话", "模型", "推理等级", "上下文"];
1453
+ var COLUMNS = ["成员", "会话", "模型", "推理等级", "工作区权限", "上下文"];
1324
1454
  function MembersTable({ group, groups, state, disabled, onChanged, onOpenSession }) {
1325
1455
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "wcb-table-scroll", tabIndex: 0, role: "region", "aria-label": `${group.name} 成员表格,可横向滚动`, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("table", { className: "wcb-table", "aria-label": `${group.name} 的成员`, children: [
1326
1456
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("colgroup", { children: [
@@ -1328,6 +1458,7 @@ window.__ModuleLoader__.load({
1328
1458
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { className: "wcb-col-session" }),
1329
1459
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { className: "wcb-col-model" }),
1330
1460
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { className: "wcb-col-effort" }),
1461
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { className: "wcb-col-access" }),
1331
1462
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("col", { className: "wcb-col-context" })
1332
1463
  ] }),
1333
1464
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tr", { children: COLUMNS.map((label) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("th", { scope: "col", children: label }, label)) }) }),
@@ -1354,7 +1485,7 @@ window.__ModuleLoader__.load({
1354
1485
  const write = useStoreApply(onChanged);
1355
1486
  const blocked = disabled || Boolean(write.busy);
1356
1487
  const catalog = state?.models;
1357
- const selection = member.sessionSelection ?? member.sessionModel;
1488
+ const selection = member.sessionModel ?? member.sessionSelection;
1358
1489
  const efforts = effortsFor(catalog, selection?.provider ?? "", selection?.model ?? "");
1359
1490
  const usable = Boolean(member.sessionId) && (member.sessionState === "bound" || member.sessionState === "blank");
1360
1491
  const name = member.displayName;
@@ -1393,6 +1524,10 @@ window.__ModuleLoader__.load({
1393
1524
  if (next.provider === selection?.provider && next.model === selection?.model) return;
1394
1525
  await apply2([setMemberModel(member.key, member.sessionId, next)]);
1395
1526
  };
1527
+ const changePermission = async (mode) => {
1528
+ if (!usable) return;
1529
+ await apply2([setMemberPermission(member.key, member.sessionId, mode)]);
1530
+ };
1396
1531
  const changeEffort = async (value) => {
1397
1532
  if (!usable || !selection || value && !efforts.some((item) => item.id === value)) return;
1398
1533
  if (value === (selection.reasoningEffort ?? "")) return;
@@ -1478,6 +1613,14 @@ window.__ModuleLoader__.load({
1478
1613
  running: member.sessionRunning,
1479
1614
  blank: member.sessionState === "blank",
1480
1615
  preset: member.sessionPreset ? presetLabel(state?.presets, member.sessionPreset) : "—",
1616
+ permission: {
1617
+ value: member.sessionPermission,
1618
+ catalog: state?.permissions,
1619
+ label: `${member.id} 的会话工作区权限`,
1620
+ onChange: (mode) => {
1621
+ void changePermission(mode);
1622
+ }
1623
+ },
1481
1624
  context: member.sessionContext,
1482
1625
  disabled: Boolean(write.busy),
1483
1626
  error,
@@ -1542,6 +1685,21 @@ window.__ModuleLoader__.load({
1542
1685
  ]
1543
1686
  }
1544
1687
  ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "wcb-muted", children: "—" }) }),
1688
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("td", { children: usable ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1689
+ PermissionSelect,
1690
+ {
1691
+ compact: true,
1692
+ value: member.sessionPermission,
1693
+ catalog: state?.permissions,
1694
+ scope: `${name} 的这个会话`,
1695
+ disabled: blocked,
1696
+ label: `${member.id} 当前会话的工作区权限`,
1697
+ title: "只修改当前会话;新会话仍使用分组的工作区权限",
1698
+ onChange: (mode) => {
1699
+ void changePermission(mode);
1700
+ }
1701
+ }
1702
+ ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "wcb-muted", children: "—" }) }),
1545
1703
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ContextMeter, { context: member.sessionContext }) })
1546
1704
  ] }),
1547
1705
  error && !details && !sessionOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tr", { className: "wcb-member-error", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("td", { colSpan: COLUMNS.length, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "wcb-error", role: "alert", children: error }) }) })
@@ -1590,7 +1748,7 @@ window.__ModuleLoader__.load({
1590
1748
  id: "groups",
1591
1749
  title: "用户分组",
1592
1750
  count: view ? `${view.groups.length} 个分组 · ${view.total} 位成员` : void 0,
1593
- description: "分组决定成员使用的工作区、模型与 Agent 预设;每位成员(单聊的人或一个群聊)各有自己的会话。",
1751
+ description: "分组决定成员使用的工作区、模型、Agent 预设与工作区权限;每位成员(单聊的人或一个群聊)各有自己的会话。",
1594
1752
  actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
1595
1753
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives6.Button, { variant: "ghost", size: "sm", icon: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IconRefresh, { size: 14 }), disabled: refreshing, title: "重新读取会话状态", onClick: onRefresh, children: refreshing ? "刷新中" : "刷新" }),
1596
1754
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives6.Button, { variant: "outline", size: "sm", icon: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(IconPlus, { size: 14 }), disabled: disabled || busy === "group:new", onClick: () => {
@@ -1625,7 +1783,8 @@ window.__ModuleLoader__.load({
1625
1783
  provider: group.provider,
1626
1784
  model: group.model,
1627
1785
  effort: group.reasoningEffort ?? "",
1628
- preset: group.preset
1786
+ preset: group.preset,
1787
+ permission: group.permission
1629
1788
  };
1630
1789
  }
1631
1790
  function patchOf(group, draft) {
@@ -1641,6 +1800,7 @@ window.__ModuleLoader__.load({
1641
1800
  patch.reasoningEffort = draft.effort;
1642
1801
  }
1643
1802
  if (draft.preset !== group.preset) patch.preset = draft.preset;
1803
+ if (draft.permission !== group.permission) patch.permission = draft.permission;
1644
1804
  return patch;
1645
1805
  }
1646
1806
  function GroupCard({ group, state, startEditing, startOpen, disabled, onApply, onChanged, onOpenSession }) {
@@ -1781,6 +1941,24 @@ window.__ModuleLoader__.load({
1781
1941
  }
1782
1942
  )
1783
1943
  }
1944
+ ),
1945
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1946
+ Field,
1947
+ {
1948
+ label: "工作区权限",
1949
+ hint: draft.permission !== group.permission ? `保存后立即应用到本组已有的会话,包括单独改过权限的成员;新会话也按此创建。${PERMISSION_HINT[draft.permission]}` : PERMISSION_HINT[group.permission],
1950
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1951
+ PermissionSelect,
1952
+ {
1953
+ value: draft.permission,
1954
+ catalog: state?.permissions,
1955
+ scope: "本组的所有会话",
1956
+ disabled,
1957
+ label: `${group.name} 的工作区权限`,
1958
+ onChange: (permission) => update({ permission })
1959
+ }
1960
+ )
1961
+ }
1784
1962
  )
1785
1963
  ] }),
1786
1964
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(FormFooter, { start: !group.isDefault && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -2124,7 +2302,7 @@ window.__ModuleLoader__.load({
2124
2302
  /* Members: a semantic table, left-aligned like every DSH list. */
2125
2303
  .wcb-table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
2126
2304
  .wcb-table-scroll:focus-visible { outline: var(--wcb-focus-width) solid var(--wcb-focus); outline-offset: -2px; }
2127
- .wcb-table { width: 100%; min-width: 660px; border-collapse: collapse; table-layout: fixed; }
2305
+ .wcb-table { width: 100%; min-width: 790px; border-collapse: collapse; table-layout: fixed; }
2128
2306
  .wcb-table th, .wcb-table td { padding: 8px 12px 8px 0; text-align: left; vertical-align: middle; white-space: nowrap; }
2129
2307
  .wcb-table th:last-child, .wcb-table td:last-child { padding-right: 0; }
2130
2308
  .wcb-table th { border-top: .5px solid var(--wcb-line); color: var(--wcb-text-3); font-size: 12px; font-weight: 400; line-height: 18px; }
@@ -2132,6 +2310,7 @@ window.__ModuleLoader__.load({
2132
2310
  .wcb-col-session { width: 108px; }
2133
2311
  .wcb-col-model { width: 200px; }
2134
2312
  .wcb-col-effort { width: 108px; }
2313
+ .wcb-col-access { width: 128px; }
2135
2314
  .wcb-col-context { width: 140px; }
2136
2315
  .wcb-member-error td { white-space: normal; }
2137
2316
 
@@ -2244,6 +2423,8 @@ window.__ModuleLoader__.load({
2244
2423
  .wcb-facts dt { flex: none; color: var(--wcb-text-2); }
2245
2424
  .wcb-facts dd { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; margin: 0; text-align: end; overflow-wrap: anywhere; }
2246
2425
  .wcb-facts dd .wcb-input, .wcb-facts dd .wcb-select { width: 220px; max-width: 100%; }
2426
+ .wcb-check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
2427
+ .wcb-check input { flex: none; width: 14px; height: 14px; margin: 3px 0 0; accent-color: var(--wcb-focus); cursor: pointer; }
2247
2428
  .wcb-confirm-text { margin: 0; color: var(--wcb-text-2); }
2248
2429
  .wcb-footer-start { margin-right: auto; }
2249
2430
  span.wcb-footer-start { display: inline-flex; align-items: center; gap: 8px; }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Button keys and `task_id` plumbing for approval cards.
3
+ *
4
+ * A tool approval used to be answered by typing `/approve <nonce>` back into
5
+ * the chat. On a phone that means copying a code out of a message first, so the
6
+ * same request now also travels as a `button_interaction` card: the nonce rides
7
+ * inside the card's `task_id`, and the two buttons carry the verdict. The text
8
+ * form stays available — the card is a convenience, never the only way in.
9
+ */
10
+ /** Button the administrator taps to allow the call once. */
11
+ export const APPROVE_BUTTON = 'approve';
12
+ /** Button the administrator taps to reject the call. */
13
+ export const DENY_BUTTON = 'deny';
14
+ /** The only button left on a settled card: nothing happens when tapped. */
15
+ export const SETTLED_BUTTON = 'settled';
16
+ const TASK_PREFIX = 'apv_';
17
+ /** WeCom echoes `task_id` on every click, so the nonce travels with the card. */
18
+ export function approvalTaskId(nonce) {
19
+ return `${TASK_PREFIX}${nonce}`;
20
+ }
21
+ /**
22
+ * Read a `template_card_event` frame.
23
+ *
24
+ * The payload nests button data differently per card type, and a frame can
25
+ * arrive for a card another integration sent, so nothing here trusts a field to
26
+ * exist: an unknown button or a `task_id` without our prefix yields no action
27
+ * and no nonce, which the caller treats as ignorable.
28
+ */
29
+ export function parseCardEvent(frame) {
30
+ const body = (frame?.body ?? {});
31
+ const event = body.event ?? {};
32
+ const card = event.template_card_event ?? {};
33
+ const key = card.event_key ?? event.event_key;
34
+ const taskId = card.task_id ?? event.task_id;
35
+ const userId = typeof body.from?.userid === 'string' ? body.from.userid : typeof body.userid === 'string' ? body.userid : '';
36
+ const chatId = typeof body.chatid === 'string' ? body.chatid : userId;
37
+ const action = key === APPROVE_BUTTON ? 'approve' : key === DENY_BUTTON ? 'deny' : undefined;
38
+ const id = typeof taskId === 'string' ? taskId : '';
39
+ const nonce = id.startsWith(TASK_PREFIX) ? id.slice(TASK_PREFIX.length) : '';
40
+ return { ...(action ? { action } : {}), nonce, taskId: id, userId, chatId };
41
+ }
42
+ //# sourceMappingURL=cards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cards.js","sourceRoot":"","sources":["../../../src/host/bridge/cards.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AACxC,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAClC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC,MAAM,WAAW,GAAG,MAAM,CAAC;AAE3B,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO,GAAG,WAAW,GAAG,KAAK,EAAE,CAAC;AAClC,CAAC;AAaD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,IAAI,EAAE,CAK9B,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC;IAC7C,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7H,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACtE,MAAM,MAAM,GAAG,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7F,MAAM,EAAE,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,MAAM,KAAK,GAAG,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7E,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC9E,CAAC"}
@@ -9,6 +9,8 @@ import { parseCommand, runCommand } from './commands.js';
9
9
  import { createSessionDirectory } from './directory.js';
10
10
  import { byteLength, limitBytes, MAX_INBOUND_BYTES, MAX_REPLY_BYTES, extractSessionPointer } from './format.js';
11
11
  import { createReplayGuard, parseInbound } from './inbound.js';
12
+ import { approvalCard, approvalSettledCards } from './notices.js';
13
+ import { parseCardEvent } from './cards.js';
12
14
  import { createInteractionRegistry } from './interactions.js';
13
15
  import { adminUnassignedText, approvalNotice, code, promptFailedNotice, questionNotice, reviewNotice, routingChangedText, sessionErrorNotice, sessionLabel, title, turnCompleteNotice, unauthorizedText, } from './notices.js';
14
16
  import { ackSummary, createOutbox } from './outbox.js';
@@ -128,9 +130,9 @@ export function createBridge(deps) {
128
130
  }
129
131
  return unique;
130
132
  }
131
- function notify(chats, text, kind, sessionId, interactionNonce) {
133
+ function notify(chats, text, kind, sessionId, interactionNonce, card) {
132
134
  for (const chat of chats)
133
- outbox.enqueue({ chat, text, kind, ...(sessionId ? { sessionId } : {}), ...(interactionNonce ? { interactionNonce } : {}) });
135
+ outbox.enqueue({ chat, text, kind, ...(sessionId ? { sessionId } : {}), ...(interactionNonce ? { interactionNonce } : {}), ...(card ? { card } : {}) });
134
136
  }
135
137
  async function reply(message, round, text) {
136
138
  if (closed)
@@ -447,6 +449,77 @@ export function createBridge(deps) {
447
449
  journal.write({ event: 'dsh.question.result', sessionId, nonce: wait.nonce, outcome: answer ? 'answered' : 'fallback', ...(answer ? { answer } : {}) });
448
450
  return answer ?? next();
449
451
  }
452
+ /**
453
+ * An approval answered with a card button instead of a typed code.
454
+ *
455
+ * The nonce rides in the card's `task_id`, so the same registry lookup and
456
+ * the same administrator/private-chat checks as `/approve` apply. WeCom has
457
+ * no disabled button: replacing the card with one that has none is what stops
458
+ * a second tap, so the replacement must land inside the five seconds WeCom
459
+ * allows — and the verdict is still spoken in text if that fails.
460
+ */
461
+ async function onCardEvent(frame) {
462
+ const event = parseCardEvent(frame);
463
+ const meta = { source: 'card', userId: event.userId, chatId: event.chatId, nonce: event.nonce, action: event.action ?? 'unknown' };
464
+ if (!event.action || !event.nonce) {
465
+ journal.write({ event: 'wecom.card.ignored', level: 'debug', ...meta, reason: 'unknown-button-or-task' });
466
+ return;
467
+ }
468
+ const state = interactions.findApproval(event.nonce);
469
+ const admin = settings.adminUserIds.includes(event.userId);
470
+ // A card is replaced for every recipient of that chat, so a tap by anybody
471
+ // else must not touch it: rewriting the card would wipe live buttons the
472
+ // administrator still needs.
473
+ //
474
+ // A request that is already closed (answered on the DSH page, by text, or
475
+ // timed out) has no pending state left, but its card is still live on the
476
+ // phone. An administrator tapping it deserves a dead card, not silence.
477
+ const stale = !state && admin && interactions.wasClosed(event.nonce);
478
+ if (!stale && (!state || !admin || !state.privateChats.has(event.chatId))) {
479
+ journal.write({ event: 'wecom.card.rejected', ...meta, admin, reason: 'not-the-asking-administrator' });
480
+ return;
481
+ }
482
+ // Another tap is already submitting: it will settle the card itself, and a
483
+ // second replacement would overwrite its verdict with “expired”.
484
+ if (state && !state.active()) {
485
+ journal.write({ event: 'wecom.card.ignored', level: 'debug', ...meta, reason: 'already-submitting' });
486
+ return;
487
+ }
488
+ let outcome = 'ignored';
489
+ if (state?.active() && !closed) {
490
+ const permitted = await directory.permitted(state.sessionId);
491
+ if (permitted && !state.active() && !closed) {
492
+ // Lost the race while checking scope: whoever won settles the card.
493
+ journal.write({ event: 'wecom.card.ignored', level: 'debug', ...meta, reason: 'already-submitting' });
494
+ return;
495
+ }
496
+ if (permitted && state.active() && !closed) {
497
+ const verdict = event.action === 'approve' ? 'allowed-once' : 'rejected';
498
+ const submission = await state.submit(verdict);
499
+ outcome = submission === 'closed' ? 'ignored' : verdict;
500
+ }
501
+ }
502
+ journal.write({ event: 'dsh.approval.answer', ...meta, sessionId: state?.sessionId, toolName: state?.toolName, outcome, admin });
503
+ const candidates = approvalSettledCards(outcome, state?.toolName, event.taskId);
504
+ for (const [index, card] of candidates.entries()) {
505
+ try {
506
+ await client.updateTemplateCard(frame, card);
507
+ journal.write({ event: 'wecom.card.updated', ...meta, index, cardType: card.card_type });
508
+ return;
509
+ }
510
+ catch (error) {
511
+ journal.write({ event: 'wecom.card.update.failed', level: 'warn', ...meta, index, cardType: card.card_type, error });
512
+ }
513
+ }
514
+ const settled = candidates[0];
515
+ try {
516
+ await client.sendMessage(event.chatId, { msgtype: 'markdown', markdown: { content: `${settled.main_title?.title ?? ''} · ${settled.main_title?.desc ?? ''}` } });
517
+ journal.write({ event: 'wecom.card.text-fallback', ...meta });
518
+ }
519
+ catch (error) {
520
+ journal.write({ event: 'wecom.card.lost', level: 'warn', ...meta, error });
521
+ }
522
+ }
450
523
  async function onApproval(request, next, delivery) {
451
524
  const sessionId = request.agent?.id;
452
525
  if (closed || !sessionId)
@@ -478,7 +551,7 @@ export function createBridge(deps) {
478
551
  return next();
479
552
  }
480
553
  journal.write({ event: 'dsh.approval', ...meta, remote: true, nonce: wait.nonce, chats: admins, timeoutMs: settings.questionTimeoutMs });
481
- notify(admins, approvalNotice(sessionId, info.title, request, wait.nonce, settings.questionTimeoutMs), 'approval-request', sessionId, wait.nonce);
554
+ notify(admins, approvalNotice(sessionId, info.title, request, wait.nonce, settings.questionTimeoutMs), 'approval-request', sessionId, wait.nonce, approvalCard(info.title, request, wait.nonce, settings.questionTimeoutMs));
482
555
  const outcome = await wait.result;
483
556
  journal.write({ event: 'dsh.approval.result', ...meta, nonce: wait.nonce, outcome: outcome ?? 'fallback' });
484
557
  return outcome ?? next();
@@ -516,6 +589,12 @@ export function createBridge(deps) {
516
589
  status.set('displaced', '同一个 Bot 在别处建立了新连接,本连接已被断开');
517
590
  });
518
591
  client.on('event', (frame) => journal.write({ event: 'wecom.event', level: 'debug', frame }));
592
+ client.on('event.template_card_event', (frame) => {
593
+ void onCardEvent(frame).catch(error => {
594
+ log.warn('WeCom card event failed (details in the plugin journal)');
595
+ journal.write({ event: 'bridge.error', level: 'error', stage: 'card', error });
596
+ });
597
+ });
519
598
  client.on('message', (frame) => {
520
599
  void handleFrame(frame).catch(error => {
521
600
  log.error('WeCom callback failed (details in the plugin journal)');