@michengai/dsh-im-connect 0.1.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.
Files changed (162) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +39 -0
  3. package/client.js +1479 -0
  4. package/cordis.patch.yml +4 -0
  5. package/lib/channels/dingtalk-card.d.ts +24 -0
  6. package/lib/channels/dingtalk-card.d.ts.map +1 -0
  7. package/lib/channels/dingtalk-card.js +182 -0
  8. package/lib/channels/dingtalk-card.js.map +1 -0
  9. package/lib/channels/dingtalk.d.ts +7 -0
  10. package/lib/channels/dingtalk.d.ts.map +1 -0
  11. package/lib/channels/dingtalk.js +107 -0
  12. package/lib/channels/dingtalk.js.map +1 -0
  13. package/lib/channels/factory.d.ts +4 -0
  14. package/lib/channels/factory.d.ts.map +1 -0
  15. package/lib/channels/factory.js +24 -0
  16. package/lib/channels/factory.js.map +1 -0
  17. package/lib/channels/feishu.d.ts +8 -0
  18. package/lib/channels/feishu.d.ts.map +1 -0
  19. package/lib/channels/feishu.js +73 -0
  20. package/lib/channels/feishu.js.map +1 -0
  21. package/lib/channels/meta.d.ts +20 -0
  22. package/lib/channels/meta.d.ts.map +1 -0
  23. package/lib/channels/meta.js +69 -0
  24. package/lib/channels/meta.js.map +1 -0
  25. package/lib/channels/qr/dingtalk.d.ts +12 -0
  26. package/lib/channels/qr/dingtalk.d.ts.map +1 -0
  27. package/lib/channels/qr/dingtalk.js +69 -0
  28. package/lib/channels/qr/dingtalk.js.map +1 -0
  29. package/lib/channels/qr/feishu.d.ts +14 -0
  30. package/lib/channels/qr/feishu.d.ts.map +1 -0
  31. package/lib/channels/qr/feishu.js +87 -0
  32. package/lib/channels/qr/feishu.js.map +1 -0
  33. package/lib/channels/qr/hub.d.ts +22 -0
  34. package/lib/channels/qr/hub.d.ts.map +1 -0
  35. package/lib/channels/qr/hub.js +193 -0
  36. package/lib/channels/qr/hub.js.map +1 -0
  37. package/lib/channels/qr/render.d.ts +3 -0
  38. package/lib/channels/qr/render.d.ts.map +1 -0
  39. package/lib/channels/qr/render.js +9 -0
  40. package/lib/channels/qr/render.js.map +1 -0
  41. package/lib/channels/qr/shared.d.ts +39 -0
  42. package/lib/channels/qr/shared.d.ts.map +1 -0
  43. package/lib/channels/qr/shared.js +51 -0
  44. package/lib/channels/qr/shared.js.map +1 -0
  45. package/lib/channels/qr/wecom.d.ts +10 -0
  46. package/lib/channels/qr/wecom.d.ts.map +1 -0
  47. package/lib/channels/qr/wecom.js +81 -0
  48. package/lib/channels/qr/wecom.js.map +1 -0
  49. package/lib/channels/qr/weixin.d.ts +10 -0
  50. package/lib/channels/qr/weixin.d.ts.map +1 -0
  51. package/lib/channels/qr/weixin.js +77 -0
  52. package/lib/channels/qr/weixin.js.map +1 -0
  53. package/lib/channels/telegram.d.ts +7 -0
  54. package/lib/channels/telegram.d.ts.map +1 -0
  55. package/lib/channels/telegram.js +133 -0
  56. package/lib/channels/telegram.js.map +1 -0
  57. package/lib/channels/wecom.d.ts +28 -0
  58. package/lib/channels/wecom.d.ts.map +1 -0
  59. package/lib/channels/wecom.js +168 -0
  60. package/lib/channels/wecom.js.map +1 -0
  61. package/lib/channels/weixin.d.ts +41 -0
  62. package/lib/channels/weixin.d.ts.map +1 -0
  63. package/lib/channels/weixin.js +678 -0
  64. package/lib/channels/weixin.js.map +1 -0
  65. package/lib/client.js +1479 -0
  66. package/lib/engine/access.d.ts +11 -0
  67. package/lib/engine/access.d.ts.map +1 -0
  68. package/lib/engine/access.js +11 -0
  69. package/lib/engine/access.js.map +1 -0
  70. package/lib/engine/agent-options.d.ts +25 -0
  71. package/lib/engine/agent-options.d.ts.map +1 -0
  72. package/lib/engine/agent-options.js +19 -0
  73. package/lib/engine/agent-options.js.map +1 -0
  74. package/lib/engine/approval.d.ts +9 -0
  75. package/lib/engine/approval.d.ts.map +1 -0
  76. package/lib/engine/approval.js +38 -0
  77. package/lib/engine/approval.js.map +1 -0
  78. package/lib/engine/assistant-settings.d.ts +17 -0
  79. package/lib/engine/assistant-settings.d.ts.map +1 -0
  80. package/lib/engine/assistant-settings.js +35 -0
  81. package/lib/engine/assistant-settings.js.map +1 -0
  82. package/lib/engine/credentials.d.ts +17 -0
  83. package/lib/engine/credentials.d.ts.map +1 -0
  84. package/lib/engine/credentials.js +51 -0
  85. package/lib/engine/credentials.js.map +1 -0
  86. package/lib/engine/gateway.d.ts +46 -0
  87. package/lib/engine/gateway.d.ts.map +1 -0
  88. package/lib/engine/gateway.js +333 -0
  89. package/lib/engine/gateway.js.map +1 -0
  90. package/lib/engine/json-state.d.ts +8 -0
  91. package/lib/engine/json-state.d.ts.map +1 -0
  92. package/lib/engine/json-state.js +24 -0
  93. package/lib/engine/json-state.js.map +1 -0
  94. package/lib/engine/merge.d.ts +21 -0
  95. package/lib/engine/merge.d.ts.map +1 -0
  96. package/lib/engine/merge.js +55 -0
  97. package/lib/engine/merge.js.map +1 -0
  98. package/lib/engine/router.d.ts +88 -0
  99. package/lib/engine/router.d.ts.map +1 -0
  100. package/lib/engine/router.js +309 -0
  101. package/lib/engine/router.js.map +1 -0
  102. package/lib/engine/seen-store.d.ts +12 -0
  103. package/lib/engine/seen-store.d.ts.map +1 -0
  104. package/lib/engine/seen-store.js +38 -0
  105. package/lib/engine/seen-store.js.map +1 -0
  106. package/lib/engine/session-id.d.ts +30 -0
  107. package/lib/engine/session-id.d.ts.map +1 -0
  108. package/lib/engine/session-id.js +53 -0
  109. package/lib/engine/session-id.js.map +1 -0
  110. package/lib/engine/session-store.d.ts +13 -0
  111. package/lib/engine/session-store.d.ts.map +1 -0
  112. package/lib/engine/session-store.js +38 -0
  113. package/lib/engine/session-store.js.map +1 -0
  114. package/lib/engine/split.d.ts +2 -0
  115. package/lib/engine/split.d.ts.map +1 -0
  116. package/lib/engine/split.js +41 -0
  117. package/lib/engine/split.js.map +1 -0
  118. package/lib/engine/types.d.ts +52 -0
  119. package/lib/engine/types.d.ts.map +1 -0
  120. package/lib/engine/types.js +2 -0
  121. package/lib/engine/types.js.map +1 -0
  122. package/lib/index.d.ts +22 -0
  123. package/lib/index.d.ts.map +1 -0
  124. package/lib/index.js +53 -0
  125. package/lib/index.js.map +1 -0
  126. package/lib/manager.d.ts +103 -0
  127. package/lib/manager.d.ts.map +1 -0
  128. package/lib/manager.js +543 -0
  129. package/lib/manager.js.map +1 -0
  130. package/package.json +63 -0
  131. package/src/channels/dingtalk-card.ts +191 -0
  132. package/src/channels/dingtalk.ts +113 -0
  133. package/src/channels/factory.ts +32 -0
  134. package/src/channels/feishu.ts +77 -0
  135. package/src/channels/meta.ts +89 -0
  136. package/src/channels/qr/dingtalk.ts +71 -0
  137. package/src/channels/qr/feishu.ts +90 -0
  138. package/src/channels/qr/hub.ts +206 -0
  139. package/src/channels/qr/render.ts +7 -0
  140. package/src/channels/qr/shared.ts +80 -0
  141. package/src/channels/qr/wecom.ts +78 -0
  142. package/src/channels/qr/weixin.ts +78 -0
  143. package/src/channels/telegram.ts +145 -0
  144. package/src/channels/wecom.ts +182 -0
  145. package/src/channels/weixin.ts +712 -0
  146. package/src/engine/access.ts +17 -0
  147. package/src/engine/agent-options.ts +24 -0
  148. package/src/engine/approval.ts +45 -0
  149. package/src/engine/assistant-settings.ts +41 -0
  150. package/src/engine/credentials.ts +64 -0
  151. package/src/engine/gateway.ts +330 -0
  152. package/src/engine/json-state.ts +20 -0
  153. package/src/engine/merge.ts +60 -0
  154. package/src/engine/router.ts +333 -0
  155. package/src/engine/seen-store.ts +36 -0
  156. package/src/engine/session-id.ts +65 -0
  157. package/src/engine/session-store.ts +45 -0
  158. package/src/engine/split.ts +29 -0
  159. package/src/engine/types.ts +55 -0
  160. package/src/index.ts +81 -0
  161. package/src/manager.ts +571 -0
  162. package/src/optional-modules.d.ts +13 -0
package/lib/client.js ADDED
@@ -0,0 +1,1479 @@
1
+ /**
2
+ * dsh-im-connect 浏览器端:IM助理设置页 + 工作区频道槽。
3
+ */
4
+ window.__ModuleLoader__.load({
5
+ id: "dsh-im-connect",
6
+ factory: (require) => {
7
+ var module = { exports: {} };
8
+ var exports = module.exports;
9
+ const React = require("react");
10
+ const { useState, useEffect, useCallback, useRef, useSyncExternalStore } = React;
11
+ const EMPTY_EXTRA_TABS = [];
12
+ const inject = ["slots", "sessions", "workspaces"];
13
+ const API_BASE = "/dsh-im-connect/api";
14
+ const TAB_KEY = "dsh-im-connect.sidebar-tab";
15
+ const h = React.createElement;
16
+
17
+ const CSS = `
18
+ .ima-page{--ima-text:var(--dsw-alias-label-primary,var(--dsh-text,#e6edf3));--ima-muted:var(--dsw-alias-label-tertiary,var(--dsh-text-muted,#8b949e));--ima-line:var(--dsw-alias-border-l2,var(--dsh-border,rgba(255,255,255,.1)));--ima-card:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));--ima-card-hover:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));--ima-ok:var(--dsw-alias-state-success-primary,#3fb950);--ima-danger:var(--dsw-alias-state-error-primary,#f85149);--ima-accent:var(--dsw-alias-brand-primary,#4b7cff);box-sizing:border-box;max-width:760px;width:100%;margin:0 auto;padding:0 0 32px;color:var(--ima-text)}
19
+ .ima-deco{display:flex;justify-content:center;align-items:flex-end;gap:10px;min-height:56px;margin:8px 0 14px}
20
+ .ima-bubble{font-size:12px;line-height:1.4;padding:6px 10px;border-radius:12px;max-width:220px;border:1px solid var(--ima-line)}
21
+ .ima-bubble.left{background:rgba(46,160,67,.14);color:#7ee787}
22
+ .ima-bubble.right{background:rgba(255,255,255,.05);color:var(--ima-muted)}
23
+ .ima-avatars{display:flex;align-items:center}
24
+ .ima-avatar{width:36px;height:36px;border-radius:50%;display:grid;place-items:center;border:2px solid #111}
25
+ .ima-avatar.bot{background:#123524;margin-right:-8px;z-index:1}
26
+ .ima-avatar.user{background:#3d3428}
27
+ .ima-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:12px}.ima-title{margin:0;font-size:20px;line-height:28px;font-weight:650;letter-spacing:-.2px;text-align:left}
28
+ .ima-sub{margin:4px 0 0;max-width:42em;color:var(--ima-muted);font-size:13px;line-height:1.5;text-align:left}
29
+ .ima-composer-wrap{margin:0 0 16px}
30
+ .ima-composer{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));align-items:center;gap:4px;padding:4px 6px;border:1px solid var(--ima-line);border-radius:14px;background:var(--ima-card)}
31
+ .ima-composer-left,.ima-composer-right{display:contents}
32
+ .ima-composer .ima-chip{width:100%;min-width:0}
33
+ .ima-composer .ima-chip-btn{width:100%;justify-content:center}
34
+ .ima-chip{position:relative;min-width:0;z-index:1}
35
+ .ima-chip.is-open{z-index:30}
36
+ .ima-chip-btn{display:inline-flex;align-items:center;gap:6px;min-height:28px;height:28px;padding:0 8px;border:0;border-radius:8px;background:transparent;color:var(--ima-muted);font-size:13px;font-weight:500;white-space:nowrap;cursor:pointer}
37
+ .ima-chip-btn:hover,.ima-chip.is-open .ima-chip-btn{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08));color:var(--ima-text)}
38
+ .ima-chip-label{min-width:0;overflow:hidden;text-overflow:ellipsis}
39
+ .ima-chip-btn em{width:6px;height:6px;margin-left:2px;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:rotate(45deg) translateY(-2px);opacity:.55;flex:none}
40
+ .ima-chip-menu{position:absolute;top:calc(100% + 6px);left:0;z-index:30;min-width:260px;max-height:280px;overflow:auto;padding:6px;border:1px solid var(--ima-line);border-radius:14px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2,#fff));box-shadow:var(--dsw-shadow-lv3,0 16px 40px rgba(0,0,0,.18))}
41
+ .ima-chip-menu.is-end{left:auto;right:0}
42
+ .ima-chip-row{display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;padding:8px 10px;border:0;border-radius:10px;background:transparent;color:inherit;text-align:left;cursor:pointer;font-size:13px}
43
+ .ima-chip-row:hover,.ima-chip-row.is-on{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
44
+ .ima-chip-row-main{display:inline-flex;align-items:center;gap:8px;min-width:0}
45
+ .ima-chip-tick{width:6px;height:12px;border-right:1.6px solid var(--ima-accent);border-bottom:1.6px solid var(--ima-accent);transform:rotate(45deg) translateY(-2px);flex:none}
46
+ .ima-chip-empty{padding:14px 12px;color:var(--ima-muted);font-size:12px;text-align:center}
47
+ .ima-composer-hint{margin-top:8px;color:var(--ima-muted);font-size:12px;text-align:center}
48
+ .ima-chip svg{flex:none}
49
+ .ima-chip-row.is-kv .ima-chip-row-main{flex:none}
50
+ .ima-chip-row-side{display:inline-flex;align-items:center;gap:8px;color:var(--ima-muted);font-size:12px;min-width:0}
51
+ .ima-chip-next{width:7px;height:7px;border-right:1.6px solid currentColor;border-bottom:1.6px solid currentColor;transform:rotate(-45deg);opacity:.55;flex:none}
52
+ .ima-chip-split{height:1px;margin:6px 8px;background:var(--ima-line)}
53
+ .ima-chip-effort{color:var(--ima-muted);font-weight:500}
54
+ .ima-chip-dialog{margin-top:10px;padding:12px;border:1px solid var(--ima-line);border-radius:12px;background:var(--dsw-alias-bg-layer-3,transparent)}
55
+ .ima-chip-dialog strong{display:block;margin:0 0 8px;font-size:13px}
56
+ .ima-chip-dialog input{width:100%;min-height:36px;padding:8px 10px;border-radius:8px;border:1px solid var(--ima-line);background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-button-elevated-fill,transparent));color:var(--ima-text);box-sizing:border-box}
57
+ .ima-chip-dialog-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:10px}
58
+
59
+ .ima-list{display:flex;flex-direction:column;gap:10px}
60
+ .ima-card{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:12px;min-height:52px;padding:13px 16px;border:1px solid var(--ima-line);border-radius:12px;background:var(--ima-card)}
61
+ .ima-card:hover{background:var(--ima-card-hover)}
62
+ .ima-card-main{min-width:0}
63
+ .ima-name-row{display:flex;align-items:center;gap:10px;min-height:28px}
64
+ .ima-status{margin-left:auto;color:var(--ima-muted);font-size:12px;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:42%}
65
+ .ima-name{font-size:15px;font-weight:650}
66
+ .ima-badge{font-size:11px;line-height:18px;padding:0 7px;border-radius:8px;background:rgba(46,160,67,.16);color:var(--ima-ok)}
67
+ .ima-desc,.ima-meta{margin-top:3px;margin-left:38px;color:var(--ima-muted);font-size:12px;line-height:1.45;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-height:17px}
68
+ .ima-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;min-height:36px;position:relative}
69
+ .ima-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:transparent;color:var(--dsw-alias-label-primary,inherit);border-radius:8px;min-width:72px;min-height:32px;padding:0 12px;font:inherit;font-size:13px;cursor:pointer}
70
+ .ima-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
71
+ .ima-btn:focus-visible,.ima-more:focus-visible,.ima-switch:focus-visible,.ima-link:focus-visible,.ima-x:focus-visible{outline:2px solid var(--ima-accent);outline-offset:2px}
72
+ .ima-btn:disabled{opacity:.5;cursor:not-allowed}
73
+ .ima-btn.primary{background:var(--dsw-alias-button-primary-fill,var(--ima-accent));border-color:transparent;color:var(--dsw-alias-label-primary-foreground,#fff)}
74
+ .ima-more{width:32px;height:32px;border:0;border-radius:8px;background:transparent;color:var(--ima-text);cursor:pointer;font-size:18px;line-height:1}
75
+ .ima-more:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
76
+ .ima-menu{position:absolute;right:0;top:36px;min-width:128px;padding:6px;border:1px solid var(--ima-line);border-radius:10px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2,#fff));z-index:5;box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.18))}
77
+ .ima-menu button{display:block;width:100%;text-align:left;border:0;background:transparent;color:var(--ima-text);padding:8px 10px;border-radius:6px;cursor:pointer;min-height:36px}
78
+ .ima-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
79
+ .ima-switch{width:40px;height:22px;border-radius:11px;border:0;background:var(--ima-ok);position:relative;cursor:pointer;flex:none}
80
+ .ima-switch.off{background:var(--dsw-alias-label-tertiary,#8b8f98)}
81
+ .ima-switch i{position:absolute;top:2px;left:20px;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .16s ease}
82
+ .ima-switch.off i{left:2px}
83
+ .ima-error{color:var(--ima-danger);font-size:12px;margin:0 0 12px}
84
+ .ima-pending{margin:0 0 14px;padding:10px 12px;border:1px solid rgba(210,153,34,.35);border-radius:12px}
85
+ .ima-pending-row{display:flex;gap:8px;align-items:center;margin-top:8px}
86
+ .ima-wrap{display:flex;flex-direction:column;min-height:0;flex:1;height:100%;overflow:hidden}.ima-official-tree{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}.ima-native,.ima-rail.ima-native,.ima-rail.dcu-wb{box-sizing:border-box;padding-right:var(--dsh-sidebar-inline-padding,12px)}
87
+ .ima-tabs{display:flex;gap:18px;padding:4px 12px 0;border-bottom:1px solid var(--ima-line)}
88
+ .ima-tab{appearance:none;border:0;background:transparent;color:var(--ima-muted);padding:8px 0;font-size:13px;cursor:pointer}
89
+ .ima-tab.on{color:var(--ima-text);box-shadow:inset 0 -2px 0 currentColor}
90
+ .ima-tabs{flex:none}
91
+ .ima-rail{flex:1 1 auto;min-height:180px;overflow:auto}
92
+ .ima-item{display:flex;align-items:center;gap:6px;padding:0 8px 0 18px;border-radius:8px;cursor:pointer;font-size:13px;min-height:32px;position:relative}
93
+ .ima-item-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
94
+ .ima-item:hover,.ima-item.on{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
95
+ .ima-sess-actions{display:none;flex:none;align-items:center;gap:2px}
96
+ .ima-item:hover .ima-sess-actions,.ima-item.menu-on .ima-sess-actions{display:flex}
97
+ .ima-sess-btn{width:24px;height:24px;border:0;border-radius:6px;background:transparent;color:inherit;cursor:pointer;font-size:16px;line-height:1}
98
+ .ima-sess-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
99
+ .ima-sess-menu{position:absolute;right:8px;top:30px;min-width:132px;padding:6px;border:1px solid var(--ima-line);border-radius:10px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2,#fff));z-index:8;box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.18))}
100
+ .ima-sess-menu button{display:block;width:100%;text-align:left;border:0;background:transparent;color:var(--ima-text);padding:7px 10px;border-radius:6px;cursor:pointer}
101
+ .ima-sess-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.08))}
102
+ .ima-sess-menu button.danger{color:var(--ima-danger)}
103
+ .ima-rename{flex:1;min-width:0;min-height:28px;padding:2px 8px;border-radius:6px;border:1px solid var(--ima-line);background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-button-elevated-fill,transparent));color:var(--ima-text);font-size:13px}
104
+ .ima-empty{color:var(--ima-muted);font-size:12px;padding:12px 8px}
105
+ .ima-logo{width:28px;height:28px;flex:none;display:block;line-height:0;background:transparent}
106
+ .ima-logo svg{width:28px;height:28px;display:block}
107
+ .ima-logo.sm{width:16px;height:16px;overflow:visible}
108
+ .ima-logo.sm svg{width:16px;height:16px}
109
+ .ima-logo.sm[data-brand="weixin"] svg,.ima-logo.sm[data-brand="feishu"] svg,.ima-logo.sm[data-brand="lark"] svg,.ima-logo.sm[data-brand="telegram"] svg{transform:scale(1.2);transform-origin:center}
110
+ .ima-logo[data-brand="wecom"]{border-radius:6px;box-shadow:inset 0 0 0 1px rgba(15,23,42,.12);overflow:hidden;background:#fff}
111
+ .ima-logo.sm[data-brand="wecom"]{border-radius:4px}
112
+ .ima-mask{position:fixed;inset:0;background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.45));backdrop-filter:var(--dsw-mask-blur,blur(8px));display:grid;place-items:center;z-index:80;padding:24px}
113
+ .ima-modal{width:min(440px,100%);background:var(--dsw-alias-bg-layer-2,#fff);color:var(--ima-text);border:1px solid var(--ima-line);border-radius:16px;padding:20px 22px 22px;text-align:left;box-shadow:var(--dsw-shadow-lv3,0 16px 48px rgba(0,0,0,.18))}
114
+ .ima-modal-h{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
115
+ .ima-modal-h h2{margin:0;font-size:16px;font-weight:650}
116
+ .ima-x{border:0;background:transparent;font-size:20px;line-height:1;cursor:pointer;color:var(--ima-muted);width:32px;height:32px}
117
+ .ima-seg{display:flex;gap:0;border-bottom:1px solid var(--ima-line);margin:0 -22px 16px;padding:0 22px}
118
+ .ima-seg button{flex:1;border:0;background:transparent;padding:10px 0;font-size:13px;color:var(--ima-muted);cursor:pointer}
119
+ .ima-seg button.on{color:var(--ima-accent);box-shadow:inset 0 -2px 0 var(--ima-accent);font-weight:600}
120
+ .ima-qrbox{display:flex;flex-direction:column;align-items:center;gap:10px;padding:8px 0 4px}
121
+ .ima-qrbox img,.ima-qrph{width:200px;height:200px;background:#fff;border:1px solid var(--ima-line);border-radius:12px;object-fit:contain}
122
+ .ima-qrph{display:grid;place-items:center;color:var(--ima-muted);font-size:13px}
123
+ .ima-hint{margin:0;color:var(--ima-muted);font-size:13px;text-align:center;line-height:1.6}
124
+ .ima-link{border:0;background:transparent;color:var(--ima-accent);cursor:pointer;font-size:13px;min-height:32px}
125
+ .ima-field{display:flex;flex-direction:column;gap:6px;margin-bottom:12px;font-size:13px}
126
+ .ima-field input{padding:8px 10px;border-radius:8px;border:1px solid var(--ima-line);background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-button-elevated-fill,transparent));color:var(--ima-text);min-height:36px}
127
+ .ima-radio{display:flex;flex-direction:column;gap:8px;margin:8px 0 14px}
128
+ .ima-radio label{display:flex;gap:8px;align-items:flex-start;font-size:13px;color:var(--ima-text)}
129
+ .ima-radio small{display:block;color:var(--ima-muted);margin-top:2px}
130
+ .ima-ok{color:var(--ima-ok);font-size:14px;text-align:center;padding:24px 0}
131
+ .ima-modal .ima-error{color:var(--ima-danger)}
132
+ @media (prefers-reduced-motion:reduce){.ima-switch i{transition:none}}
133
+ `;
134
+
135
+ let styleEl = null;
136
+ const ensureStyle = () => {
137
+ if (styleEl && styleEl.isConnected) return;
138
+ styleEl = document.createElement("style");
139
+ styleEl.textContent = CSS;
140
+ document.head.appendChild(styleEl);
141
+ };
142
+
143
+ const api = (path, opts) => fetch(API_BASE + path, opts).then((r) => r.json());
144
+
145
+ function BrandMark({ id }) {
146
+ const svg = (viewBox, children) => h("svg", {
147
+ viewBox,
148
+ xmlns: "http://www.w3.org/2000/svg",
149
+ fill: "none",
150
+ "aria-hidden": "true",
151
+ }, children);
152
+
153
+ if (id === "dingtalk") {
154
+ return svg("0 0 48 48", [
155
+ h("rect", { key: "bg", x: 6, y: 6, width: 36, height: 36, rx: 8, fill: "#0285fc" }),
156
+ h("path", { key: "mark", d: "m20.178 37.577 3.5-6h-3l2-3c-5.5-1-6.281-3.938-6-4.5.162-.325 2.5 1 6.281 1-8.281-.5-8.281-7-7.781-7.5.423-.424 2.44 1.666 6.564 3.53-9.126-4.314-6.453-11.956-5.064-11.03 3.344 3 9.5 8.5 15 13 .658.538 1 2 0 3.25s-2.5 2.75-3 3.25h2.5z", fill: "#fff" }),
157
+ ]);
158
+ }
159
+
160
+ if (id === "feishu" || id === "lark") {
161
+ return svg("0 0 48 48", [
162
+ h("path", { key: "wing", d: "M10 8c0 1 7 3.5 14.745 16.744 0 0 4.184-4.363 6.255-5.744 1.5-1 2.712-1.332 2.712-1.332C33.712 15.156 29.5 8 28 8z", fill: "#00d6b9" }),
163
+ h("path", { key: "head", d: "M43.5 18.5c-1-.667-3.65-1.771-6.5-1.5a15 15 0 0 0-3.288.668S32.5 18 31 19c-2.07 1.38-6.255 5.744-6.255 5.744-1.428 1.397-3.05 2.732-5.245 3.756 0 0 7 3 11.5 3 5.063 0 7-3.5 7-3.5 1.5-3.305 3.5-7 5.5-9.5", fill: "#163c9a" }),
164
+ h("path", { key: "body", d: "M4 17.5v17c0 1 6 5.5 15 5.5 10 0 17.05-7.705 19-12 0 0-1.937 3.5-7 3.5-4.5 0-11.5-3-11.5-3-5.117-2.239-10.03-6.577-12.906-9.117C4.974 17.953 4 17.093 4 17.5", fill: "#3370ff" }),
165
+ ]);
166
+ }
167
+
168
+ if (id === "weixin") {
169
+ return svg("0 0 48 48", [
170
+ h("path", { key: "left", fillRule: "evenodd", clipRule: "evenodd", d: "M32.8 18.003 32.5 18C25.732 18 20 22.798 20 29c0 1.007.151 1.976.433 2.894A18 18 0 0 1 18.5 32c-1.809 0-3.54-.274-5.137-.775-.394-.123-1.828.696-3.039 1.389-.927.53-1.724.986-1.824.886-.094-.094.169-.718.476-1.448.446-1.06.986-2.346.664-2.552C6.21 27.305 4 23.866 4 20c0-6.627 6.492-12 14.5-12 7.186 0 13.151 4.326 14.3 10.003M16 16a2 2 0 1 1-4 0 2 2 0 0 1 4 0m7 2a2 2 0 1 0 0-4 2 2 0 0 0 0 4", fill: "#07C160" }),
171
+ h("path", { key: "right", fillRule: "evenodd", clipRule: "evenodd", d: "M44 29c0 3.362-1.908 6.336-4.833 8.149-.13.08.169.858.446 1.583.237.618.459 1.196.387 1.268-.075.075-.802-.327-1.571-.752-.829-.458-1.706-.942-1.871-.888-1.262.413-2.63.64-4.058.64C26.149 39 21 34.523 21 29s5.149-10 11.5-10S44 23.477 44 29m-6-3.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0M28.5 27a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3", fill: "#07C160" }),
172
+ ]);
173
+ }
174
+
175
+ if (id === "wecom") {
176
+ return svg("0 0 46 46", [
177
+ h("path", { key: "bg", d: "M39.743 0H6.257A6.257 6.257 0 0 0 0 6.257v33.487A6.257 6.257 0 0 0 6.257 46h33.487A6.257 6.257 0 0 0 46 39.743V6.257A6.257 6.257 0 0 0 39.743 0", fill: "#fff" }),
178
+ h("path", { key: "orange", d: "M28.856 31.647a.483.483 0 0 0 .06.738 6.2 6.2 0 0 1 1.911 3.725 2.02 2.02 0 1 0 2.16-2.54 6.2 6.2 0 0 1-3.448-1.922.483.483 0 0 0-.683-.001", fill: "#fb6500" }),
179
+ h("path", { key: "blueDot", d: "M37.057 28.448a2 2 0 0 0-.58 1.215 6.2 6.2 0 0 1-1.918 3.454.484.484 0 1 0 .738.616 6.2 6.2 0 0 1 3.725-1.91 2.02 2.02 0 1 0-1.96-3.376z", fill: "#0082ef" }),
180
+ h("path", { key: "green", d: "M31.366 22.75a2.02 2.02 0 0 0 1.215 3.435 6.2 6.2 0 0 1 3.454 1.918.483.483 0 0 0 .829-.27.48.48 0 0 0-.212-.468 6.2 6.2 0 0 1-1.911-3.726 2.02 2.02 0 0 0-3.375-.889", fill: "#2dbc00" }),
181
+ h("path", { key: "yellow", d: "m30.374 25.907-.037.037a6.2 6.2 0 0 1-3.78 1.978 2.007 2.007 0 0 0-.895 3.374 2.02 2.02 0 0 0 3.435-1.216 6.2 6.2 0 0 1 1.923-3.453.484.484 0 0 0-.646-.72", fill: "#fc0" }),
182
+ h("path", { key: "bubble", d: "M18.17 8.471c-3.624.4-6.908 1.948-9.266 4.367-.938.956-1.7 2.032-2.262 3.182a11.08 11.08 0 0 0 .78 11.188c.64.968 1.693 2.178 2.654 3.037l-.435 3.423-.048.145c-.012.042-.012.09-.018.133l-.012.108.012.11a1.1 1.1 0 0 0 1.657.852h.018l.067-.049 1.04-.52 3.102-1.56a16 16 0 0 0 4.537.623c1.897.004 3.78-.323 5.564-.968a2.014 2.014 0 0 1-1.373-2.11 13.7 13.7 0 0 1-5.721.568l-.309-.042a14 14 0 0 1-2.056-.43 1.4 1.4 0 0 0-1.1.116l-.085.042-2.552 1.5-.109.066c-.06.036-.09.048-.12.048a.176.176 0 0 1-.164-.181l.097-.393.115-.43.181-.707.212-.787a1.07 1.07 0 0 0-.387-1.19 11.2 11.2 0 0 1-2.577-2.686 8.73 8.73 0 0 1-.629-8.818c.46-.92 1.065-1.773 1.815-2.54 1.935-1.997 4.657-3.267 7.669-3.593a14.3 14.3 0 0 1 3.132 0c2.994.344 5.704 1.633 7.627 3.617a10 10 0 0 1 1.796 2.551 8.7 8.7 0 0 1 .901 3.84c0 .14-.012.279-.018.412a2.015 2.015 0 0 1 2.48.29l.09.109a11 11 0 0 0-1.1-5.733 12.3 12.3 0 0 0-2.238-3.182 15.18 15.18 0 0 0-9.229-4.397 17 17 0 0 0-3.739-.01", fill: "#0082ef" }),
183
+ ]);
184
+ }
185
+
186
+ if (id === "telegram") {
187
+ return svg("0 0 24 24", [
188
+ h("path", { key: "mark", fill: "#26A5E4", d: "M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z" }),
189
+ ]);
190
+ }
191
+
192
+ return svg("0 0 24 24", [
193
+ h("circle", { key: "bg", cx: 12, cy: 12, r: 12, fill: "#8b949e" }),
194
+ ]);
195
+ }
196
+
197
+ function Logo({ id, small }) {
198
+ return h("div", { className: small ? "ima-logo sm" : "ima-logo", "data-brand": id, "aria-hidden": "true" }, h(BrandMark, { id }));
199
+ }
200
+
201
+ function isRasterQr(value) {
202
+ return typeof value === "string" && (/^data:image\//i.test(value) || /\.(png|jpe?g|gif|webp)(\?|$)/i.test(value));
203
+ }
204
+
205
+ function qrSrc(pairing) {
206
+ if (!pairing) return "";
207
+ if (isRasterQr(pairing.qrImage)) return pairing.qrImage;
208
+ const payload = pairing.qrUrl || pairing.qrImage;
209
+ if (!payload) return "";
210
+ return "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=" + encodeURIComponent(payload);
211
+ }
212
+
213
+ function hintOf(ch) {
214
+ if (ch.id === "weixin") return "请使用微信扫描二维码完成绑定";
215
+ if (ch.id === "feishu") return "请使用飞书扫描二维码,将自动创建机器人";
216
+ if (ch.id === "lark") return "请使用 Lark 扫描二维码完成配对";
217
+ if (ch.id === "wecom") return "请使用企业微信扫描二维码,快捷绑定机器人";
218
+ if (ch.id === "dingtalk") return "请使用钉钉扫描二维码,自动创建机器人";
219
+ return "请使用对应 App 扫描二维码";
220
+ }
221
+
222
+ let openImSession = (id) => {
223
+ try {
224
+ if (window.__dshSessionsOpen) { window.__dshSessionsOpen(id); return true; }
225
+ } catch { /* ignore */ }
226
+ return false;
227
+ };
228
+ const openListedSession = (id, hostOpen) => {
229
+ if (!id) return;
230
+ if (String(id).startsWith("im:")) {
231
+ api("/sessions/ensure", {
232
+ method: "POST",
233
+ headers: { "content-type": "application/json" },
234
+ body: JSON.stringify({ sessionId: id }),
235
+ }).then((data) => {
236
+ if (!data.ok) { console.warn("[dsh-im-connect] 无法恢复会话", data.error || id); return; }
237
+ const tryOpen = (left) => {
238
+ if (openImSession(id) || left <= 0) return;
239
+ setTimeout(() => tryOpen(left - 1), 80);
240
+ };
241
+ tryOpen(20);
242
+ }).catch((error) => console.warn("[dsh-im-connect] 无法恢复会话", id, error));
243
+ return;
244
+ }
245
+ if (typeof hostOpen === "function") hostOpen(id);
246
+ else openImSession(id);
247
+ };
248
+ let channelSkin = "native";
249
+
250
+ function BindModal({ ch, onClose, onConnected }) {
251
+ const hasQr = ch.kind === "qr" || ch.kind === "qr-or-credentials";
252
+ const hasManual = ch.kind === "credentials" || ch.kind === "qr-or-credentials";
253
+ const [tab, setTab] = useState(hasQr ? "qr" : "manual");
254
+ const [pairing, setPairing] = useState(null);
255
+ const [draft, setDraft] = useState({});
256
+ const [accessMode, setAccessMode] = useState(ch.accessMode === "open" ? "open" : "pair");
257
+ const [busy, setBusy] = useState(false);
258
+ const [error, setError] = useState("");
259
+ const alive = useRef(true);
260
+
261
+ const startQr = useCallback((refresh) => {
262
+ if (!hasQr) return;
263
+ setBusy(true);
264
+ setError("");
265
+ api(`/channels/${ch.id}/qr/${refresh ? "refresh" : "start"}`, {
266
+ method: "POST",
267
+ headers: { "content-type": "application/json" },
268
+ body: JSON.stringify(ch.id === "dingtalk" ? { accessMode } : {}),
269
+ }).then((data) => {
270
+ if (!alive.current) return;
271
+ if (!data.ok && !data.pairing) setError(data.error || "无法生成二维码");
272
+ setPairing(data.pairing || null);
273
+ }).catch(() => { if (alive.current) setError("无法生成二维码"); })
274
+ .finally(() => { if (alive.current) setBusy(false); });
275
+ }, [ch.id, hasQr, accessMode]);
276
+
277
+ useEffect(() => {
278
+ alive.current = true;
279
+ if (tab === "qr") startQr(false);
280
+ return () => { alive.current = false; };
281
+ }, []);
282
+
283
+ useEffect(() => {
284
+ if (tab !== "qr") return undefined;
285
+ const timer = setInterval(() => {
286
+ api(`/channels/${ch.id}/qr/status`).then((data) => {
287
+ if (!alive.current || !data.ok) return;
288
+ setPairing(data.pairing);
289
+ if (data.pairing && data.pairing.status === "success") {
290
+ onConnected();
291
+ }
292
+ }).catch(() => undefined);
293
+ }, 2000);
294
+ return () => clearInterval(timer);
295
+ }, [tab, ch.id, onConnected]);
296
+
297
+ const close = () => {
298
+ alive.current = false;
299
+ if (hasQr) api(`/channels/${ch.id}/qr/cancel`, { method: "POST" }).catch(() => undefined);
300
+ onClose();
301
+ };
302
+
303
+ const saveManual = () => {
304
+ const config = { ...draft };
305
+ if (ch.id === "dingtalk") config.accessMode = accessMode;
306
+ setBusy(true);
307
+ setError("");
308
+ api(`/channels/${ch.id}/connect`, {
309
+ method: "POST",
310
+ headers: { "content-type": "application/json" },
311
+ body: JSON.stringify({ config }),
312
+ }).then((data) => {
313
+ if (!data.ok) setError(data.error || "保存失败");
314
+ else onConnected();
315
+ }).catch(() => setError("保存失败")).finally(() => setBusy(false));
316
+ };
317
+
318
+ const switchTab = (next) => {
319
+ setTab(next);
320
+ setError("");
321
+ if (next === "qr") startQr(false);
322
+ else api(`/channels/${ch.id}/qr/cancel`, { method: "POST" }).catch(() => undefined);
323
+ };
324
+
325
+ const status = pairing && pairing.status;
326
+ const src = qrSrc(pairing);
327
+ const remain = pairing && pairing.remainingSeconds;
328
+
329
+ return h("div", { className: "ima-mask", onClick: close },
330
+ h("div", { className: "ima-modal", onClick: (e) => e.stopPropagation() },
331
+ h("div", { className: "ima-modal-h" },
332
+ h("h2", null, "配置" + ch.label),
333
+ h("button", { className: "ima-x", onClick: close, "aria-label": "关闭" }, "×"),
334
+ ),
335
+ hasQr && hasManual && h("div", { className: "ima-seg" },
336
+ h("button", { className: tab === "qr" ? "on" : "", onClick: () => switchTab("qr") }, "快捷绑定(推荐)"),
337
+ h("button", { className: tab === "manual" ? "on" : "", onClick: () => switchTab("manual") }, "手动配置"),
338
+ ),
339
+ error && h("div", { className: "ima-error" }, error),
340
+ tab === "qr" && hasQr && (
341
+ status === "success"
342
+ ? h("div", { className: "ima-ok" }, "绑定成功,频道已连接")
343
+ : h("div", { className: "ima-qrbox" },
344
+ h("p", { className: "ima-hint" }, (pairing && pairing.hint) || hintOf(ch)),
345
+ src
346
+ ? h("img", { src, alt: ch.label + " 绑定二维码" })
347
+ : h("div", { className: "ima-qrph" }, busy || status === "starting" ? "正在生成…" : (pairing && pairing.error) || "等待二维码"),
348
+ remain > 0 && h("p", { className: "ima-hint" }, "二维码 " + Math.floor(remain / 60) + ":" + String(remain % 60).padStart(2, "0") + " 后过期"),
349
+ status === "scanned" && h("p", { className: "ima-hint" }, "已扫码,请在手机上确认"),
350
+ (status === "expired" || status === "failed") && h("p", { className: "ima-error" }, (pairing && pairing.error) || "请重新生成二维码"),
351
+ ch.id === "dingtalk" && h("div", { className: "ima-radio" },
352
+ h("label", null,
353
+ h("input", { type: "radio", name: "am", checked: accessMode === "pair", onChange: () => setAccessMode("pair") }),
354
+ h("span", null, "配对模式", h("small", null, "仅批准过的用户可以驱动本机助手")),
355
+ ),
356
+ h("label", null,
357
+ h("input", { type: "radio", name: "am", checked: accessMode === "open", onChange: () => setAccessMode("open") }),
358
+ h("span", null, "开放模式", h("small", null, "该渠道消息默认放行,适合企业内部共用")),
359
+ ),
360
+ ),
361
+ h("button", { className: "ima-link", disabled: busy, onClick: () => startQr(true) }, "重新生成二维码"),
362
+ )
363
+ ),
364
+ tab === "manual" && hasManual && h("div", null,
365
+ ...ch.fields.map((f) => h("label", { key: f.key, className: "ima-field" },
366
+ f.label,
367
+ h("input", {
368
+ type: f.secret ? "password" : "text",
369
+ value: draft[f.key] || "",
370
+ placeholder: f.label,
371
+ onChange: (e) => setDraft({ ...draft, [f.key]: e.target.value }),
372
+ }),
373
+ )),
374
+ ch.id === "dingtalk" && h("div", { className: "ima-radio" },
375
+ h("label", null,
376
+ h("input", { type: "radio", name: "am2", checked: accessMode === "pair", onChange: () => setAccessMode("pair") }),
377
+ h("span", null, "配对模式", h("small", null, "仅批准过的用户可以驱动本机助手")),
378
+ ),
379
+ h("label", null,
380
+ h("input", { type: "radio", name: "am2", checked: accessMode === "open", onChange: () => setAccessMode("open") }),
381
+ h("span", null, "开放模式", h("small", null, "该渠道消息默认放行,适合企业内部共用")),
382
+ ),
383
+ ),
384
+ h("div", { style: { display: "flex", justifyContent: "flex-end" } },
385
+ h("button", { className: "ima-btn primary", disabled: busy, onClick: saveManual }, busy ? "保存中…" : "确认"),
386
+ ),
387
+ ),
388
+ ),
389
+ );
390
+ }
391
+
392
+ function ChannelCard({ ch, busy, onAction, onConfigure }) {
393
+ const [menu, setMenu] = useState(false);
394
+ const configuring = !ch.connected;
395
+ const meta = configuring ? "未配置" : (ch.status && ch.status !== "未连接" ? ch.status : "已连接");
396
+ const right = h("div", { className: "ima-actions" },
397
+ configuring
398
+ ? h("button", { className: "ima-btn", disabled: busy, onClick: onConfigure }, busy ? "接入中…" : "配置")
399
+ : [
400
+ h("button", { key: "more", className: "ima-more", "aria-label": ch.label + " 更多", onClick: () => setMenu(!menu) }, "…"),
401
+ menu && h("div", { key: "menu", className: "ima-menu" },
402
+ h("button", { onClick: () => { setMenu(false); onConfigure(); } }, "重新接入"),
403
+ h("button", { onClick: () => { setMenu(false); onAction(ch.id, "disconnect"); } }, "断开"),
404
+ h("button", { onClick: () => { setMenu(false); onAction(ch.id, "remove"); } }, "删除配置"),
405
+ ),
406
+ h("button", {
407
+ key: "sw",
408
+ className: ch.receiveEnabled ? "ima-switch" : "ima-switch off",
409
+ role: "switch",
410
+ "aria-checked": ch.receiveEnabled,
411
+ "aria-label": "接收消息",
412
+ onClick: () => onAction(ch.id, "receive", { receiveEnabled: !ch.receiveEnabled }),
413
+ }, h("i")),
414
+ ],
415
+ );
416
+
417
+ return h("div", { className: "ima-card", title: ch.description || ch.label },
418
+ h("div", { className: "ima-card-main" },
419
+ h("div", { className: "ima-name-row" },
420
+ h(Logo, { id: ch.id }),
421
+ h("span", { className: "ima-name" }, ch.label),
422
+ ch.connected && h("span", { className: "ima-badge" }, "已连接"),
423
+ h("span", { className: "ima-status" }, meta),
424
+ ),
425
+ ),
426
+ right,
427
+ );
428
+ }
429
+
430
+
431
+ const PERMISSIONS = [
432
+ { value: "read-only", label: "Read Only" },
433
+ { value: "workspace-write", label: "Workspace Write" },
434
+ { value: "full-access", label: "Full access" },
435
+ ];
436
+ const DEFAULT_EFFORTS = [
437
+ { id: "low", name: "Low" },
438
+ { id: "medium", name: "Medium" },
439
+ { id: "high", name: "High" },
440
+ ];
441
+
442
+ function FolderIcon() {
443
+ return h("svg", { viewBox: "0 0 16 16", width: 14, height: 14, fill: "none", "aria-hidden": "true" },
444
+ h("path", { d: "M5.196 1.571c.615 0 1.19.308 1.532.819l.471.708c.086.128.23.205.383.205h4.588A2.666 2.666 0 0 1 14.586 5.72v.907c.683.4 1.074 1.223.852 2.06l-1.053 3.971A2.666 2.666 0 0 1 12.05 14.453H2.917A2.416 2.416 0 0 1 .502 11.952V3.987A2.416 2.416 0 0 1 2.918 1.571h2.278Z", fill: "currentColor" }),
445
+ );
446
+ }
447
+
448
+ function ShieldIcon() {
449
+ return h("svg", { viewBox: "0 0 16 16", width: 14, height: 14, fill: "none", "aria-hidden": "true" },
450
+ h("path", { d: "M8 1.25 14.1 3.15v4.25c0 3.55-2.18 6.15-6.1 7.5-3.92-1.35-6.1-3.95-6.1-7.5V3.15L8 1.25Z", stroke: "currentColor", strokeWidth: "1.4", strokeLinejoin: "round" }),
451
+ h("path", { d: "m5.55 8.05 1.55 1.55 3.35-3.55", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round" }),
452
+ );
453
+ }
454
+
455
+ function PlusIcon() {
456
+ return h("svg", { viewBox: "0 0 16 16", width: 14, height: 14, fill: "none", "aria-hidden": "true" },
457
+ h("path", { d: "M8 3v10M3 8h10", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }),
458
+ );
459
+ }
460
+
461
+ function ChipMenu(props) {
462
+ const root = useRef(null);
463
+ useEffect(() => {
464
+ if (!props.open) return undefined;
465
+ const close = (event) => {
466
+ if (root.current && root.current.contains(event.target)) return;
467
+ props.onToggle(false);
468
+ };
469
+ document.addEventListener("mousedown", close);
470
+ return () => document.removeEventListener("mousedown", close);
471
+ }, [props.open]);
472
+ return h("div", { className: "ima-chip" + (props.open ? " is-open" : ""), ref: root },
473
+ h("button", {
474
+ type: "button",
475
+ className: "ima-chip-btn",
476
+ "aria-label": props.ariaLabel,
477
+ "aria-expanded": Boolean(props.open),
478
+ onMouseDown: (event) => event.stopPropagation(),
479
+ onClick: () => props.onToggle(!props.open),
480
+ },
481
+ props.icon,
482
+ h("span", { className: "ima-chip-label" }, props.label),
483
+ props.suffix && h("span", { className: "ima-chip-effort" }, props.suffix),
484
+ h("em"),
485
+ ),
486
+ props.open && h("div", { className: "ima-chip-menu" + (props.align === "end" ? " is-end" : "") }, props.children),
487
+ );
488
+ }
489
+
490
+ function ChipRow(props) {
491
+ return h("button", {
492
+ type: "button",
493
+ className: "ima-chip-row" + (props.active ? " is-on" : "") + (props.kv ? " is-kv" : ""),
494
+ onClick: props.onClick,
495
+ },
496
+ h("span", { className: "ima-chip-row-main" },
497
+ props.icon,
498
+ h("span", null, props.label),
499
+ ),
500
+ h("span", { className: "ima-chip-row-side" },
501
+ props.hint && h("span", null, props.hint),
502
+ props.active && !props.chevron && h("i", { className: "ima-chip-tick" }),
503
+ props.chevron && h("i", { className: "ima-chip-next" }),
504
+ ),
505
+ );
506
+ }
507
+
508
+ function ComposerBar(props) {
509
+ const items = typeof props.useWorkspaces === "function"
510
+ ? (props.useWorkspaces((state) => (state && state.items) || []) || [])
511
+ : [];
512
+ const [providers, setProviders] = useState([]);
513
+ const [provider, setProvider] = useState("");
514
+ const [model, setModel] = useState("");
515
+ const [effort, setEffort] = useState("");
516
+ const [cwd, setCwd] = useState("");
517
+ const [permission, setPermission] = useState("full-access");
518
+ const [open, setOpen] = useState("");
519
+ const [modelPane, setModelPane] = useState("root");
520
+ const [hint, setHint] = useState("");
521
+ const [adding, setAdding] = useState(false);
522
+ const [addPath, setAddPath] = useState("");
523
+ const [addBusy, setAddBusy] = useState(false);
524
+
525
+ useEffect(() => {
526
+ api("/assistant").then((data) => {
527
+ if (!data.ok) { setHint(data.error || "无法加载全局配置"); return; }
528
+ const list = data.providers || [];
529
+ setProviders(list);
530
+ const current = data.assistant || {};
531
+ const nextProvider = current.provider || (list[0] && list[0].id) || "";
532
+ const models = ((list.find((item) => item.id === nextProvider) || {}).models) || [];
533
+ const nextModel = current.model || (models[0] && models[0].id) || "";
534
+ const found = models.find((item) => item.id === nextModel) || models[0];
535
+ setProvider(nextProvider);
536
+ setModel(nextModel);
537
+ setEffort(current.reasoningEffort || (found && found.reasoning && found.reasoning.defaultEffort) || "");
538
+ setCwd(data.cwd || "");
539
+ setPermission(data.permission || "full-access");
540
+ if (!list.length) setHint("当前 Host 还没有可用模型,请先在网页里配置提供商");
541
+ }).catch(() => setHint("无法加载全局配置"));
542
+ }, []);
543
+
544
+ const save = (body) => {
545
+ api("/assistant", {
546
+ method: "POST",
547
+ headers: { "content-type": "application/json" },
548
+ body: JSON.stringify(body),
549
+ }).then((data) => {
550
+ if (!data.ok) setHint(data.error || "保存失败");
551
+ else setHint("");
552
+ }).catch(() => setHint("保存失败"));
553
+ };
554
+
555
+ const workspace = items.find((item) => item.path === cwd);
556
+ const models = providers.flatMap((item) => (item.models || []).map((entry) => ({
557
+ value: item.id + "::" + entry.id,
558
+ provider: item.id,
559
+ model: entry.id,
560
+ label: entry.name || entry.id,
561
+ reasoning: entry.reasoning,
562
+ })));
563
+ const currentModel = models.find((item) => item.provider === provider && item.model === model);
564
+ const efforts = (currentModel && currentModel.reasoning && currentModel.reasoning.efforts && currentModel.reasoning.efforts.length)
565
+ ? currentModel.reasoning.efforts.map((item) => ({ id: item.id, name: item.name || item.id }))
566
+ : DEFAULT_EFFORTS;
567
+ const effortLabel = (efforts.find((item) => item.id === effort) || {}).name || "";
568
+ const perm = PERMISSIONS.find((item) => item.value === permission) || PERMISSIONS[2];
569
+
570
+ const addWorkspace = (path) => {
571
+ const next = (path || "").trim();
572
+ if (!next) { setHint("请选择工作区目录"); return Promise.resolve(); }
573
+ if (typeof props.createWorkspace !== "function") { setHint("当前 Host 无法新增工作区"); return Promise.resolve(); }
574
+ setAddBusy(true);
575
+ return Promise.resolve(props.createWorkspace({ path: next })).then((created) => {
576
+ const cwdPath = (created && (created.path || created.cwd)) || next;
577
+ setCwd(cwdPath);
578
+ save({ cwd: cwdPath });
579
+ setAdding(false);
580
+ setAddPath("");
581
+ setOpen("");
582
+ }).catch((error) => {
583
+ setHint((error && error.message) || "新增工作区失败");
584
+ }).finally(() => setAddBusy(false));
585
+ };
586
+
587
+ const onAddWorkspace = () => {
588
+ setOpen("");
589
+ if (typeof props.pickDirectory === "function") {
590
+ Promise.resolve(props.pickDirectory()).then((picked) => {
591
+ if (!picked) return;
592
+ return addWorkspace(picked);
593
+ }).catch(() => {
594
+ setAdding(true);
595
+ setAddPath("");
596
+ });
597
+ return;
598
+ }
599
+ setAdding(true);
600
+ setAddPath("");
601
+ };
602
+
603
+ return h("div", { className: "ima-composer-wrap" },
604
+ h("div", { className: "ima-composer", "aria-label": "全局会话配置" },
605
+ h("div", { className: "ima-composer-left" },
606
+ h(ChipMenu, {
607
+ open: open === "ws",
608
+ onToggle: (next) => setOpen(next ? "ws" : ""),
609
+ icon: h(FolderIcon),
610
+ label: (workspace && (workspace.title || workspace.path)) || cwd || "选择项目",
611
+ ariaLabel: "项目",
612
+ },
613
+ items.length === 0 && h("div", { className: "ima-chip-empty" }, "暂无工作区"),
614
+ ...items.map((item) => h(ChipRow, {
615
+ key: item.path,
616
+ icon: h(FolderIcon),
617
+ label: item.title || item.path,
618
+ active: item.path === cwd,
619
+ onClick: () => { setCwd(item.path); save({ cwd: item.path }); setOpen(""); },
620
+ })),
621
+ h("div", { className: "ima-chip-split" }),
622
+ h(ChipRow, {
623
+ icon: h(PlusIcon),
624
+ label: "添加工作区…",
625
+ onClick: onAddWorkspace,
626
+ }),
627
+ ),
628
+ h(ChipMenu, {
629
+ open: open === "perm",
630
+ onToggle: (next) => setOpen(next ? "perm" : ""),
631
+ icon: h(ShieldIcon),
632
+ label: perm.label,
633
+ ariaLabel: "权限",
634
+ },
635
+ ...PERMISSIONS.map((item) => h(ChipRow, {
636
+ key: item.value,
637
+ icon: h(ShieldIcon),
638
+ label: item.label,
639
+ active: item.value === permission,
640
+ onClick: () => { setPermission(item.value); save({ permission: item.value }); setOpen(""); },
641
+ })),
642
+ ),
643
+ ),
644
+ h("div", { className: "ima-composer-right" },
645
+ h(ChipMenu, {
646
+ open: open === "model",
647
+ onToggle: (next) => {
648
+ setOpen(next ? "model" : "");
649
+ if (next) setModelPane("root");
650
+ },
651
+ align: "end",
652
+ label: (currentModel && currentModel.label) || "选择模型",
653
+ suffix: effortLabel,
654
+ ariaLabel: "模型",
655
+ },
656
+ modelPane === "root" && [
657
+ h(ChipRow, {
658
+ key: "model",
659
+ kv: true,
660
+ label: "Model",
661
+ hint: (currentModel && currentModel.label) || "未选择",
662
+ chevron: true,
663
+ onClick: () => setModelPane("model"),
664
+ }),
665
+ h(ChipRow, {
666
+ key: "effort",
667
+ kv: true,
668
+ label: "Effort",
669
+ hint: effortLabel || "Default",
670
+ chevron: true,
671
+ onClick: () => setModelPane("effort"),
672
+ }),
673
+ ],
674
+ modelPane === "model" && (
675
+ models.length === 0
676
+ ? h("div", { className: "ima-chip-empty" }, "暂无模型")
677
+ : models.map((item) => h(ChipRow, {
678
+ key: item.value,
679
+ label: item.label,
680
+ active: item.provider === provider && item.model === model,
681
+ onClick: () => {
682
+ const nextEffort = (item.reasoning && item.reasoning.defaultEffort) || effort || "high";
683
+ setProvider(item.provider);
684
+ setModel(item.model);
685
+ setEffort(nextEffort);
686
+ save({ provider: item.provider, model: item.model, reasoningEffort: nextEffort });
687
+ setOpen("");
688
+ },
689
+ }))
690
+ ),
691
+ modelPane === "effort" && efforts.map((item) => h(ChipRow, {
692
+ key: item.id,
693
+ label: item.name,
694
+ active: item.id === effort,
695
+ onClick: () => {
696
+ setEffort(item.id);
697
+ if (provider && model) save({ provider, model, reasoningEffort: item.id });
698
+ setOpen("");
699
+ },
700
+ })),
701
+ ),
702
+ ),
703
+ ),
704
+ adding && h("div", { className: "ima-chip-dialog" },
705
+ h("strong", null, "添加工作区…"),
706
+ h("input", {
707
+ value: addPath,
708
+ placeholder: "工作区路径",
709
+ "aria-label": "工作区路径",
710
+ onChange: (event) => setAddPath(event.target.value),
711
+ }),
712
+ h("div", { className: "ima-chip-dialog-actions" },
713
+ h("button", { className: "ima-btn", onClick: () => { setAdding(false); setAddPath(""); } }, "取消"),
714
+ h("button", {
715
+ className: "ima-btn primary",
716
+ disabled: addBusy || !addPath.trim(),
717
+ onClick: () => addWorkspace(addPath),
718
+ }, addBusy ? "添加中…" : "确认"),
719
+ ),
720
+ ),
721
+ hint && h("div", { className: "ima-composer-hint" }, hint),
722
+ );
723
+ }
724
+
725
+ function SettingsPage(props) {
726
+ const [channels, setChannels] = useState(null);
727
+ const [pending, setPending] = useState([]);
728
+ const [error, setError] = useState("");
729
+ const [busy, setBusy] = useState({});
730
+ const [editing, setEditing] = useState(null);
731
+
732
+ const refresh = useCallback(() => {
733
+ api("/channels").then((data) => {
734
+ if (data.ok) { setChannels(data.channels); setPending(data.pending || []); setError(""); }
735
+ else setError(data.error || "加载失败");
736
+ }).catch(() => setError("无法连接本机 IM 助理接口"));
737
+ }, []);
738
+
739
+ useEffect(() => { ensureStyle(); refresh(); }, [refresh]);
740
+ useEffect(() => {
741
+ if (!(pending || []).length) return;
742
+ const timer = setInterval(refresh, 4000);
743
+ return () => clearInterval(timer);
744
+ }, [pending, refresh]);
745
+
746
+ const onAction = (id, action, body) => {
747
+ setBusy((prev) => ({ ...prev, [id]: true }));
748
+ api(`/channels/${id}/${action}`, {
749
+ method: "POST",
750
+ headers: { "content-type": "application/json" },
751
+ body: JSON.stringify(body || {}),
752
+ }).then((data) => {
753
+ if (!data.ok) setError(data.error || "操作失败");
754
+ else setError("");
755
+ refresh();
756
+ }).catch(() => setError("请求失败")).finally(() => {
757
+ setBusy((prev) => ({ ...prev, [id]: false }));
758
+ });
759
+ };
760
+
761
+ return h("section", { className: "ima-page", "aria-label": "IM助理" },
762
+ h("header", { className: "ima-head" },
763
+ h("div", null,
764
+ h("h2", { className: "ima-title" }, "IM 频道"),
765
+ h("p", { className: "ima-sub" }, "配置 IM 频道,让本机助手接收来自钉钉、飞书等平台的消息。频道配置仅保存在本机。"),
766
+ ),
767
+ ),
768
+ h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory }),
769
+ error && h("div", { className: "ima-error" }, error),
770
+ pending && pending.length > 0 && h("div", { className: "ima-pending" },
771
+ h("div", null, "有访问请求(仅在关闭全局放行时需要批准)"),
772
+ ...pending.map((p) => h("div", { key: p.channelId + p.userId, className: "ima-pending-row" },
773
+ h("span", { style: { flex: 1 } }, (p.username || p.userId) + " · " + p.channelId),
774
+ h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "approve", { userId: p.userId }) }, "批准"),
775
+ h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "deny", { userId: p.userId }) }, "拒绝"),
776
+ )),
777
+ ),
778
+ channels == null
779
+ ? h("div", { className: "ima-empty" }, "加载中…")
780
+ : h("div", { className: "ima-list" },
781
+ ...channels.map((ch) => h(ChannelCard, {
782
+ key: ch.id,
783
+ ch,
784
+ busy: busy[ch.id],
785
+ onAction,
786
+ onConfigure: () => setEditing(ch.id),
787
+ })),
788
+ ),
789
+ editing && h(BindModal, {
790
+ ch: (channels || []).find((item) => item.id === editing) || { id: editing, label: editing, kind: "qr", fields: [] },
791
+ onClose: () => setEditing(null),
792
+ onConnected: () => { setEditing(null); refresh(); },
793
+ }),
794
+ );
795
+ }
796
+
797
+ const WB_CSS = `.dcu-wb,.ima-native{display:flex;flex:1;min-height:0;flex-direction:column;padding:0;padding-right:var(--dsh-sidebar-inline-padding,12px);box-sizing:border-box;color:var(--dsw-alias-label-primary,var(--ima-text));font:14px/20px inherit}.ima-n-head{flex:none;display:flex;align-items:center;height:36px;padding-left:4px;margin:2px 0 4px;color:var(--dsw-alias-label-tertiary,#81858C);font:14px/20px inherit}.ima-native-tree,.dcu-wb-tree{padding:0 0 16px 4px;scrollbar-gutter:stable}.ima-native-project+.ima-native-project,.dcu-wb-project+.dcu-wb-project{margin-top:4px}.ima-native-project>*+*,.dcu-wb-project>*+*{margin-top:2px}
798
+ .dcu-wb *,.ima-native *{box-sizing:border-box}
799
+ .dcu-wb-tree,.ima-native-tree{flex:1;min-height:0;overflow-y:auto;padding-bottom:16px;user-select:none}
800
+ .dcu-wb-project-head,.ima-native-head,.dcu-wb-session,.ima-native-session{display:flex;align-items:center;gap:6px;width:100%;border:0;border-radius:8px;padding:0 8px;background:transparent;color:inherit;cursor:pointer;font:inherit;text-align:left}
801
+ .dcu-wb-project-head,.ima-native-head{height:34px}
802
+ .dcu-wb-project-head:hover,.dcu-wb-session:hover,.dcu-wb-session.dcu-wb-selected,.ima-native-head:hover,.ima-native-session:hover,.ima-native-session.on{background:var(--dsw-alias-interactive-bg-hover,var(--dcu-sidebar-hover,rgba(255,255,255,.06)))}
803
+ .dcu-wb-folder,.ima-native-folder{display:grid;place-items:center;flex:none;width:16px;height:20px}
804
+ .dcu-wb-project-title,.dcu-wb-session-title,.ima-native-title,.ima-n-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;flex:1;font-weight:400}
805
+ .dcu-wb-session-title,.ima-native-session .ima-native-title{font-weight:400}
806
+ .dcu-wb-session,.ima-native-session{position:relative;min-height:32px;padding-left:32px}
807
+ .dcu-wb-actions,.ima-native-actions{display:none;align-items:center;flex:none}
808
+ .dcu-wb-session:hover .dcu-wb-actions,.dcu-wb-session.dcu-wb-menu-open .dcu-wb-actions,.ima-native-session:hover .ima-native-actions,.ima-native-session.menu-on .ima-native-actions{display:flex}
809
+ .dcu-wb-more,.ima-native-more{display:grid;place-items:center;width:20px;height:20px;border:0;border-radius:4px;padding:0;background:transparent;color:var(--dsw-alias-label-secondary,var(--ima-muted));cursor:pointer}
810
+ .dcu-wb-empty,.ima-native-empty{padding:14px 8px;color:var(--dsw-alias-label-tertiary,var(--ima-muted));font-size:13px}
811
+ .ima-sess-menu{position:absolute;right:8px;top:30px;min-width:132px;padding:6px;border:1px solid var(--dsw-alias-stroke-primary,var(--ima-line));border-radius:10px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));z-index:8}
812
+ .ima-sess-menu button{display:block;width:100%;text-align:left;border:0;background:transparent;color:inherit;padding:7px 10px;border-radius:6px;cursor:pointer;font:13px/18px inherit}
813
+ .ima-sess-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
814
+ .ima-sess-menu button.danger{color:var(--dsw-alias-state-error-primary,var(--ima-danger))}
815
+ .ima-rename{flex:1;min-width:0;min-height:28px;padding:2px 8px;border-radius:6px;border:1px solid var(--dsw-alias-stroke-primary,var(--ima-line));background:transparent;color:inherit;font:inherit}
816
+ .ima-n-row,.ima-n-sess{display:flex;align-items:center;gap:6px;border-radius:8px;padding:0 8px;cursor:pointer;user-select:none;width:100%;border:0;background:transparent;color:var(--dsw-alias-label-primary,var(--ima-text));font:14px/20px inherit;text-align:left;box-sizing:border-box}
817
+ .ima-n-row{height:34px}
818
+ .ima-n-sess{height:32px;gap:0;position:relative}
819
+ .ima-n-row:hover,.ima-n-sess:hover,.ima-n-sess.on,.ima-n-row.menu-on,.ima-n-sess.menu-on{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
820
+ .ima-n-slot{flex:none;width:16px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary,#81858C)}.ima-run-dot{flex:none;color:var(--dsw-static-deepseek-450,#4c8dff)}.ima-run-dot-cell{fill:currentColor;opacity:.15;animation:ima-run-chase 1s infinite}@keyframes ima-run-chase{0%,12.4%{opacity:1}12.5%,24.9%{opacity:.6}25%,37.4%{opacity:.35}37.5%,100%{opacity:.15}}
821
+ .ima-n-row .ima-n-chevron{display:none;color:var(--dsw-alias-label-caption,#ADB2B8)}
822
+ .ima-n-row:hover .ima-n-chevron{display:inline-flex}
823
+ .ima-n-row:hover .ima-n-folder{display:none}
824
+ .ima-n-arrow{transition:transform .15s ease}
825
+ .ima-n-arrow.open{transform:rotate(90deg)}
826
+ .ima-n-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;flex:1;font-weight:400}
827
+ .ima-n-sess .ima-n-title{margin:0 6px 0 4px}
828
+ .ima-n-time{flex:none;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary,#81858C)}
829
+ .ima-n-acts{flex:none;display:none;align-items:center;gap:12px}
830
+ .ima-n-row:hover .ima-n-acts,.ima-n-sess:hover .ima-n-acts,.ima-n-row.menu-on .ima-n-acts,.ima-n-sess.menu-on .ima-n-acts{display:inline-flex}
831
+ .ima-n-sess:hover .ima-n-time,.ima-n-sess.menu-on .ima-n-time{display:none}
832
+ .ima-n-ico{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:0;border-radius:4px;padding:0;background:transparent;cursor:pointer;color:var(--dsw-alias-label-tertiary,#81858C)}
833
+ .ima-n-ico:hover{color:var(--dsw-alias-label-primary,var(--ima-text))}
834
+ .ima-n-menu{position:absolute;right:8px;top:calc(100% + 4px);z-index:1100;min-width:218px;max-width:360px;box-sizing:border-box;padding:4px;display:flex;flex-direction:column;border:1px solid var(--dsw-alias-border-inverted,rgba(255,255,255,.12));border-radius:12px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.36))}
835
+ .ima-n-menu button{display:flex;align-items:center;gap:8px;width:100%;min-height:40px;padding:8px 10px;border:0;border-radius:10px;background:transparent;cursor:pointer;font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary,var(--ima-text));text-align:left}
836
+ .ima-n-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
837
+ .ima-n-mi{display:inline-flex;flex:none;width:16px;height:16px;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary,#81858C)}
838
+ .ima-n-menu button.danger{color:var(--dsw-alias-state-error-primary,#f85149)}
839
+ .ima-n-menu button.danger .ima-n-mi{color:inherit}
840
+ .ima-n-menu button.danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(248,81,73,.12))}`;
841
+
842
+ function NativeSvg(viewBox, size, children) {
843
+ return h("svg", { viewBox, width: size, height: size, fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, children);
844
+ }
845
+ function NativePath(d, extra) {
846
+ return h("path", Object.assign({ d, fill: "currentColor" }, extra || {}));
847
+ }
848
+ function IconEllipsis() {
849
+ return NativeSvg("0 0 16 16", 16, [
850
+ NativePath("M4.55146 8.00001C4.55146 8.63513 4.03659 9.15001 3.40146 9.15001C2.76634 9.15001 2.25146 8.63513 2.25146 8.00001C2.25146 7.36488 2.76634 6.85001 3.40146 6.85001C4.03659 6.85001 4.55146 7.36488 4.55146 8.00001Z"),
851
+ NativePath("M9.1476 8.00001C9.1476 8.63513 8.63273 9.15001 7.9976 9.15001C7.36248 9.15001 6.8476 8.63513 6.8476 8.00001C6.8476 7.36488 7.36248 6.85001 7.9976 6.85001C8.63273 6.85001 9.1476 7.36488 9.1476 8.00001Z"),
852
+ NativePath("M13.7486 8.00001C13.7486 8.63513 13.2338 9.15001 12.5986 9.15001C11.9635 9.15001 11.4486 8.63513 11.4486 8.00001C11.4486 7.36488 11.9635 6.85001 12.5986 6.85001C13.2338 6.85001 13.7486 7.36488 13.7486 8.00001Z"),
853
+ ]);
854
+ }
855
+ function IconEdit() {
856
+ return NativeSvg("0 0 16 16", 16, NativePath("M9.941 1.349a2.54 2.54 0 0 1 2.473 0c.292.171.555.442.897.784.341.341.612.604.783.896a2.54 2.54 0 0 1 0 2.473c-.171.292-.442.555-.784.896L6.659 13.05c-.378.378-.652.661-.994.86-.341.199-.722.298-1.238.44l-1.183.326c-.469.13-.899.25-1.243.292-.349.043-.821.033-1.19-.336-.369-.369-.379-.841-.336-1.19.042-.344.163-.774.292-1.243l.326-1.183c.143-.516.242-.897.44-1.238.199-.342.482-.615.86-.994l6.652-6.651c.341-.342.604-.613.896-.784Zm1.759 1.222a1.16 1.16 0 0 0-1.045 0c-.095.056-.206.158-.61.562L9.456 3.721l2.265 2.265.589-.588c.404-.403.507-.515.562-.61a1.16 1.16 0 0 0 0-1.045c-.056-.095-.158-.206-.562-.61-.404-.404-.515-.507-.61-.562ZM3.394 9.784c-.429.429-.551.56-.637.706-.085.147-.138.318-.3.903l-.326 1.183c-.129.468-.209.766-.242.978.212-.033.51-.112.979-.241l1.183-.327c.585-.161.756-.214.902-.3.147-.085.277-.208.706-.636l5.062-5.063-2.265-2.265-5.062 5.062Z"));
857
+ }
858
+ function IconBranch() {
859
+ return NativeSvg("0 0 16 16", 16, NativePath("M13.076 1.372c1.008 0 1.826.819 1.826 1.827s-.818 1.826-1.826 1.826c-.78 0-1.444-.488-1.706-1.175H4.355c.439.415.804.915 1.062 1.485l1.69 3.733a4.83 4.83 0 0 0 4.312 2.97c.29-.626.923-1.061 1.658-1.061 1.008 0 1.826.818 1.826 1.826s-.818 1.826-1.826 1.826c-.823 0-1.519-.545-1.747-1.293a6.34 6.34 0 0 1-5.406-3.731L4.232 5.871A3.83 3.83 0 0 0 1.098 3.85V2.549h10.272c.263-.687.927-1.177 1.706-1.177Zm0 10.904a.525.525 0 1 0 0 1.052.525.525 0 0 0 0-1.052Zm0-9.603a.526.526 0 1 0 0 1.053.526.526 0 0 0 0-1.053Z", { fillRule: "evenodd", clipRule: "evenodd" }));
860
+ }
861
+ function IconArchive() {
862
+ return NativeSvg("0 0 20 20", 16, [
863
+ NativePath("M15.866 2.06a2.526 2.526 0 0 1 2.525 2.525v.902c0 .54-.172 1.04-.461 1.45l.009.085v5.866c0 .746 0 1.35-.039 1.837-.035.434-.106.825-.262 1.189l-.072.154a3.03 3.03 0 0 1-1.262 1.366l-.236.132c-.408.208-.848.294-1.344.334-.488.04-1.091.04-1.837.04H7.111c-.746 0-1.35 0-1.837-.04-.434-.035-.825-.105-1.189-.261l-.154-.073a3.03 3.03 0 0 1-1.366-1.262l-.132-.235a2.53 2.53 0 0 1-.335-1.344c-.04-.487-.039-1.091-.039-1.837V7.022c0-.029.005-.057.008-.086A2.48 2.48 0 0 1 1.609 5.487v-.902A2.526 2.526 0 0 1 4.134 2.06h11.732Zm.632 5.87a2.48 2.48 0 0 1-.632.083H4.134a2.48 2.48 0 0 1-.634-.083v4.959c0 .77 0 1.304.034 1.72.034.406.095.635.182.806l.076.137c.191.311.465.565.792.731l.141.061c.156.055.361.096.666.121.415.034.95.035 1.72.035h5.775c.77 0 1.305 0 1.72-.035.407-.033.636-.095.807-.182l.138-.077c.311-.191.565-.464.731-.791l.06-.142c.056-.155.097-.36.122-.665.034-.415.034-.95.034-1.72V7.93ZM4.134 3.5a1.086 1.086 0 0 0-1.085 1.085v.902c0 .599.486 1.085 1.085 1.085h11.732c.599 0 1.085-.486 1.085-1.085v-.902A1.086 1.086 0 0 0 15.866 3.5H4.134Z", { fillRule: "evenodd", clipRule: "evenodd" }),
864
+ NativePath("M12.796 12.566v-1.483H7.205v1.483h5.591Z"),
865
+ ]);
866
+ }
867
+ function IconTrash() {
868
+ return NativeSvg("0 0 16 16", 16, NativePath("M14.478 4.841 14.214 10.115c-.104 2.072-.147 2.896-.827 3.846a3.53 3.53 0 0 1-1.044.993c-.519.333-1.101.478-1.784.546-.671.067-1.509.066-2.559.066s-1.887.001-2.558-.066c-.683-.068-1.266-.213-1.784-.546a3.53 3.53 0 0 1-1.044-.993c-.681-.95-.724-1.774-.828-3.846L1.522 4.841l1.368-.068.263 5.273c.109 2.176.171 2.556.573 3.117a2.16 2.16 0 0 0 .673.64c.263.169.603.277 1.179.334.587.059 1.345.06 2.422.06s1.834-.001 2.422-.06c.575-.057.916-.165 1.179-.335.262-.168.49-.386.672-.64.402-.56.464-.94.573-3.116l.263-5.273 1.369.068ZM5.43 6.228h1.37v5.163H5.43V6.228Zm3.77 0h1.37v5.163H9.2V6.228ZM8.536.434c.644 0 1.116-.007 1.56.137.14.045.276.101.406.168.416.212.745.552 1.2 1.007l.796.795h2.876v1.37H.626V2.541h2.876l.796-.795c.456-.455.784-.795 1.2-1.007.13-.067.266-.123.405-.168C6.348.427 6.82.434 7.464.434h1.072Zm-1.072 1.37c-.732 0-.948.008-1.138.07a2.2 2.2 0 0 0-.206.085c-.156.08-.296.204-.678.583h5.117c-.382-.379-.522-.503-.679-.583a2.2 2.2 0 0 0-.205-.085c-.191-.062-.406-.07-1.138-.07H7.464Z"));
869
+ }
870
+ function IconFolderClose() {
871
+ return NativeSvg("0 0 16 16", 16, NativePath("M6.556 3.377 6.007 3.725l.549-.348ZM14.5 12.342h.65V6.397h-.65-.65v5.945h.65Zm-1.674-7.618v-.65H8.023v.65h4.803Zm-5.746-.519.55-.347-.525-.828-.549.348-.549.348.525.828.55-.348ZM5.613 2.858h0H3.174v.65h2.439v-.65ZM3 4.532v8.46h.65V4.532H3Zm11.326 9.484v-.65H4.674v.65h9.652ZM3 12.342h-.65A2.324 2.324 0 0 0 4.674 14.666v-1.3A.824.824 0 0 1 3.65 12.342H3Zm.174-9.484h0A2.324 2.324 0 0 0 2.35 4.532h1.3A.824.824 0 0 1 4.674 3.508h0V2.858Zm3.382.519.549-.348A1.824 1.824 0 0 0 5.613 2.208v1.3c.16 0 .308.082.394.217l.549-.348Zm1.467 1.347h0c-.16 0-.308-.082-.393-.216l-.55.347-.549.348A1.824 1.824 0 0 0 8.023 5.374v-1.3ZM14.5 6.397h.65A2.324 2.324 0 0 0 12.826 4.073v1.3c.565 0 1.024.458 1.024 1.024h.65Zm0 5.945h-.65c0 .565-.458 1.024-1.024 1.024v1.3A2.324 2.324 0 0 0 15.15 12.342h-.65Z"));
872
+ }
873
+ function IconFolderOpen() {
874
+ return NativeSvg("0 0 16 16", 16, NativePath("M5.196 1.571c.615 0 1.19.308 1.532.819l.471.708c.086.128.23.205.383.205h4.588A2.666 2.666 0 0 1 14.586 5.72v.907c.683.4 1.074 1.223.852 2.06l-1.053 3.971A2.666 2.666 0 0 1 12.05 14.453H2.917A2.416 2.416 0 0 1 .502 11.952V3.987A2.416 2.416 0 0 1 2.918 1.571h2.278Zm-1.417 6.185c-.469 0-.88.316-1.001.77l-.862 3.247c-.174.657.322 1.301 1.001 1.301H12.05c.469 0 .88-.316 1.001-.77l1.053-3.97c.078-.291-.142-.577-.444-.577H3.779Zm-.861-4.804c-.572 0-1.035.464-1.035 1.035v3.307a2.67 2.67 0 0 1 1.896-.919h9.426V5.72c0-.572-.464-1.035-1.035-1.035H7.582c-.615 0-1.19-.309-1.531-.82L5.579 3.156a.666.666 0 0 0-.383-.204H2.918Z"));
875
+ }
876
+ function IconChevron() {
877
+ return NativeSvg("0 0 14 14", 14, NativePath("M4.25 2.828v8.344c0 .49.592.735.939.389l4.172-4.172a.55.55 0 0 0 0-.778L5.189 2.439c-.347-.347-.939-.101-.939.389Z"));
878
+ }
879
+ function MoreIcon() {
880
+ return h(IconEllipsis);
881
+ }
882
+ const RUN_CELLS = [[0,0],[4,0],[8,0],[8,4],[8,8],[4,8],[0,8],[0,4]];
883
+ function RunningStateDot() {
884
+ return h("svg", { className: "ima-run-dot", width: 10, height: 10, viewBox: "0 0 10 10", shapeRendering: "crispEdges", "aria-hidden": "true" },
885
+ RUN_CELLS.map(function (cell, index) {
886
+ return h("rect", { key: cell[0] + "-" + cell[1], className: "ima-run-dot-cell", x: cell[0], y: cell[1], width: "2", height: "2", style: { animationDelay: ((index - RUN_CELLS.length) * 125) + "ms" } });
887
+ })
888
+ );
889
+ }
890
+ function relativeTime(value) {
891
+ const ts = Date.parse(value || "");
892
+ if (!Number.isFinite(ts)) return "";
893
+ const delta = Math.max(0, Date.now() - ts);
894
+ const min = Math.floor(delta / 60000);
895
+ if (min < 1) return "刚刚";
896
+ if (min < 60) return min + "分钟";
897
+ const hour = Math.floor(min / 60);
898
+ if (hour < 24) return hour + "小时";
899
+ return Math.floor(hour / 24) + "天";
900
+ }
901
+
902
+
903
+ function ChannelSessionRow({ sess, selected, onOpen, onChanged, skin, sessionActions, sessionById }) {
904
+ const [menu, setMenu] = useState(false);
905
+ const [renaming, setRenaming] = useState(false);
906
+ const [draft, setDraft] = useState(sess.title || sess.chatId || "");
907
+ const title = sess.title || sess.chatId;
908
+ const native = skin !== "codex";
909
+ const rowClass = native
910
+ ? ("ima-native-session" + (selected ? " on" : "") + (menu ? " menu-on" : ""))
911
+ : ("dcu-wb-session" + (selected ? " dcu-wb-selected" : "") + (menu ? " dcu-wb-menu-open" : ""));
912
+ const syncList = (groups) => { if (groups) onChanged(groups); };
913
+ const run = (action, extra) => {
914
+ setMenu(false);
915
+ if (action === "copy-title") { try { navigator.clipboard.writeText(title); } catch { /* ignore */ } return; }
916
+ if (action === "copy-id") { try { navigator.clipboard.writeText(sess.sessionId); } catch { /* ignore */ } return; }
917
+ if (action === "copy-link") {
918
+ try { navigator.clipboard.writeText(location.origin + "/?session=" + encodeURIComponent(sess.sessionId)); } catch { /* ignore */ }
919
+ return;
920
+ }
921
+ const acts = sessionActions || {};
922
+ const afterHost = () => api("/sessions/" + (action === "archive" || action === "delete" || action === "fork" ? "remove" : action), {
923
+ method: "POST",
924
+ headers: { "content-type": "application/json" },
925
+ body: JSON.stringify(Object.assign({ sessionId: sess.sessionId }, extra || {})),
926
+ }).then((data) => { if (data.ok) syncList(data.groups); }).catch(() => undefined);
927
+ if (action === "rename" && typeof acts.renameSession === "function") {
928
+ Promise.resolve(acts.renameSession(sess.sessionId, (extra && extra.title) || title)).then(afterHost).catch(afterHost);
929
+ return;
930
+ }
931
+ if (action === "archive") {
932
+ if (typeof acts.archiveSession === "function") {
933
+ Promise.resolve(acts.archiveSession(sess.sessionId)).then(afterHost).catch(afterHost);
934
+ } else {
935
+ afterHost();
936
+ }
937
+ return;
938
+ }
939
+ if ((action === "delete" || action === "remove") && typeof acts.deleteSession === "function") {
940
+ Promise.resolve(acts.deleteSession(sess.sessionId)).then(() => afterHost()).catch(() => afterHost());
941
+ return;
942
+ }
943
+ if (action === "fork" && typeof acts.forkSession === "function") {
944
+ Promise.resolve(acts.forkSession(sess.sessionId)).catch(() => undefined);
945
+ return;
946
+ }
947
+ const localAction = action === "delete" ? "remove" : action;
948
+ api("/sessions/" + localAction, {
949
+ method: "POST",
950
+ headers: { "content-type": "application/json" },
951
+ body: JSON.stringify(Object.assign({ sessionId: sess.sessionId }, extra || {})),
952
+ }).then((data) => { if (data.ok) syncList(data.groups); }).catch(() => undefined);
953
+ };
954
+ if (renaming) {
955
+ return h("div", { className: rowClass },
956
+ h("input", {
957
+ className: "ima-rename",
958
+ value: draft,
959
+ autoFocus: true,
960
+ "aria-label": "重命名会话",
961
+ onChange: (e) => setDraft(e.target.value),
962
+ onClick: (e) => e.stopPropagation(),
963
+ onKeyDown: (e) => {
964
+ if (e.key === "Enter") { e.preventDefault(); setRenaming(false); run("rename", { title: draft.trim() || title }); }
965
+ if (e.key === "Escape") { e.preventDefault(); setRenaming(false); setDraft(title); }
966
+ },
967
+ onBlur: () => { setRenaming(false); if (draft.trim() && draft.trim() !== title) run("rename", { title: draft.trim() }); },
968
+ }),
969
+ );
970
+ }
971
+ const menuItems = [
972
+ { id: "rename", label: "重命名", icon: h(IconEdit), go: () => { setRenaming(true); } },
973
+ { id: "fork", label: "分叉会话", icon: h(IconBranch), go: () => run("fork") },
974
+ { id: "archive", label: "归档会话", icon: h(IconArchive), go: () => run("archive") },
975
+ { id: "delete", label: "删除会话", icon: h(IconTrash), danger: true, go: () => run("delete") },
976
+ ];
977
+ return h("div", {
978
+ className: native ? ("ima-n-sess" + (selected ? " on" : "") + (menu ? " menu-on" : "")) : rowClass,
979
+ role: "treeitem",
980
+ tabIndex: 0,
981
+ "aria-selected": selected,
982
+ onClick: () => onOpen(sess.sessionId),
983
+ onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onOpen(sess.sessionId); } },
984
+ onContextMenu: (e) => { e.preventDefault(); e.stopPropagation(); setMenu(!menu); },
985
+ },
986
+ native && h("span", { className: "ima-n-slot" }, (sess.running || (sessionById && sessionById[sess.sessionId] && sessionById[sess.sessionId].running)) ? h(RunningStateDot) : null),
987
+ h("span", { className: native ? "ima-n-title" : "dcu-wb-session-title" }, title),
988
+ native && h("span", { className: "ima-n-time" }, relativeTime(sess.updatedAt)),
989
+ h("span", { className: native ? "ima-n-acts" : "dcu-wb-actions" },
990
+ h("button", {
991
+ type: "button",
992
+ className: native ? "ima-n-ico" : "dcu-wb-more",
993
+ "aria-label": title + " 更多",
994
+ onClick: (e) => { e.stopPropagation(); setMenu(!menu); },
995
+ }, native ? h(IconEllipsis) : h(MoreIcon)),
996
+ ),
997
+ menu && h("div", { className: native ? "ima-n-menu" : "ima-sess-menu", onClick: (e) => e.stopPropagation() },
998
+ ...menuItems.map((item) => h("button", {
999
+ key: item.id,
1000
+ type: "button",
1001
+ className: item.danger ? "danger" : undefined,
1002
+ onClick: () => { setMenu(false); item.go(); },
1003
+ }, native && h("span", { className: "ima-n-mi" }, item.icon), item.label)),
1004
+ ),
1005
+ );
1006
+ }
1007
+
1008
+ function ChannelRail(props) {
1009
+ if (typeof props.useSessions === "function" || typeof props.useWorkspaces === "function") return h(ChannelRailWithSessions, props);
1010
+ return h(ChannelRailView, props);
1011
+ }
1012
+
1013
+ function ChannelRailWithSessions(props) {
1014
+ const selectedId = typeof props.useSessions === "function"
1015
+ ? props.useSessions((state) => (state && state.current) || null)
1016
+ : (props.selectedId || null);
1017
+ const archivedIds = typeof props.useWorkspaces === "function"
1018
+ ? props.useWorkspaces((state) => (state && state.archivedSessionIds) || [])
1019
+ : (props.archivedIds || []);
1020
+ const sessionById = typeof props.useSessions === "function"
1021
+ ? props.useSessions((state) => (state && state.byId) || {})
1022
+ : {};
1023
+ return h(ChannelRailView, Object.assign({}, props, {
1024
+ selectedId: selectedId || props.selectedId || null,
1025
+ archivedIds,
1026
+ sessionById,
1027
+ }));
1028
+ }
1029
+
1030
+ function ChannelRailView(props) {
1031
+ const [groups, setGroups] = useState([]);
1032
+ const [folded, setFolded] = useState({});
1033
+ const [error, setError] = useState("");
1034
+ const selectedId = props.selectedId;
1035
+ const archived = new Set(props.archivedIds || []);
1036
+ const skin = props.skin || channelSkin;
1037
+ const native = skin !== "codex";
1038
+ const open = (id) => openListedSession(id, props.openSession || props.open);
1039
+ useEffect(() => {
1040
+ ensureStyle();
1041
+ const load = () => api("/channels").then((data) => {
1042
+ if (data.ok) { setGroups(data.groups || []); setError(""); }
1043
+ else setError(data.error || "加载失败");
1044
+ }).catch(() => setError("无法连接本机 IM 助理接口"));
1045
+ load();
1046
+ const timer = setInterval(load, 4000);
1047
+ return () => clearInterval(timer);
1048
+ }, []);
1049
+ return h("div", { className: native ? "ima-native ima-rail" : "dcu-wb ima-rail" },
1050
+ h("style", null, WB_CSS),
1051
+ h("div", { className: native ? "ima-native-tree" : "dcu-wb-tree", role: "tree" },
1052
+ error && h("div", { className: native ? "ima-native-empty" : "dcu-wb-empty" }, error),
1053
+ !error && groups.length === 0 && h("div", { className: native ? "ima-native-empty" : "dcu-wb-empty" }, "还没有频道会话。先在设置 → IM助理 里连接渠道,并给机器人发一条消息。"),
1054
+ ...groups.map((g) => {
1055
+ const visible = (g.sessions || []).filter((sess) => !archived.has(sess.sessionId));
1056
+ if (!visible.length) return null;
1057
+ const expanded = !folded[g.id];
1058
+ return h("div", { key: g.id, className: native ? "ima-native-project" : "dcu-wb-project" },
1059
+ h("button", {
1060
+ className: native ? "ima-n-row" : "dcu-wb-project-head",
1061
+ type: "button",
1062
+ role: "treeitem",
1063
+ "aria-expanded": expanded,
1064
+ onClick: () => setFolded({ ...folded, [g.id]: !folded[g.id] }),
1065
+ },
1066
+ native
1067
+ ? [
1068
+ h("span", { key: "folder", className: "ima-n-slot ima-n-folder" }, expanded ? h(IconFolderOpen) : h(IconFolderClose)),
1069
+ h("span", { key: "chev", className: "ima-n-slot ima-n-chevron" }, h("span", { className: expanded ? "ima-n-arrow open" : "ima-n-arrow" }, h(IconChevron))),
1070
+ h("span", { key: "title", className: "ima-n-title" }, g.label),
1071
+ ]
1072
+ : [
1073
+ h("span", { key: "folder", className: "dcu-wb-folder" }, h(Logo, { id: g.id, small: true })),
1074
+ h("span", { key: "title", className: "dcu-wb-project-title" }, g.label),
1075
+ ],
1076
+ ),
1077
+ !folded[g.id] && (visible.length
1078
+ ? visible.map((sess) => h(ChannelSessionRow, {
1079
+ key: sess.sessionId,
1080
+ sess,
1081
+ selected: selectedId === sess.sessionId,
1082
+ sessionById: props.sessionById,
1083
+ onOpen: open,
1084
+ onChanged: (next) => setGroups(next),
1085
+ skin,
1086
+ sessionActions: {
1087
+ renameSession: props.renameSession,
1088
+ archiveSession: props.archiveSession,
1089
+ deleteSession: props.deleteSession,
1090
+ forkSession: props.forkSession,
1091
+ openPath: props.openPath,
1092
+ },
1093
+ }))
1094
+ : h("div", { className: native ? "ima-native-empty" : "dcu-wb-empty" }, "暂无会话")),
1095
+ );
1096
+ }),
1097
+ ),
1098
+ );
1099
+ }
1100
+
1101
+ function isTaskSessionItem(item) {
1102
+ if (!item) return false;
1103
+ if (item.blank) return false;
1104
+ if (item.origin === "im" || item.origin === "subagent") return false;
1105
+ return !String(item.id || "").startsWith("im:");
1106
+ }
1107
+
1108
+ function TaskList(props) {
1109
+ if (typeof props.useSessions === "function") return h(TaskListWithSessions, props);
1110
+ return h(TaskListView, { groups: [], current: null, openSession: props.openSession });
1111
+ }
1112
+
1113
+ function TaskListWithSessions(props) {
1114
+ const snap = props.useSessions((state) => state || { ids: [], byId: {}, current: null });
1115
+ const workspaces = typeof props.useWorkspaces === "function"
1116
+ ? props.useWorkspaces((state) => state || { items: [], archivedSessionIds: [] })
1117
+ : { items: [], archivedSessionIds: [] };
1118
+ const archived = new Set(workspaces.archivedSessionIds || []);
1119
+ const assigned = new Set();
1120
+ const groups = [];
1121
+ for (const ws of workspaces.items || []) {
1122
+ const sessions = (ws.sessionIds || [])
1123
+ .map((id) => snap.byId[id])
1124
+ .filter((item) => isTaskSessionItem(item) && !archived.has(item.id));
1125
+ sessions.forEach((item) => assigned.add(item.id));
1126
+ if (sessions.length) {
1127
+ groups.push({ id: ws.workspaceId || ws.id, label: ws.title || ws.path || "工作区", sessions });
1128
+ }
1129
+ }
1130
+ const ungrouped = (snap.ids || [])
1131
+ .map((id) => snap.byId[id])
1132
+ .filter((item) => item && !assigned.has(item.id) && isTaskSessionItem(item) && !archived.has(item.id));
1133
+ if (ungrouped.length) groups.push({ id: "", label: "未分组", sessions: ungrouped });
1134
+ return h(TaskListView, { groups, current: snap.current, openSession: props.openSession });
1135
+ }
1136
+
1137
+ function TaskListView({ groups, current, openSession }) {
1138
+ if (!groups.length) return h("div", { className: "ima-empty" }, "暂无网页任务");
1139
+ return h("div", { className: "ima-native ima-rail" },
1140
+ h("div", { className: "ima-native-tree" },
1141
+ ...groups.map((group) => h("div", { key: group.id || "ungrouped", className: "ima-native-project" },
1142
+ h("div", { className: "ima-native-head" },
1143
+ h("span", { className: "ima-native-title" }, group.label),
1144
+ ),
1145
+ ...group.sessions.map((item) => h("div", {
1146
+ key: item.id,
1147
+ className: current === item.id ? "ima-native-session on" : "ima-native-session",
1148
+ role: "treeitem",
1149
+ tabIndex: 0,
1150
+ onClick: () => openSession && openSession(item.id),
1151
+ onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); openSession && openSession(item.id); } },
1152
+ }, h("span", { className: "ima-native-title" }, item.title || item.id))),
1153
+ )),
1154
+ ),
1155
+ );
1156
+ }
1157
+
1158
+ function filterSessionsByIm(state, keepIm) {
1159
+ const src = state || { ids: [], byId: {}, current: null };
1160
+ const ids = (src.ids || []).filter((id) => String(id).startsWith("im:") === keepIm);
1161
+ const byId = {};
1162
+ for (const id of ids) {
1163
+ if (src.byId && src.byId[id]) byId[id] = src.byId[id];
1164
+ }
1165
+ return Object.assign({}, src, { ids, byId });
1166
+ }
1167
+
1168
+ function filterTaskSessions(state) {
1169
+ return filterSessionsByIm(state, false);
1170
+ }
1171
+
1172
+ function filterChannelSessions(state) {
1173
+ return filterSessionsByIm(state, true);
1174
+ }
1175
+
1176
+ function createNativeTabRegistry(officialTree) {
1177
+ const tabs = new Map();
1178
+ const sessionFilters = [];
1179
+ const listeners = new Set();
1180
+ let cachedTabs = [];
1181
+ const rebuild = () => { cachedTabs = [...tabs.values()].sort((a, b) => (a.order || 0) - (b.order || 0)); };
1182
+ const emit = () => { for (const listener of listeners) listener(); };
1183
+ return {
1184
+ version: 1,
1185
+ officialTree,
1186
+ sessionFilters,
1187
+ getTabs() { return cachedTabs; },
1188
+ subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
1189
+ insert(tab) {
1190
+ if (!tab || !tab.id) return () => {};
1191
+ tabs.set(tab.id, tab);
1192
+ rebuild();
1193
+ emit();
1194
+ return () => { tabs.delete(tab.id); rebuild(); emit(); };
1195
+ },
1196
+ addSessionFilter(filter) {
1197
+ sessionFilters.push(filter);
1198
+ emit();
1199
+ return () => {
1200
+ const index = sessionFilters.indexOf(filter);
1201
+ if (index >= 0) sessionFilters.splice(index, 1);
1202
+ emit();
1203
+ };
1204
+ },
1205
+ };
1206
+ }
1207
+
1208
+ function attachNativeTabRegistry(target, registry) {
1209
+ try { target.__dshNativeTabs = registry; } catch { /* ignore */ }
1210
+ return registry;
1211
+ }
1212
+
1213
+ function findNativeTabRegistry(entry) {
1214
+ return entry?.__dshNativeTabs || entry?.component?.__dshNativeTabs || null;
1215
+ }
1216
+
1217
+ function applyRegistryFilters(state, registry) {
1218
+ const src = state || { ids: [], byId: {}, current: null };
1219
+ const filters = registry && registry.sessionFilters ? registry.sessionFilters : [];
1220
+ if (!filters.length) return src;
1221
+ const ids = (src.ids || []).filter((id) => filters.every((fn) => fn(String(id))));
1222
+ const byId = {};
1223
+ for (const id of ids) {
1224
+ if (src.byId && src.byId[id]) byId[id] = src.byId[id];
1225
+ }
1226
+ return Object.assign({}, src, { ids, byId });
1227
+ }
1228
+
1229
+ function SessionSwitcher(props) {
1230
+ const Official = props.officialTree;
1231
+ const rawUseSessions = props.useSessions;
1232
+ const nativeTabs = props.nativeTabs;
1233
+ const extraTabs = useSyncExternalStore(
1234
+ (listener) => (nativeTabs && nativeTabs.subscribe ? nativeTabs.subscribe(listener) : () => {}),
1235
+ () => (nativeTabs && nativeTabs.getTabs ? nativeTabs.getTabs() : EMPTY_EXTRA_TABS),
1236
+ () => EMPTY_EXTRA_TABS,
1237
+ );
1238
+ const [tab, setTab] = useState(() => {
1239
+ try { return localStorage.getItem(TAB_KEY) || "tasks"; } catch { return "tasks"; }
1240
+ });
1241
+ const currentId = typeof rawUseSessions === "function"
1242
+ ? rawUseSessions((state) => (state && state.current) || null)
1243
+ : (props.selectedId || null);
1244
+ const useTaskSessions = useCallback((selector) => {
1245
+ if (typeof rawUseSessions !== "function") return selector({ ids: [], byId: {}, current: null });
1246
+ return rawUseSessions((state) => selector(applyRegistryFilters(filterTaskSessions(state), nativeTabs)));
1247
+ }, [rawUseSessions, nativeTabs]);
1248
+ const useChannelSessions = useCallback((selector) => {
1249
+ if (typeof rawUseSessions !== "function") return selector({ ids: [], byId: {}, current: null });
1250
+ return rawUseSessions((state) => selector(filterChannelSessions(state)));
1251
+ }, [rawUseSessions]);
1252
+ useEffect(() => { ensureStyle(); }, []);
1253
+ useEffect(() => { try { localStorage.setItem(TAB_KEY, tab); } catch { /* ignore */ } }, [tab]);
1254
+ useEffect(() => {
1255
+ if (typeof currentId === "string" && currentId.startsWith("im:")) setTab("channels");
1256
+ if (typeof currentId === "string") {
1257
+ const matched = extraTabs.find((item) => item.matchSession && item.matchSession(currentId));
1258
+ if (matched) setTab(matched.id);
1259
+ }
1260
+ }, [currentId, extraTabs]);
1261
+ const openSession = (id) => openListedSession(id, props.openSession || props.open);
1262
+ const officialProps = Object.assign({}, props, { useSessions: useTaskSessions });
1263
+ const channelRail = h(ChannelRail, {
1264
+ openSession,
1265
+ open: openSession,
1266
+ useSessions: rawUseSessions,
1267
+ useWorkspaces: props.useWorkspaces,
1268
+ selectedId: currentId || props.selectedId || null,
1269
+ skin: "native",
1270
+ renameSession: props.renameSession,
1271
+ archiveSession: props.archiveSession,
1272
+ deleteSession: props.deleteSession,
1273
+ forkSession: props.forkSession,
1274
+ openPath: props.openPath,
1275
+ });
1276
+ if (props.wide === false) return Official ? h(Official, officialProps) : null;
1277
+ const officialTree = Official
1278
+ ? h("div", { className: "ima-official-tree" }, h(Official, officialProps))
1279
+ : null;
1280
+ const extra = extraTabs.find((item) => item.id === tab);
1281
+ return h("div", { className: "ima-wrap" },
1282
+ h("div", { className: "ima-tabs", role: "tablist", "aria-label": "工作区分类" },
1283
+ h("button", { type: "button", role: "tab", "aria-selected": tab === "tasks", className: tab === "tasks" ? "ima-tab on" : "ima-tab", onClick: () => setTab("tasks") }, "任务"),
1284
+ h("button", { type: "button", role: "tab", "aria-selected": tab === "channels", className: tab === "channels" ? "ima-tab on" : "ima-tab", onClick: () => setTab("channels") }, "频道"),
1285
+ ...extraTabs.map((item) => h("button", {
1286
+ key: item.id,
1287
+ type: "button",
1288
+ role: "tab",
1289
+ "aria-selected": tab === item.id,
1290
+ className: tab === item.id ? "ima-tab on" : "ima-tab",
1291
+ onClick: () => setTab(item.id),
1292
+ }, item.label)),
1293
+ ),
1294
+ tab === "tasks"
1295
+ ? (officialTree || h(TaskList, { useSessions: useTaskSessions, useWorkspaces: props.useWorkspaces, openSession }))
1296
+ : extra
1297
+ ? extra.render(Object.assign({}, props, { openSession, open: openSession }))
1298
+ : channelRail,
1299
+ );
1300
+ }
1301
+
1302
+ function sidebarOccupantName(item) {
1303
+ return String(
1304
+ item?.options?.locale ??
1305
+ item?.options?.id ??
1306
+ item?.options?.name ??
1307
+ item?.options?.registrant ??
1308
+ item?.component?.displayName ??
1309
+ item?.component?.name ??
1310
+ item?.id ??
1311
+ item?.name ??
1312
+ "",
1313
+ );
1314
+ }
1315
+
1316
+ /** 只认真正占用 sidebar 槽的主人。包在注册表里但没接管侧栏时,必须走原生页签。 */
1317
+ function hasDshCodexUiSidebar(ctx) {
1318
+ try {
1319
+ const read = ctx.slots && (ctx.slots.entriesOfSlot || ctx.slots.entries);
1320
+ const sidebar = read && read.call(ctx.slots, "sidebar");
1321
+ if (!sidebar) return false;
1322
+ for (const item of sidebar) {
1323
+ if (/dsh-codex-ui|michengai-codex-ui|michengai\.codexUi|codex-ui/i.test(sidebarOccupantName(item))) return true;
1324
+ }
1325
+ } catch { /* ignore */ }
1326
+ return false;
1327
+ }
1328
+
1329
+ function pickOfficialWorkspaces(ctx) {
1330
+ const entries = (ctx.slots.entries && ctx.slots.entries("sidebar.workspaces")) || [];
1331
+ for (const item of entries) {
1332
+ if (!item || !item.component) continue;
1333
+ if (item.component.__imConnectWrapped) continue;
1334
+ if (item.component.__imConnectOriginal) continue;
1335
+ if (item.component.__dshNativeTabHost) continue;
1336
+ if (item.component.__dshAutomationWrapped) continue;
1337
+ return item;
1338
+ }
1339
+ return null;
1340
+ }
1341
+
1342
+ function apply(ctx) {
1343
+ ensureStyle();
1344
+ openImSession = (id) => {
1345
+ try { ctx.sessions.open(id); return true; }
1346
+ catch (error) { console.warn("[dsh-im-connect] 无法打开会话", id, error); return false; }
1347
+ };
1348
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
1349
+ name: "settings.section",
1350
+ id: "im-assistant",
1351
+ order: 28,
1352
+ label: "IM助理",
1353
+ icon: "chat",
1354
+ inject: () => ({
1355
+ createWorkspace: (input) => ctx.workspaces.create(input),
1356
+ pickDirectory: () => ctx.workspaces.pickDirectory(),
1357
+ }),
1358
+ }, SettingsPage));
1359
+
1360
+ ctx.slots.inject("sidebar.channels", () => ctx.slots.register({
1361
+ name: "sidebar.channels",
1362
+ id: "im-connect-channels",
1363
+ inject: () => ({
1364
+ openSession: (id) => { ctx.sessions.open(id); },
1365
+ open: (id) => { ctx.sessions.open(id); },
1366
+ archiveSession: (id) => ctx.workspaces.archiveSession(id),
1367
+ forkSession: (id) => {
1368
+ ctx.sessions.fork({ sessionId: id, increaseTitle: true })
1369
+ .then((childId) => { ctx.sessions.open(childId); })
1370
+ .catch(() => undefined);
1371
+ },
1372
+ renameSession: async (sessionId, title) => {
1373
+ const session = ctx.sessions.binding && ctx.sessions.binding(sessionId)?.session;
1374
+ if (!session) throw new Error("unknown session");
1375
+ const result = await session.rename(title);
1376
+ if (!result.ok) throw new Error(result.error.message);
1377
+ },
1378
+ }),
1379
+ }, ChannelRail));
1380
+
1381
+ // 只包一层官方任务树,绝不在通知回调里再 register,否则会把启动卡在 Loading plugins。
1382
+ ctx.slots.inject("sidebar.workspaces", () => {
1383
+ let wrappedEntry = null;
1384
+ let originalComp = null;
1385
+ let removeInsertedTab = () => {};
1386
+ let syncing = false;
1387
+ const unwrap = () => {
1388
+ removeInsertedTab();
1389
+ removeInsertedTab = () => {};
1390
+ if (wrappedEntry && originalComp) {
1391
+ try { wrappedEntry.component = originalComp; } catch { /* ignore */ }
1392
+ }
1393
+ wrappedEntry = null;
1394
+ originalComp = null;
1395
+ };
1396
+ const insertChannelTab = (entry) => {
1397
+ const registry = findNativeTabRegistry(entry);
1398
+ if (!registry) return false;
1399
+ if (registry.getTabs().some((item) => item.id === "channels")) return true;
1400
+ removeInsertedTab();
1401
+ removeInsertedTab = registry.insert({
1402
+ id: "channels",
1403
+ label: "频道",
1404
+ order: 20,
1405
+ matchSession: (id) => String(id).startsWith("im:"),
1406
+ render: (props) => h(ChannelRail, Object.assign({}, props, {
1407
+ skin: "native",
1408
+ openSession: (id) => openListedSession(id, props.openSession || props.open),
1409
+ open: (id) => openListedSession(id, props.openSession || props.open),
1410
+ })),
1411
+ });
1412
+ return true;
1413
+ };
1414
+ const sync = () => {
1415
+ if (syncing) return;
1416
+ syncing = true;
1417
+ try {
1418
+ const combo = hasDshCodexUiSidebar(ctx);
1419
+ channelSkin = combo ? "codex" : "native";
1420
+ if (combo) {
1421
+ unwrap();
1422
+ return;
1423
+ }
1424
+ const entries = (ctx.slots.entries && ctx.slots.entries("sidebar.workspaces")) || [];
1425
+ const occupant = entries.find((item) => item && item.component);
1426
+ if (occupant && (occupant.component.__dshNativeTabHost || occupant.component.__dshAutomationWrapped || findNativeTabRegistry(occupant))) {
1427
+ insertChannelTab(occupant);
1428
+ return;
1429
+ }
1430
+ if (wrappedEntry && wrappedEntry.component && wrappedEntry.component.__imConnectWrapped) {
1431
+ insertChannelTab(wrappedEntry);
1432
+ return;
1433
+ }
1434
+ const official = pickOfficialWorkspaces(ctx);
1435
+ if (!official || official.component.__imConnectWrapped || official.component.__dshNativeTabHost) return;
1436
+ originalComp = official.component;
1437
+ const registry = createNativeTabRegistry(originalComp);
1438
+ attachNativeTabRegistry(official, registry);
1439
+ function ImNativeWorkspaceShell(innerProps) {
1440
+ return h(SessionSwitcher, Object.assign({}, innerProps, { officialTree: originalComp, nativeTabs: registry }));
1441
+ }
1442
+ ImNativeWorkspaceShell.displayName = "ImNativeWorkspaceShell";
1443
+ ImNativeWorkspaceShell.__imConnectWrapped = true;
1444
+ ImNativeWorkspaceShell.__imConnectOriginal = originalComp;
1445
+ ImNativeWorkspaceShell.__dshNativeTabHost = true;
1446
+ attachNativeTabRegistry(ImNativeWorkspaceShell, registry);
1447
+ official.component = ImNativeWorkspaceShell;
1448
+ wrappedEntry = official;
1449
+ } catch (error) {
1450
+ console.warn("[dsh-im-connect] 包裹官方任务树失败", error);
1451
+ } finally {
1452
+ syncing = false;
1453
+ }
1454
+ };
1455
+ sync();
1456
+ const unsub = typeof ctx.slots.subscribe === "function" ? ctx.slots.subscribe("sidebar.workspaces", sync) : () => {};
1457
+ return () => { unsub(); unwrap(); };
1458
+ });
1459
+ }
1460
+
1461
+ exports.apply = apply;
1462
+ exports.inject = inject;
1463
+ return module.exports;
1464
+ },
1465
+ });
1466
+
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+