dsh-plugin-dingtalk-bridge 0.0.0-stage → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +183 -2
- package/client.js +2519 -0
- package/cordis.patch.yml +23 -0
- package/docs/images/auth-device.png +0 -0
- package/docs/images/auth-loopback.png +0 -0
- package/docs/images/auth-qr.png +0 -0
- package/docs/images/confirm-modal.png +0 -0
- package/docs/images/duplicate-hint.png +0 -0
- package/docs/images/group-at-reply.png +0 -0
- package/docs/images/help-view.png +0 -0
- package/docs/images/icon-source.png +0 -0
- package/docs/images/icon.png +0 -0
- package/docs/images/inbox-panel.png +0 -0
- package/docs/images/inbox-real.png +0 -0
- package/docs/images/settings.png +0 -0
- package/docs/images/sources-collapsed.png +0 -0
- package/docs/images/sources-expanded.png +0 -0
- package/docs/images/window-setting.png +0 -0
- package/docs//344/275/277/347/224/250/350/257/264/346/230/216.md +1841 -0
- package/icon-128.png +0 -0
- package/icon-64.png +0 -0
- package/icon.png +0 -0
- package/icon.svg +6 -0
- package/index.js +37 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +78 -4
- package/src/host/config.js +147 -0
- package/src/host/dws.js +277 -0
- package/src/host/service.js +2352 -0
- package/src/host/suggest.js +307 -0
package/client.js
ADDED
|
@@ -0,0 +1,2519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 钉钉消息自动化 —— Web 客户端。
|
|
3
|
+
*
|
|
4
|
+
* 槽位:
|
|
5
|
+
* - sidebar.panellist : 侧边栏图标入口
|
|
6
|
+
* - main : 收件箱页面(自动回复开关 / 消息卡片 / 逐条建议回复)
|
|
7
|
+
* - shell.overlay : 全局待确认弹框(「有 xxx 发送的 xxx 消息」)
|
|
8
|
+
* - settings.section : 设置页说明
|
|
9
|
+
* - plugins.bundle.config : 插件配置卡片
|
|
10
|
+
*
|
|
11
|
+
* 实时链路:宿主 /api/dingtalk-bridge/events 的 SSE 推送,断线后自动重连并降级为轮询。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: 'dsh-plugin-dingtalk-bridge',
|
|
16
|
+
factory(require) {
|
|
17
|
+
const React = require('react')
|
|
18
|
+
const h = React.createElement
|
|
19
|
+
const { useState, useEffect, useMemo, useRef, useCallback } = React
|
|
20
|
+
|
|
21
|
+
const API = '/api/dingtalk-bridge'
|
|
22
|
+
const PACKAGE_NAME = 'dsh-plugin-dingtalk-bridge'
|
|
23
|
+
const PANEL_KEY = 'dingtalk-inbox'
|
|
24
|
+
const POLL_MS = 5000
|
|
25
|
+
const SOFT_POLL_MS = 30000
|
|
26
|
+
// 与 package.json 的 version 保持一致:宿主上报的 build 前缀对不上,说明 DSH 还在跑旧宿主代码。
|
|
27
|
+
const CLIENT_BUILD = '0.3.3'
|
|
28
|
+
// 源码仓库(GitHub):Star 与 Issue 入口都指向这里
|
|
29
|
+
const REPO_URL = 'https://github.com/gcggcg/dsh-plugin-dingtalk-bridge'
|
|
30
|
+
const ISSUES_URL = `${REPO_URL}/issues`
|
|
31
|
+
const NPM_URL = 'https://www.npmjs.com/package/dsh-plugin-dingtalk-bridge'
|
|
32
|
+
|
|
33
|
+
function openExternal(url) {
|
|
34
|
+
try {
|
|
35
|
+
window.open(url, '_blank', 'noopener,noreferrer')
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// 浏览器拦截弹窗时退化为同页跳转
|
|
38
|
+
try {
|
|
39
|
+
window.location.href = url
|
|
40
|
+
} catch (ignored) {
|
|
41
|
+
/* 忽略:无 window 环境(测试) */
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ------------------------------------------------------------------ 设计令牌
|
|
47
|
+
|
|
48
|
+
const C = {
|
|
49
|
+
bg: 'var(--dsw-alias-bg-base, #ffffff)',
|
|
50
|
+
layer1: 'var(--dsw-alias-bg-layer-1, #ffffff)',
|
|
51
|
+
layer2: 'var(--dsw-alias-bg-layer-2, #f5f6f8)',
|
|
52
|
+
overlay: 'var(--dsw-alias-bg-overlay, #ffffff)',
|
|
53
|
+
border1: 'var(--dsw-alias-border-l1, #ececf0)',
|
|
54
|
+
border2: 'var(--dsw-alias-border-l2, #dcdee4)',
|
|
55
|
+
brand: 'var(--dsw-alias-brand-primary, #2e7cf6)',
|
|
56
|
+
text: 'var(--dsw-alias-label-primary, #1b1e23)',
|
|
57
|
+
sub: 'var(--dsw-alias-label-secondary, #6b7280)',
|
|
58
|
+
error: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
59
|
+
idle: 'var(--dsw-alias-state-idle-primary, #9aa0aa)',
|
|
60
|
+
success: 'var(--dsw-alias-state-success-primary, #12a150)',
|
|
61
|
+
warn: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
62
|
+
sidebarFill: 'var(--dsw-specific-sidebar-fill, #f7f8fa)',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const STYLES = `
|
|
66
|
+
.dsh-dt-root{height:100%;display:flex;flex-direction:column;background:${C.bg};color:${C.text};
|
|
67
|
+
font-family:inherit;font-size:13px;overflow:hidden;letter-spacing:.2px}
|
|
68
|
+
.dsh-dt-header{display:flex;align-items:center;gap:12px;padding:14px 20px 12px;border-bottom:1px solid ${C.border1};
|
|
69
|
+
background:linear-gradient(180deg, rgba(46,124,246,.045), rgba(46,124,246,0))}
|
|
70
|
+
.dsh-dt-title{font-size:15px;font-weight:650;letter-spacing:.2px;display:flex;align-items:center;gap:8px}
|
|
71
|
+
.dsh-dt-sub{font-size:11.5px;color:${C.sub};display:flex;align-items:center;gap:6px;margin-top:2px;flex-wrap:wrap}
|
|
72
|
+
.dsh-dt-spacer{flex:1}
|
|
73
|
+
.dsh-dt-footnote{font-size:11.5px;color:${C.sub};opacity:.85;white-space:nowrap}
|
|
74
|
+
.dsh-dt-links{display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin-top:14px;padding-top:12px;
|
|
75
|
+
border-top:1px dashed ${C.border1};font-size:12px;color:${C.sub}}
|
|
76
|
+
.dsh-dt-links a{color:${C.brand};text-decoration:none;display:inline-flex;align-items:center;gap:4px}
|
|
77
|
+
.dsh-dt-links a:hover{text-decoration:underline}
|
|
78
|
+
.dsh-dt-toolbar{display:flex;align-items:center;gap:10px;padding:10px 20px;flex-wrap:wrap;
|
|
79
|
+
border-bottom:1px solid ${C.border1};background:${C.bg}}
|
|
80
|
+
.dsh-dt-tabs{display:flex;gap:2px;padding:2px;background:${C.layer2};border-radius:9px;border:1px solid ${C.border1}}
|
|
81
|
+
.dsh-dt-tab{appearance:none;border:0;background:transparent;color:${C.sub};font:inherit;font-size:12px;
|
|
82
|
+
padding:5px 10px;border-radius:7px;cursor:pointer;display:flex;align-items:center;gap:5px;transition:.14s}
|
|
83
|
+
.dsh-dt-tab:hover{color:${C.text}}
|
|
84
|
+
.dsh-dt-tab[data-active="1"]{background:${C.layer1};color:${C.text};box-shadow:0 1px 2px rgba(16,24,40,.1);font-weight:600}
|
|
85
|
+
.dsh-dt-count{font-size:10px;min-width:16px;text-align:center;padding:0 4px;border-radius:999px;
|
|
86
|
+
background:rgba(46,124,246,.12);color:${C.brand};line-height:15px}
|
|
87
|
+
.dsh-dt-search{flex:1;min-width:130px;display:flex;align-items:center;gap:6px;padding:0 10px;height:32px;
|
|
88
|
+
border:1px solid ${C.border1};border-radius:9px;background:${C.layer2};transition:.15s}
|
|
89
|
+
.dsh-dt-search:focus-within{border-color:${C.brand};background:${C.layer1};box-shadow:0 0 0 3px rgba(46,124,246,.12)}
|
|
90
|
+
.dsh-dt-search input{flex:1;border:0;outline:0;background:transparent;color:${C.text};font:inherit;font-size:12.5px}
|
|
91
|
+
.dsh-dt-autocfg{display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin:12px 20px 0;padding:12px 14px;border-radius:13px;
|
|
92
|
+
border:1px solid ${C.border1};background:linear-gradient(135deg, rgba(46,124,246,.08), rgba(23,176,240,.05));
|
|
93
|
+
transition:.16s}
|
|
94
|
+
.dsh-dt-autocfg[data-on="1"]{border-color:rgba(46,124,246,.4);box-shadow:0 4px 18px rgba(46,124,246,.12)}
|
|
95
|
+
.dsh-dt-autocfg-title{font-size:12.8px;font-weight:620;display:flex;align-items:center;gap:7px}
|
|
96
|
+
.dsh-dt-autocfg-desc{font-size:11.5px;color:${C.sub};margin-top:3px;line-height:1.5}
|
|
97
|
+
.dsh-dt-autocfg-extra{width:100%;display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin-top:11px;padding-top:11px;
|
|
98
|
+
border-top:1px dashed ${C.border2}}
|
|
99
|
+
.dsh-dt-range{-webkit-appearance:none;appearance:none;width:168px;height:20px;background:transparent;
|
|
100
|
+
outline:none;cursor:pointer;padding:0;margin:0}
|
|
101
|
+
.dsh-dt-range::-webkit-slider-runnable-track{height:5px;border-radius:99px;background:${C.border2}}
|
|
102
|
+
.dsh-dt-range::-moz-range-track{height:5px;border-radius:99px;background:${C.border2}}
|
|
103
|
+
.dsh-dt-range:disabled{opacity:.45;cursor:default}
|
|
104
|
+
.dsh-dt-range::-webkit-slider-thumb{-webkit-appearance:none;width:15px;height:15px;border-radius:50%;margin-top:-5px;
|
|
105
|
+
background:${C.brand};border:2px solid ${C.layer1};box-shadow:0 1px 4px rgba(16,24,40,.28)}
|
|
106
|
+
.dsh-dt-range::-moz-range-thumb{width:13px;height:13px;border-radius:50%;background:${C.brand};
|
|
107
|
+
border:2px solid ${C.layer1};box-shadow:0 1px 4px rgba(16,24,40,.28)}
|
|
108
|
+
.dsh-dt-range:active::-webkit-slider-thumb{width:17px;height:17px;margin-top:-6px;
|
|
109
|
+
box-shadow:0 2px 8px rgba(16,24,40,.34)}
|
|
110
|
+
.dsh-dt-range:active::-moz-range-thumb{width:15px;height:15px}
|
|
111
|
+
.dsh-dt-range:focus-visible{box-shadow:0 0 0 3px rgba(46,124,246,.22);border-radius:99px}
|
|
112
|
+
.dsh-dt-ticks{display:flex;justify-content:space-between;width:168px;font-size:10px;color:${C.sub};opacity:.7;
|
|
113
|
+
font-variant-numeric:tabular-nums;margin-top:-2px}
|
|
114
|
+
.dsh-dt-select{appearance:none;-webkit-appearance:none;font-size:12px;line-height:18px;padding:4px 24px 4px 9px;
|
|
115
|
+
border-radius:8px;border:1px solid ${C.border1};background:${C.bg} url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888f9c' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 8px center;
|
|
116
|
+
color:${C.text};font-variant-numeric:tabular-nums;cursor:pointer;transition:border-color .15s}
|
|
117
|
+
.dsh-dt-select:hover{border-color:${C.border2}}
|
|
118
|
+
.dsh-dt-select:focus-visible{outline:none;border-color:${C.brand};box-shadow:0 0 0 3px rgba(46,124,246,.18)}
|
|
119
|
+
.dsh-dt-conf{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:1px 8px;border-radius:999px;
|
|
120
|
+
border:1px solid transparent;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
121
|
+
.dsh-dt-conf[data-tone="high"]{color:${C.success};background:rgba(18,161,80,.1);border-color:rgba(18,161,80,.25)}
|
|
122
|
+
.dsh-dt-conf[data-tone="mid"]{color:${C.warn};background:rgba(245,165,36,.12);border-color:rgba(245,165,36,.3)}
|
|
123
|
+
.dsh-dt-conf[data-tone="low"]{color:${C.error};background:rgba(229,72,77,.1);border-color:rgba(229,72,77,.26)}
|
|
124
|
+
.dsh-dt-imgs{display:flex;flex-wrap:wrap;gap:8px;margin:9px 0 2px}
|
|
125
|
+
.dsh-dt-img{width:104px;height:104px;border-radius:10px;border:1px solid ${C.border1};background:${C.layer2};
|
|
126
|
+
display:flex;align-items:center;justify-content:center;overflow:hidden;text-decoration:none;
|
|
127
|
+
font-size:11px;color:${C.sub};transition:border-color .14s,transform .14s}
|
|
128
|
+
.dsh-dt-img img{width:100%;height:100%;object-fit:cover;display:block}
|
|
129
|
+
.dsh-dt-img:hover{border-color:${C.brand};transform:translateY(-1px)}
|
|
130
|
+
.dsh-dt-img[data-state="failed"]{color:${C.error};border-style:dashed}
|
|
131
|
+
.dsh-dt-qr{width:150px;height:150px;border-radius:12px;background:#fff;border:1px solid ${C.border1};padding:7px;
|
|
132
|
+
display:block;margin:0 auto}
|
|
133
|
+
.dsh-dt-qrwrap{display:flex;flex-direction:column;align-items:center;gap:7px;width:100%}
|
|
134
|
+
.dsh-dt-auth{display:flex;gap:11px;align-items:flex-start;padding:13px;border-radius:12px;background:${C.layer2};
|
|
135
|
+
border:1px solid ${C.border1}}
|
|
136
|
+
.dsh-dt-auth-icon{width:26px;height:26px;border-radius:9px;flex:0 0 auto;display:flex;align-items:center;
|
|
137
|
+
justify-content:center;font-size:13px;font-weight:700;color:#fff;background:${C.brand}}
|
|
138
|
+
.dsh-dt-modelchip{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;padding:4px 9px;border-radius:8px;
|
|
139
|
+
background:${C.layer2};border:1px solid ${C.border1};color:${C.sub};max-width:100%;overflow:hidden}
|
|
140
|
+
.dsh-dt-modelchip b{color:${C.text};font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
141
|
+
.dsh-dt-modal-code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:21px;letter-spacing:4px;
|
|
142
|
+
font-weight:700;padding:13px 10px;border-radius:12px;background:${C.layer2};border:1px dashed ${C.border2};
|
|
143
|
+
color:${C.text};text-align:center;user-select:all}
|
|
144
|
+
.dsh-dt-modal-link{font-size:11.5px;color:${C.brand};word-break:break-all;text-decoration:none;line-height:1.5}
|
|
145
|
+
.dsh-dt-sources{display:flex;align-items:center;gap:7px;padding:10px 20px 2px;overflow:hidden;flex-wrap:nowrap}
|
|
146
|
+
.dsh-dt-src{display:flex;align-items:center;gap:6px;white-space:nowrap;font-size:11.5px;padding:4px 9px;
|
|
147
|
+
border-radius:999px;border:1px solid ${C.border1};background:${C.layer1};color:${C.sub};cursor:pointer;transition:.14s;
|
|
148
|
+
max-width:220px;overflow:hidden;text-overflow:ellipsis}
|
|
149
|
+
.dsh-dt-src:hover{border-color:${C.border2};color:${C.text}}
|
|
150
|
+
.dsh-dt-src[data-active="1"]{border-color:${C.brand};color:${C.brand};background:rgba(46,124,246,.08);font-weight:600}
|
|
151
|
+
.dsh-dt-src[data-more="1"]{border-style:dashed;color:${C.brand};border-color:rgba(46,124,246,.4);background:rgba(46,124,246,.05)}
|
|
152
|
+
.dsh-dt-srcname{overflow:hidden;text-overflow:ellipsis}
|
|
153
|
+
.dsh-dt-srcpanel{margin:8px 20px 10px;padding:10px 12px 12px;border:1px solid ${C.border1};border-radius:12px;
|
|
154
|
+
background:${C.layer2};display:flex;flex-direction:column;gap:9px}
|
|
155
|
+
.dsh-dt-srcpanel-head{display:flex;align-items:center;gap:8px;font-size:11.5px;color:${C.sub}}
|
|
156
|
+
.dsh-dt-srcpanel-body{display:flex;flex-wrap:wrap;gap:7px;max-height:126px;overflow-y:auto;padding-right:2px}
|
|
157
|
+
.dsh-dt-srcsearch{flex:1;min-width:120px;font-size:11.5px;padding:4px 9px;border-radius:8px;
|
|
158
|
+
border:1px solid ${C.border1};background:${C.layer1};color:${C.text};outline:none}
|
|
159
|
+
.dsh-dt-srcsearch:focus{border-color:${C.brand}}
|
|
160
|
+
.dsh-dt-notice{margin:0 20px 8px;padding:8px 12px;border-radius:10px;border:1px dashed ${C.border2};
|
|
161
|
+
background:${C.layer2};color:${C.sub};font-size:12px;display:flex;align-items:center;gap:6px}
|
|
162
|
+
.dsh-dt-listbox{margin:0 20px 16px;border:1px solid ${C.border1};border-radius:14px;background:${C.layer1};
|
|
163
|
+
box-shadow:0 1px 2px rgba(16,24,40,.04);display:flex;flex-direction:column;
|
|
164
|
+
height:calc(100vh - 330px);min-height:340px;max-height:900px;overflow:hidden}
|
|
165
|
+
.dsh-dt-listbox[data-empty="1"]{background:transparent;border-style:dashed;box-shadow:none}
|
|
166
|
+
.dsh-dt-helpbox{margin:12px 20px 16px;border:1px solid ${C.border1};border-radius:14px;background:${C.layer1};
|
|
167
|
+
box-shadow:0 1px 2px rgba(16,24,40,.04);height:calc(100vh - 430px);min-height:320px;max-height:1000px;
|
|
168
|
+
overflow-y:auto;padding:0 16px 18px}
|
|
169
|
+
.dsh-dt-helpbox::-webkit-scrollbar{width:9px}
|
|
170
|
+
.dsh-dt-helpbox::-webkit-scrollbar-thumb{background:${C.border2};border-radius:6px;border:2px solid ${C.layer1}}
|
|
171
|
+
.dsh-dt-helpbox::-webkit-scrollbar-track{background:transparent}
|
|
172
|
+
.dsh-dt-helphead{display:flex;align-items:center;gap:9px;position:sticky;top:0;z-index:2;
|
|
173
|
+
padding:12px 0 10px;background:${C.layer1};border-bottom:1px solid ${C.border1}}
|
|
174
|
+
.dsh-dt-help{display:flex;flex-direction:column;gap:15px;margin-top:14px}
|
|
175
|
+
.dsh-dt-helpsteps{display:grid;grid-template-columns:repeat(auto-fit,minmax(215px,1fr));gap:10px}
|
|
176
|
+
.dsh-dt-helpstep{padding:11px 13px;border-radius:11px;border:1px solid ${C.border1};background:${C.layer2}}
|
|
177
|
+
.dsh-dt-stephead{display:flex;align-items:center;gap:7px;font-size:13px;font-weight:600;color:${C.text}}
|
|
178
|
+
.dsh-dt-stephead i{display:inline-flex;align-items:center;justify-content:center;width:17px;height:17px;
|
|
179
|
+
border-radius:50%;font-style:normal;font-size:10.5px;font-weight:700;color:#fff;background:${C.brand};flex:none}
|
|
180
|
+
.dsh-dt-stepbody{margin-top:6px;font-size:12.5px;line-height:1.65;color:${C.sub}}
|
|
181
|
+
.dsh-dt-helpgrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(330px,1fr));gap:10px}
|
|
182
|
+
.dsh-dt-helpitem{display:flex;gap:9px;align-items:flex-start;padding:10px 12px;border-radius:11px;
|
|
183
|
+
border:1px solid ${C.border1};background:${C.layer2}}
|
|
184
|
+
.dsh-dt-helptag{font-size:11px;font-weight:700;color:${C.brand};background:rgba(46,124,246,.1);
|
|
185
|
+
border:1px solid rgba(46,124,246,.2);border-radius:7px;padding:2px 7px;white-space:nowrap;line-height:16px;flex:none}
|
|
186
|
+
.dsh-dt-list{flex:1;min-height:0;overflow-y:auto;padding:12px 14px 16px;display:flex;flex-direction:column;gap:11px}
|
|
187
|
+
.dsh-dt-list::-webkit-scrollbar{width:9px}
|
|
188
|
+
.dsh-dt-list::-webkit-scrollbar-thumb{background:${C.border2};border-radius:6px;border:2px solid ${C.layer1}}
|
|
189
|
+
.dsh-dt-list::-webkit-scrollbar-track{background:transparent}
|
|
190
|
+
.dsh-dt-card{position:relative;background:${C.layer1};border:1px solid ${C.border1};border-radius:14px;
|
|
191
|
+
padding:13px 15px 14px;transition:box-shadow .16s,border-color .16s}
|
|
192
|
+
.dsh-dt-card:hover{box-shadow:0 8px 24px rgba(16,24,40,.075);border-color:${C.border2}}
|
|
193
|
+
.dsh-dt-card[data-tone="warn"]{border-color:rgba(245,165,36,.45);background:
|
|
194
|
+
linear-gradient(180deg, rgba(245,165,36,.06), rgba(255,255,255,0) 60%),${C.layer1}}
|
|
195
|
+
.dsh-dt-card[data-tone="success"]{border-color:rgba(18,161,80,.28)}
|
|
196
|
+
.dsh-dt-card[data-tone="error"]{border-color:rgba(229,72,77,.35)}
|
|
197
|
+
.dsh-dt-row{display:flex;align-items:center;gap:9px}
|
|
198
|
+
.dsh-dt-avatar{width:30px;height:30px;border-radius:10px;flex:none;display:flex;align-items:center;justify-content:center;
|
|
199
|
+
color:#fff;font-size:12.5px;font-weight:650;letter-spacing:.3px;box-shadow:0 2px 8px rgba(16,24,40,.14)}
|
|
200
|
+
.dsh-dt-sender{font-size:13px;font-weight:640;line-height:1.2}
|
|
201
|
+
.dsh-dt-meta{font-size:11px;color:${C.sub};display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-top:2px}
|
|
202
|
+
.dsh-dt-badge{font-size:10.5px;line-height:16px;padding:0 7px;border-radius:999px;border:1px solid transparent;
|
|
203
|
+
white-space:nowrap;font-weight:600}
|
|
204
|
+
.dsh-dt-badge[data-tone="brand"]{background:rgba(46,124,246,.12);color:${C.brand};border-color:rgba(46,124,246,.2)}
|
|
205
|
+
.dsh-dt-badge[data-tone="warn"]{background:rgba(245,165,36,.14);color:#b0730a;border-color:rgba(245,165,36,.3)}
|
|
206
|
+
.dsh-dt-badge[data-tone="success"]{background:rgba(18,161,80,.12);color:${C.success};border-color:rgba(18,161,80,.22)}
|
|
207
|
+
.dsh-dt-badge[data-tone="error"]{background:rgba(229,72,77,.12);color:${C.error};border-color:rgba(229,72,77,.24)}
|
|
208
|
+
.dsh-dt-badge[data-tone="idle"]{background:${C.layer2};color:${C.sub};border-color:${C.border1}}
|
|
209
|
+
.dsh-dt-text{margin:9px 0 0;font-size:13px;line-height:1.62;white-space:pre-wrap;word-break:break-word;color:${C.text}}
|
|
210
|
+
.dsh-dt-quote{margin-top:8px;padding:7px 10px;border-left:3px solid ${C.border2};border-radius:0 8px 8px 0;
|
|
211
|
+
background:${C.layer2};color:${C.sub};font-size:12px;line-height:1.55;white-space:pre-wrap;word-break:break-word}
|
|
212
|
+
.dsh-dt-replybox{margin-top:10px;padding:9px 11px;border-radius:10px;background:rgba(18,161,80,.07);
|
|
213
|
+
border:1px solid rgba(18,161,80,.2);font-size:12.5px;line-height:1.55;white-space:pre-wrap;word-break:break-word}
|
|
214
|
+
.dsh-dt-replybox[data-fail="1"]{background:rgba(229,72,77,.07);border-color:rgba(229,72,77,.24);color:${C.error}}
|
|
215
|
+
.dsh-dt-replybox[data-duplicate="1"]{background:rgba(217,119,6,.09);border-color:rgba(217,119,6,.28);color:#a15c07}
|
|
216
|
+
.dsh-dt-at{display:inline-block;margin-right:5px;padding:0 6px;border-radius:6px;background:rgba(31,111,235,.12);
|
|
217
|
+
color:${C.brand};font-size:11.5px;font-weight:600;line-height:18px;vertical-align:1px}
|
|
218
|
+
.dsh-dt-multi{color:${C.brand};font-weight:600}
|
|
219
|
+
.dsh-dt-parts{display:flex;flex-direction:column;gap:4px;margin-top:5px}
|
|
220
|
+
.dsh-dt-part{display:flex;gap:7px;align-items:flex-start;font-size:12.5px;line-height:1.6}
|
|
221
|
+
.dsh-dt-partno{flex:none;min-width:16px;height:16px;border-radius:5px;background:rgba(31,111,235,.12);color:${C.brand};
|
|
222
|
+
font-size:10.5px;font-weight:600;line-height:16px;text-align:center;font-variant-numeric:tabular-nums}
|
|
223
|
+
.dsh-dt-composer{display:flex;gap:8px;align-items:center;margin-top:10px}
|
|
224
|
+
.dsh-dt-ghostwrap{position:relative;flex:1;min-width:0}
|
|
225
|
+
.dsh-dt-ghost{position:absolute;inset:1px;display:flex;align-items:center;padding:0 46px 0 12px;pointer-events:none;
|
|
226
|
+
overflow:hidden;white-space:pre;font-size:13px;line-height:20px;color:${C.idle};opacity:.95;z-index:2;
|
|
227
|
+
text-shadow:0 1px 0 rgba(255,255,255,.65)}
|
|
228
|
+
.dsh-dt-input{width:100%;box-sizing:border-box;height:38px;padding:0 12px;font:inherit;font-size:13px;line-height:20px;
|
|
229
|
+
border-radius:10px;border:1px solid ${C.border2};background:${C.bg};color:${C.text};outline:none;
|
|
230
|
+
transition:border-color .15s,box-shadow .15s}
|
|
231
|
+
.dsh-dt-input::placeholder{color:${C.idle}}
|
|
232
|
+
.dsh-dt-input:focus{border-color:${C.brand};box-shadow:0 0 0 3px rgba(46,124,246,.14)}
|
|
233
|
+
.dsh-dt-inputwrap{position:relative}
|
|
234
|
+
.dsh-dt-tabhint{position:absolute;right:8px;top:50%;transform:translateY(-50%);font-size:10px;
|
|
235
|
+
padding:1px 5px;border-radius:5px;border:1px solid ${C.border2};background:${C.layer2};color:${C.sub};
|
|
236
|
+
pointer-events:none;letter-spacing:.4px}
|
|
237
|
+
.dsh-dt-btn{appearance:none;border:1px solid ${C.border2};background:${C.layer1};color:${C.text};font:inherit;
|
|
238
|
+
font-size:12px;height:32px;padding:0 12px;border-radius:9px;cursor:pointer;display:inline-flex;align-items:center;
|
|
239
|
+
gap:5px;white-space:nowrap;transition:.14s}
|
|
240
|
+
.dsh-dt-btn:hover{background:${C.layer2};border-color:${C.border2}}
|
|
241
|
+
.dsh-dt-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
242
|
+
.dsh-dt-btn[data-variant="primary"]{background:${C.brand};border-color:${C.brand};color:#fff;font-weight:600}
|
|
243
|
+
.dsh-dt-btn[data-variant="primary"]:hover{filter:brightness(1.06)}
|
|
244
|
+
.dsh-dt-btn[data-variant="ghost"]{border-color:transparent;background:transparent;color:${C.sub}}
|
|
245
|
+
.dsh-dt-btn[data-variant="ghost"]:hover{background:${C.layer2};color:${C.text}}
|
|
246
|
+
.dsh-dt-btn[data-size="sm"]{height:28px;font-size:11.5px;padding:0 9px}
|
|
247
|
+
.dsh-dt-foot{display:flex;align-items:center;gap:8px;margin-top:9px;flex-wrap:wrap}
|
|
248
|
+
.dsh-dt-hint{font-size:11px;color:${C.sub};display:flex;align-items:center;gap:5px;flex-wrap:wrap}
|
|
249
|
+
.dsh-dt-dot{width:6px;height:6px;border-radius:50%;flex:none;background:${C.idle}}
|
|
250
|
+
.dsh-dt-dot[data-state="online"]{background:${C.success};box-shadow:0 0 0 3px rgba(18,161,80,.16);animation:dsh-dt-pulse 2s ease-in-out infinite}
|
|
251
|
+
.dsh-dt-dot[data-state="connecting"]{background:${C.warn};animation:dsh-dt-pulse 1.2s ease-in-out infinite}
|
|
252
|
+
.dsh-dt-dot[data-state="error"]{background:${C.error}}
|
|
253
|
+
.dsh-dt-switch{position:relative;width:42px;height:24px;border-radius:999px;flex:none;cursor:pointer;
|
|
254
|
+
border:1px solid ${C.border2};background:${C.layer2};transition:.18s;padding:0}
|
|
255
|
+
.dsh-dt-switch[data-on="1"]{background:${C.brand};border-color:${C.brand};box-shadow:0 2px 8px rgba(46,124,246,.32)}
|
|
256
|
+
.dsh-dt-switch span{position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;
|
|
257
|
+
box-shadow:0 1px 3px rgba(16,24,40,.28);transition:.18s}
|
|
258
|
+
.dsh-dt-switch[data-on="1"] span{left:20px}
|
|
259
|
+
.dsh-dt-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;
|
|
260
|
+
color:${C.sub};text-align:center;padding:40px 20px;line-height:1.65}
|
|
261
|
+
.dsh-dt-empty-title{font-size:14px;font-weight:620;color:${C.text}}
|
|
262
|
+
.dsh-dt-skel{height:44px;border-radius:14px;border:1px solid ${C.border1};
|
|
263
|
+
background:linear-gradient(90deg,${C.layer2} 25%,${C.layer1} 37%,${C.layer2} 63%);
|
|
264
|
+
background-size:400% 100%;animation:dsh-dt-shimmer 1.4s ease infinite}
|
|
265
|
+
.dsh-dt-modal-overlay{position:fixed;inset:0;z-index:1200;display:flex;align-items:center;justify-content:center;
|
|
266
|
+
padding:24px;background:rgba(15,23,42,.44);backdrop-filter:blur(3px);animation:dsh-dt-fade .18s ease}
|
|
267
|
+
.dsh-dt-modal{width:min(560px,100%);max-height:86vh;overflow-y:auto;padding:20px 22px 18px;border-radius:18px;
|
|
268
|
+
background:${C.overlay};border:1px solid ${C.border1};box-shadow:0 28px 72px rgba(15,23,42,.32);
|
|
269
|
+
animation:dsh-dt-rise .2s cubic-bezier(.2,.8,.3,1)}
|
|
270
|
+
.dsh-dt-modal-title{font-size:15px;font-weight:650;display:flex;align-items:center;gap:8px}
|
|
271
|
+
.dsh-dt-modal-sub{font-size:12px;color:${C.sub};margin-top:5px;line-height:1.6}
|
|
272
|
+
.dsh-dt-modal-quote{margin-top:14px;padding:11px 13px;border-radius:11px;background:${C.layer2};
|
|
273
|
+
border:1px solid ${C.border1};font-size:12.8px;line-height:1.62;white-space:pre-wrap;word-break:break-word;
|
|
274
|
+
max-height:180px;overflow:auto}
|
|
275
|
+
.dsh-dt-modal-foot{display:flex;align-items:center;gap:9px;margin-top:16px;flex-wrap:wrap}
|
|
276
|
+
.dsh-dt-kbd{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:10.5px;padding:1px 5px;
|
|
277
|
+
border-radius:5px;border:1px solid ${C.border2};background:${C.layer2};color:${C.sub}}
|
|
278
|
+
.dsh-dt-section{padding:18px 22px;border-radius:14px;border:1px solid ${C.border1};background:${C.layer1};
|
|
279
|
+
margin:12px 20px;box-sizing:border-box}
|
|
280
|
+
.dsh-dt-kv{display:grid;grid-template-columns:150px 1fr;gap:8px 14px;font-size:12.5px;margin-top:12px}
|
|
281
|
+
.dsh-dt-kv dt{color:${C.sub}}
|
|
282
|
+
.dsh-dt-kv dd{margin:0;color:${C.text};word-break:break-word}
|
|
283
|
+
@keyframes dsh-dt-pulse{0%,100%{opacity:1}50%{opacity:.4}}
|
|
284
|
+
@keyframes dsh-dt-fade{from{opacity:0}to{opacity:1}}
|
|
285
|
+
@keyframes dsh-dt-rise{from{opacity:0;transform:translateY(10px) scale(.99)}to{opacity:1;transform:none}}
|
|
286
|
+
@keyframes dsh-dt-shimmer{0%{background-position:100% 0}100%{background-position:0 0}}
|
|
287
|
+
`
|
|
288
|
+
|
|
289
|
+
function Styles() {
|
|
290
|
+
// 必须走 dangerouslySetInnerHTML:React 会把 <style> 的文本子节点里的引号转义成
|
|
291
|
+
// ",导致 [data-on="1"]、[data-state="online"] 这类属性选择器整条失效。
|
|
292
|
+
return h('style', { 'data-dingtalk-bridge': '1', dangerouslySetInnerHTML: { __html: STYLES } })
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ------------------------------------------------------------------ 共享 store
|
|
296
|
+
|
|
297
|
+
const store = {
|
|
298
|
+
state: null,
|
|
299
|
+
error: '',
|
|
300
|
+
listeners: new Set(),
|
|
301
|
+
source: null,
|
|
302
|
+
retryTimer: null,
|
|
303
|
+
pollTimer: null,
|
|
304
|
+
softTimer: null,
|
|
305
|
+
started: false,
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function emit() {
|
|
309
|
+
for (const fn of store.listeners) {
|
|
310
|
+
try {
|
|
311
|
+
fn(store.state)
|
|
312
|
+
} catch {
|
|
313
|
+
// 单个订阅者异常不影响其它组件。
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function applyState(next) {
|
|
319
|
+
if (!next || typeof next !== 'object') return
|
|
320
|
+
store.state = next
|
|
321
|
+
store.error = ''
|
|
322
|
+
emit()
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function fetchState() {
|
|
326
|
+
try {
|
|
327
|
+
const res = await fetch(`${API}/state`, {
|
|
328
|
+
credentials: 'same-origin',
|
|
329
|
+
headers: { accept: 'application/json' },
|
|
330
|
+
})
|
|
331
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
332
|
+
const data = await res.json()
|
|
333
|
+
if (data && data.state) applyState(data.state)
|
|
334
|
+
} catch (error) {
|
|
335
|
+
store.error = String(error && error.message ? error.message : error)
|
|
336
|
+
emit()
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function scheduleReconnect() {
|
|
341
|
+
if (store.retryTimer) return
|
|
342
|
+
store.retryTimer = setTimeout(() => {
|
|
343
|
+
store.retryTimer = null
|
|
344
|
+
connectStream()
|
|
345
|
+
}, 4000)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function connectStream() {
|
|
349
|
+
if (typeof EventSource === 'undefined') {
|
|
350
|
+
store.source = null
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
const source = new EventSource(`${API}/events`)
|
|
355
|
+
store.source = source
|
|
356
|
+
source.onmessage = (event) => {
|
|
357
|
+
try {
|
|
358
|
+
applyState(JSON.parse(event.data))
|
|
359
|
+
} catch {
|
|
360
|
+
// 忽略坏帧。
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
source.onerror = () => {
|
|
364
|
+
try {
|
|
365
|
+
source.close()
|
|
366
|
+
} catch {
|
|
367
|
+
// 忽略。
|
|
368
|
+
}
|
|
369
|
+
if (store.source === source) store.source = null
|
|
370
|
+
scheduleReconnect()
|
|
371
|
+
}
|
|
372
|
+
source.onopen = () => {
|
|
373
|
+
store.retryTimer = null
|
|
374
|
+
}
|
|
375
|
+
} catch {
|
|
376
|
+
store.source = null
|
|
377
|
+
scheduleReconnect()
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function startStore() {
|
|
382
|
+
if (store.started) return
|
|
383
|
+
store.started = true
|
|
384
|
+
fetchState()
|
|
385
|
+
connectStream()
|
|
386
|
+
store.pollTimer = setInterval(() => {
|
|
387
|
+
if (!store.source) fetchState()
|
|
388
|
+
}, POLL_MS)
|
|
389
|
+
// 即使 SSE 在线也做低频对账:DSH 里切换模型、重新登录后无需等下一次消息事件。
|
|
390
|
+
store.softTimer = setInterval(() => {
|
|
391
|
+
if (store.source) fetchState()
|
|
392
|
+
}, SOFT_POLL_MS)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 有些环境里 POST 会被宿主安全护栏挡下(GET 正常),所以失败时自动改用
|
|
396
|
+
// 带查询参数的 GET /action 再试一次,两条通道在宿主里走同一套 handleAction。
|
|
397
|
+
function actionQuery(payload) {
|
|
398
|
+
const params = new URLSearchParams()
|
|
399
|
+
for (const [key, value] of Object.entries(payload || {})) {
|
|
400
|
+
if (value === undefined || value === null) continue
|
|
401
|
+
params.set(key, String(value))
|
|
402
|
+
}
|
|
403
|
+
return `${API}/action?${params.toString()}`
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function acceptResponse(data, res) {
|
|
407
|
+
if (data && data.state) applyState(data.state)
|
|
408
|
+
if (data && data.ok === false) {
|
|
409
|
+
store.error = `${String(data.error || '操作未成功')}`
|
|
410
|
+
emit()
|
|
411
|
+
return false
|
|
412
|
+
}
|
|
413
|
+
if (res && !res.ok) {
|
|
414
|
+
store.error = `操作失败(HTTP ${res.status})`
|
|
415
|
+
emit()
|
|
416
|
+
return false
|
|
417
|
+
}
|
|
418
|
+
if (store.error) {
|
|
419
|
+
store.error = ''
|
|
420
|
+
emit()
|
|
421
|
+
}
|
|
422
|
+
return true
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function postAction(payload) {
|
|
426
|
+
try {
|
|
427
|
+
const res = await fetch(`${API}/action`, {
|
|
428
|
+
method: 'POST',
|
|
429
|
+
credentials: 'same-origin',
|
|
430
|
+
headers: { 'content-type': 'application/json' },
|
|
431
|
+
body: JSON.stringify(payload),
|
|
432
|
+
})
|
|
433
|
+
const data = await res.json().catch(() => ({}))
|
|
434
|
+
if (res.ok && data && data.state) {
|
|
435
|
+
acceptResponse(data, res)
|
|
436
|
+
return data || {}
|
|
437
|
+
}
|
|
438
|
+
// POST 不通(403/401/空响应):换 GET 通道重试。
|
|
439
|
+
store.error = `操作被宿主拒绝(HTTP ${res.status}),已改用兼容通道重试`
|
|
440
|
+
emit()
|
|
441
|
+
} catch (error) {
|
|
442
|
+
store.error = String(error && error.message ? error.message : error)
|
|
443
|
+
emit()
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
try {
|
|
447
|
+
const res = await fetch(actionQuery(payload), { credentials: 'same-origin', cache: 'no-store' })
|
|
448
|
+
const data = await res.json().catch(() => ({}))
|
|
449
|
+
acceptResponse(data, res)
|
|
450
|
+
return data || {}
|
|
451
|
+
} catch (error) {
|
|
452
|
+
store.error = String(error && error.message ? error.message : error)
|
|
453
|
+
emit()
|
|
454
|
+
return { ok: false, error: store.error }
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function useBridge() {
|
|
459
|
+
const [state, setState] = useState(store.state)
|
|
460
|
+
const [error, setError] = useState(store.error)
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
const listener = (next) => {
|
|
463
|
+
setState(next)
|
|
464
|
+
setError(store.error)
|
|
465
|
+
}
|
|
466
|
+
store.listeners.add(listener)
|
|
467
|
+
startStore()
|
|
468
|
+
if (store.state) setState(store.state)
|
|
469
|
+
return () => {
|
|
470
|
+
store.listeners.delete(listener)
|
|
471
|
+
}
|
|
472
|
+
}, [])
|
|
473
|
+
return { state, error }
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// ------------------------------------------------------------------ 工具函数
|
|
477
|
+
|
|
478
|
+
const STATUS = {
|
|
479
|
+
received: { label: '待生成建议', tone: 'idle' },
|
|
480
|
+
suggesting: { label: '生成建议中', tone: 'idle' },
|
|
481
|
+
suggested: { label: '建议已生成', tone: 'brand' },
|
|
482
|
+
'needs-human': { label: '需要你确认', tone: 'warn' },
|
|
483
|
+
waiting: { label: '已忽略', tone: 'idle' },
|
|
484
|
+
'auto-replied': { label: '已自动回复', tone: 'success' },
|
|
485
|
+
replied: { label: '已回复', tone: 'success' },
|
|
486
|
+
failed: { label: '处理失败', tone: 'error' },
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function statusMeta(message) {
|
|
490
|
+
if (message.status === 'needs-human') return STATUS['needs-human']
|
|
491
|
+
// 幂等键重复不是发送失败:这条回复大概率早就发出去了,提示可以换键重发即可。
|
|
492
|
+
if (message.status === 'failed' && message.reply && message.reply.duplicate) {
|
|
493
|
+
return { label: '已提交过', tone: 'warn' }
|
|
494
|
+
}
|
|
495
|
+
return STATUS[message.status] || STATUS.received
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function cardTone(message) {
|
|
499
|
+
if (message.status === 'failed' && message.reply && message.reply.duplicate) return 'warn'
|
|
500
|
+
if (message.status === 'failed') return 'error'
|
|
501
|
+
if (message.status === 'needs-human') return 'warn'
|
|
502
|
+
if (message.reply && message.reply.ok) return 'success'
|
|
503
|
+
return ''
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function timeLabel(timestamp) {
|
|
507
|
+
const value = Number(timestamp) || 0
|
|
508
|
+
if (value <= 0) return ''
|
|
509
|
+
const diff = Date.now() - value
|
|
510
|
+
if (diff < 0) return '刚刚'
|
|
511
|
+
if (diff < 60 * 1000) return '刚刚'
|
|
512
|
+
if (diff < 60 * 60 * 1000) return `${Math.floor(diff / 60000)} 分钟前`
|
|
513
|
+
if (diff < 24 * 60 * 60 * 1000) return `${Math.floor(diff / 3600000)} 小时前`
|
|
514
|
+
const date = new Date(value)
|
|
515
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
516
|
+
const sameYear = date.getFullYear() === new Date().getFullYear()
|
|
517
|
+
const stamp = `${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
518
|
+
return sameYear ? stamp : `${date.getFullYear()}-${stamp}`
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const AVATAR_GRADIENTS = [
|
|
522
|
+
['#2E7CF6', '#17B0F0'],
|
|
523
|
+
['#7C5CFC', '#B07CFF'],
|
|
524
|
+
['#F5623F', '#FF9A62'],
|
|
525
|
+
['#12A150', '#4ED17E'],
|
|
526
|
+
['#E5484D', '#FF8A8A'],
|
|
527
|
+
['#F5A524', '#FFC85C'],
|
|
528
|
+
['#0EA5A4', '#38D9C5'],
|
|
529
|
+
]
|
|
530
|
+
|
|
531
|
+
function gradientOf(name) {
|
|
532
|
+
const text = String(name || '?')
|
|
533
|
+
let hash = 0
|
|
534
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
535
|
+
hash = (hash * 31 + text.charCodeAt(index)) >>> 0
|
|
536
|
+
}
|
|
537
|
+
return AVATAR_GRADIENTS[hash % AVATAR_GRADIENTS.length]
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function initialsOf(name) {
|
|
541
|
+
const text = String(name || '').trim()
|
|
542
|
+
if (text === '') return '?'
|
|
543
|
+
return text.slice(-2)
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function kindLabel(message) {
|
|
547
|
+
return message.kind === 'group' ? '群 @' : '私信'
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function sourceText(message) {
|
|
551
|
+
if (message.kind === 'group') {
|
|
552
|
+
return message.conversationTitle || '未命名群聊'
|
|
553
|
+
}
|
|
554
|
+
return '单聊'
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function confidenceText(value) {
|
|
558
|
+
const number = Number(value)
|
|
559
|
+
if (!Number.isFinite(number)) return ''
|
|
560
|
+
return `${Math.round(number * 100)}%`
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* 当前模型能不能看图(来自 host 的探测结果)。
|
|
565
|
+
* 只看图不分析时也要讲清楚原因,避免用户以为图片坏了。
|
|
566
|
+
*/
|
|
567
|
+
function imageCapabilityText(state) {
|
|
568
|
+
if (!state) return ''
|
|
569
|
+
if (state.vision === true) return ' · 当前模型支持看图'
|
|
570
|
+
if (state.vision === false) return ' · 当前模型不支持看图,图片只展示不分析'
|
|
571
|
+
return ''
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// ------------------------------------------------------------------ 基础组件
|
|
575
|
+
|
|
576
|
+
function Badge(props) {
|
|
577
|
+
return h(
|
|
578
|
+
'span',
|
|
579
|
+
{ className: 'dsh-dt-badge', 'data-tone': props.tone || 'idle', title: props.title || undefined },
|
|
580
|
+
props.children,
|
|
581
|
+
)
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* 匹配度胶囊:把模型自评的置信度明确画出来,自动回复与人工确认都能一眼看到「AI 有多确定」。
|
|
586
|
+
* ≥80% 绿、≥60% 黄、其余红;没有建议时返回 null,不占位。
|
|
587
|
+
*/
|
|
588
|
+
function ConfidencePill(props) {
|
|
589
|
+
const raw = props.value
|
|
590
|
+
const number = Number(raw)
|
|
591
|
+
if (raw === null || raw === undefined || !Number.isFinite(number)) return null
|
|
592
|
+
const percent = Math.round(number * 100)
|
|
593
|
+
const tone = number >= 0.8 ? 'high' : number >= 0.6 ? 'mid' : 'low'
|
|
594
|
+
return h(
|
|
595
|
+
'span',
|
|
596
|
+
{
|
|
597
|
+
className: 'dsh-dt-conf',
|
|
598
|
+
'data-tone': tone,
|
|
599
|
+
title: props.title || `模型对该回复的自评匹配度:${percent}%`,
|
|
600
|
+
'data-confidence': percent,
|
|
601
|
+
},
|
|
602
|
+
props.label || '匹配度',
|
|
603
|
+
h('b', { style: { fontWeight: 650 } }, `${percent}%`),
|
|
604
|
+
)
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 消息里的图片:缩略图直接从宿主 /media 路由取字节流。
|
|
609
|
+
* 正在下载的显示骨架,失败的显示占位说明,点击在新窗口看原图。
|
|
610
|
+
*/
|
|
611
|
+
function MessageImages(props) {
|
|
612
|
+
const images = Array.isArray(props.images) ? props.images : []
|
|
613
|
+
if (images.length === 0) return null
|
|
614
|
+
const id = props.id || ''
|
|
615
|
+
return h(
|
|
616
|
+
'div',
|
|
617
|
+
{ className: 'dsh-dt-imgs' },
|
|
618
|
+
images.map((image, index) => {
|
|
619
|
+
const indexValue = image.index !== undefined ? image.index : index
|
|
620
|
+
const url = `${API}/media?id=${encodeURIComponent(id)}&i=${indexValue}`
|
|
621
|
+
if (image.state === 'ready') {
|
|
622
|
+
return h(
|
|
623
|
+
'a',
|
|
624
|
+
{
|
|
625
|
+
key: indexValue,
|
|
626
|
+
className: 'dsh-dt-img',
|
|
627
|
+
href: url,
|
|
628
|
+
target: '_blank',
|
|
629
|
+
rel: 'noreferrer',
|
|
630
|
+
title: '在新窗口查看原图',
|
|
631
|
+
},
|
|
632
|
+
h('img', { src: url, alt: '消息图片', loading: 'lazy' }),
|
|
633
|
+
)
|
|
634
|
+
}
|
|
635
|
+
if (image.state === 'failed') {
|
|
636
|
+
return h(
|
|
637
|
+
'div',
|
|
638
|
+
{ key: indexValue, className: 'dsh-dt-img', 'data-state': 'failed', title: image.error || '图片下载失败' },
|
|
639
|
+
'图片不可用',
|
|
640
|
+
)
|
|
641
|
+
}
|
|
642
|
+
return h('div', { key: indexValue, className: 'dsh-dt-img', 'data-state': 'loading' }, '加载中…')
|
|
643
|
+
}),
|
|
644
|
+
)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function Button(props) {
|
|
648
|
+
return h(
|
|
649
|
+
'button',
|
|
650
|
+
{
|
|
651
|
+
type: 'button',
|
|
652
|
+
className: 'dsh-dt-btn',
|
|
653
|
+
'data-variant': props.variant || 'default',
|
|
654
|
+
'data-size': props.size || 'md',
|
|
655
|
+
disabled: props.disabled || false,
|
|
656
|
+
onClick: props.onClick,
|
|
657
|
+
title: props.title || undefined,
|
|
658
|
+
},
|
|
659
|
+
props.children,
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function Switch(props) {
|
|
664
|
+
return h(
|
|
665
|
+
'button',
|
|
666
|
+
{
|
|
667
|
+
type: 'button',
|
|
668
|
+
className: 'dsh-dt-switch',
|
|
669
|
+
'data-on': props.checked ? '1' : '0',
|
|
670
|
+
'aria-pressed': props.checked ? 'true' : 'false',
|
|
671
|
+
'aria-label': props.label || '切换',
|
|
672
|
+
onClick: () => props.onChange(!props.checked),
|
|
673
|
+
},
|
|
674
|
+
h('span'),
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function Avatar(props) {
|
|
679
|
+
const [from, to] = gradientOf(props.name)
|
|
680
|
+
return h(
|
|
681
|
+
'div',
|
|
682
|
+
{
|
|
683
|
+
className: 'dsh-dt-avatar',
|
|
684
|
+
style: { background: `linear-gradient(135deg, ${from}, ${to})` },
|
|
685
|
+
'aria-hidden': 'true',
|
|
686
|
+
},
|
|
687
|
+
initialsOf(props.name),
|
|
688
|
+
)
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* 带「阴影建议」的输入框:建议文字以灰色显示在输入框内,按 Tab 补全,Enter 发送,Esc 收起。
|
|
693
|
+
*/
|
|
694
|
+
function GhostInput(props) {
|
|
695
|
+
const {
|
|
696
|
+
value,
|
|
697
|
+
suggestion,
|
|
698
|
+
placeholder,
|
|
699
|
+
disabled,
|
|
700
|
+
autoFocus,
|
|
701
|
+
onChange,
|
|
702
|
+
onSubmit,
|
|
703
|
+
ariaLabel,
|
|
704
|
+
} = props
|
|
705
|
+
const inputRef = useRef(null)
|
|
706
|
+
|
|
707
|
+
const ghost = useMemo(() => {
|
|
708
|
+
if (disabled) return ''
|
|
709
|
+
const text = typeof suggestion === 'string' ? suggestion : ''
|
|
710
|
+
if (text === '') return ''
|
|
711
|
+
if (value === '') return text
|
|
712
|
+
if (text.startsWith(value)) return text.slice(value.length)
|
|
713
|
+
return ''
|
|
714
|
+
}, [value, suggestion, disabled])
|
|
715
|
+
|
|
716
|
+
useEffect(() => {
|
|
717
|
+
if (autoFocus && inputRef.current) {
|
|
718
|
+
try {
|
|
719
|
+
inputRef.current.focus()
|
|
720
|
+
} catch {
|
|
721
|
+
// 忽略。
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}, [autoFocus])
|
|
725
|
+
|
|
726
|
+
const handleKeyDown = (event) => {
|
|
727
|
+
if (event.key === 'Tab' && ghost !== '') {
|
|
728
|
+
event.preventDefault()
|
|
729
|
+
onChange(value + ghost)
|
|
730
|
+
return
|
|
731
|
+
}
|
|
732
|
+
if (event.key === 'Escape') {
|
|
733
|
+
event.preventDefault()
|
|
734
|
+
try {
|
|
735
|
+
if (inputRef.current) inputRef.current.blur()
|
|
736
|
+
} catch {
|
|
737
|
+
// 忽略。
|
|
738
|
+
}
|
|
739
|
+
return
|
|
740
|
+
}
|
|
741
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
742
|
+
event.preventDefault()
|
|
743
|
+
onSubmit()
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return h(
|
|
748
|
+
'div',
|
|
749
|
+
{ className: 'dsh-dt-ghostwrap' },
|
|
750
|
+
h(
|
|
751
|
+
'div',
|
|
752
|
+
{ className: 'dsh-dt-inputwrap' },
|
|
753
|
+
h('input', {
|
|
754
|
+
ref: inputRef,
|
|
755
|
+
className: 'dsh-dt-input',
|
|
756
|
+
value,
|
|
757
|
+
placeholder: ghost !== '' ? '' : placeholder,
|
|
758
|
+
disabled,
|
|
759
|
+
spellCheck: false,
|
|
760
|
+
'aria-label': ariaLabel || '输入回复',
|
|
761
|
+
onChange: (event) => onChange(event.target.value),
|
|
762
|
+
onKeyDown: handleKeyDown,
|
|
763
|
+
}),
|
|
764
|
+
// 建议直接画在输入框内(灰色阴影字),叠在 input 之上以便肉眼可见。
|
|
765
|
+
ghost !== ''
|
|
766
|
+
? h(
|
|
767
|
+
'div',
|
|
768
|
+
{ className: 'dsh-dt-ghost', 'aria-hidden': 'true', title: `建议回复:${suggestion}` },
|
|
769
|
+
h('span', { style: { visibility: 'hidden' } }, value),
|
|
770
|
+
h('span', null, ghost),
|
|
771
|
+
)
|
|
772
|
+
: null,
|
|
773
|
+
ghost !== '' ? h('span', { className: 'dsh-dt-tabhint' }, 'Tab') : null,
|
|
774
|
+
),
|
|
775
|
+
)
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function EmptyState(props) {
|
|
779
|
+
return h(
|
|
780
|
+
'div',
|
|
781
|
+
{ className: 'dsh-dt-empty' },
|
|
782
|
+
h(
|
|
783
|
+
'svg',
|
|
784
|
+
{ width: 56, height: 56, viewBox: '0 0 48 48', fill: 'none', 'aria-hidden': 'true' },
|
|
785
|
+
h('path', {
|
|
786
|
+
d: 'M24 6C13.5 6 5 13.5 5 22.8c0 5.2 2.7 9.8 7 12.9v6.9c0 .8.9 1.3 1.6.8l7.4-4.9c1 .2 2 .3 3 .3 10.5 0 19-7.5 19-16.8S34.5 6 24 6Z',
|
|
787
|
+
fill: 'rgba(46,124,246,.12)',
|
|
788
|
+
stroke: 'rgba(46,124,246,.42)',
|
|
789
|
+
strokeWidth: '1.6',
|
|
790
|
+
}),
|
|
791
|
+
h('path', {
|
|
792
|
+
d: 'M17 19.5h14M17 24.5h9',
|
|
793
|
+
stroke: 'rgba(46,124,246,.55)',
|
|
794
|
+
strokeWidth: '1.8',
|
|
795
|
+
strokeLinecap: 'round',
|
|
796
|
+
}),
|
|
797
|
+
),
|
|
798
|
+
h('div', { className: 'dsh-dt-empty-title' }, props.title || '暂无消息'),
|
|
799
|
+
h('div', { style: { maxWidth: '360px', fontSize: 12.5 } }, props.description || ''),
|
|
800
|
+
props.children || null,
|
|
801
|
+
)
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ------------------------------------------------------------------ 消息卡片
|
|
805
|
+
|
|
806
|
+
function MessageCard(props) {
|
|
807
|
+
const { message, autoReply, groupReplyAt, busy, onSend, onRegenerate, onDismiss } = props
|
|
808
|
+
const [value, setValue] = useState('')
|
|
809
|
+
const suggestion = message.suggestion && message.suggestion.text ? message.suggestion.text : ''
|
|
810
|
+
const meta = statusMeta(message)
|
|
811
|
+
const tone = cardTone(message)
|
|
812
|
+
const replied = message.reply && message.reply.ok
|
|
813
|
+
const suggesting = message.status === 'suggesting'
|
|
814
|
+
const showComposer = !(replied && message.reply.auto)
|
|
815
|
+
const canSend = (value.trim() !== '' || suggestion !== '') && !busy
|
|
816
|
+
|
|
817
|
+
const submit = async () => {
|
|
818
|
+
if (!canSend) return
|
|
819
|
+
const text = value.trim() !== '' ? value.trim() : suggestion
|
|
820
|
+
const result = await onSend(message.id, text)
|
|
821
|
+
if (result && result.ok !== false) setValue('')
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const confidence =
|
|
825
|
+
message.suggestion && message.suggestion.confidence !== null && message.suggestion.confidence !== undefined
|
|
826
|
+
? message.suggestion.confidence
|
|
827
|
+
: null
|
|
828
|
+
|
|
829
|
+
return h(
|
|
830
|
+
'div',
|
|
831
|
+
{ className: 'dsh-dt-card dsh-dt-fade', 'data-tone': tone },
|
|
832
|
+
h(
|
|
833
|
+
'div',
|
|
834
|
+
{ className: 'dsh-dt-row' },
|
|
835
|
+
h(Avatar, { name: message.sender }),
|
|
836
|
+
h(
|
|
837
|
+
'div',
|
|
838
|
+
{ style: { minWidth: 0, flex: 1 } },
|
|
839
|
+
h('div', { className: 'dsh-dt-sender' }, message.sender),
|
|
840
|
+
h(
|
|
841
|
+
'div',
|
|
842
|
+
{ className: 'dsh-dt-meta' },
|
|
843
|
+
h(Badge, { tone: message.kind === 'group' ? 'warn' : 'brand' }, kindLabel(message)),
|
|
844
|
+
h('span', { style: { opacity: 0.65 } }, '·'),
|
|
845
|
+
h('span', null, sourceText(message)),
|
|
846
|
+
h('span', { style: { opacity: 0.65 } }, '·'),
|
|
847
|
+
h('span', null, timeLabel(message.at)),
|
|
848
|
+
),
|
|
849
|
+
),
|
|
850
|
+
!replied && confidence !== null ? h(ConfidencePill, { value: confidence, label: '匹配度 ' }) : null,
|
|
851
|
+
h(Badge, { tone: meta.tone }, meta.label),
|
|
852
|
+
),
|
|
853
|
+
|
|
854
|
+
message.images && message.images.length > 0
|
|
855
|
+
? h(MessageImages, { id: message.id, images: message.images })
|
|
856
|
+
: null,
|
|
857
|
+
|
|
858
|
+
h('div', { className: 'dsh-dt-text' }, message.text),
|
|
859
|
+
|
|
860
|
+
message.quoted
|
|
861
|
+
? h('div', { className: 'dsh-dt-quote' }, `引用 ${message.quoted}`)
|
|
862
|
+
: null,
|
|
863
|
+
|
|
864
|
+
replied
|
|
865
|
+
? h(
|
|
866
|
+
'div',
|
|
867
|
+
{ className: 'dsh-dt-replybox', 'data-fail': '0' },
|
|
868
|
+
message.reply.atSender
|
|
869
|
+
? h('span', { className: 'dsh-dt-at', title: '群消息回复会自动 @ 回发送人' }, `@${message.sender} `)
|
|
870
|
+
: null,
|
|
871
|
+
`${message.reply.auto ? '已自动回复' : '已回复'}:`,
|
|
872
|
+
Array.isArray(message.reply.parts) && message.reply.parts.length > 1
|
|
873
|
+
? h(
|
|
874
|
+
'div',
|
|
875
|
+
{ className: 'dsh-dt-parts' },
|
|
876
|
+
message.reply.parts.map((part, index) =>
|
|
877
|
+
h('div', { className: 'dsh-dt-part', key: `${message.id}-part-${index}` }, h('span', { className: 'dsh-dt-partno' }, index + 1), part.text),
|
|
878
|
+
),
|
|
879
|
+
)
|
|
880
|
+
: message.reply.text,
|
|
881
|
+
)
|
|
882
|
+
: null,
|
|
883
|
+
|
|
884
|
+
message.reply && message.reply.ok === false && message.reply.duplicate
|
|
885
|
+
? h(
|
|
886
|
+
'div',
|
|
887
|
+
{ className: 'dsh-dt-replybox', 'data-duplicate': '1' },
|
|
888
|
+
`幂等键重复:${message.reply.error || '钉钉认为这条回复已经提交过'}(第 ${message.reply.attempt || 1} 次尝试;再点「发送」会自动换新的幂等键重发)`,
|
|
889
|
+
)
|
|
890
|
+
: message.reply && message.reply.ok === false
|
|
891
|
+
? h('div', { className: 'dsh-dt-replybox', 'data-fail': '1' }, `发送失败:${message.reply.error || message.error}`)
|
|
892
|
+
: null,
|
|
893
|
+
|
|
894
|
+
replied && confidence !== null
|
|
895
|
+
? h(
|
|
896
|
+
'div',
|
|
897
|
+
{ className: 'dsh-dt-hint', style: { marginTop: 7, display: 'flex', alignItems: 'center', gap: 7, flexWrap: 'wrap' } },
|
|
898
|
+
h(ConfidencePill, { value: confidence, label: '本次回复匹配度 ' }),
|
|
899
|
+
h(
|
|
900
|
+
'span',
|
|
901
|
+
{ style: { opacity: 0.8 } },
|
|
902
|
+
message.reply.auto
|
|
903
|
+
? `AI 自评匹配度达到阈值,已自动发送${message.reply.matchBy === 'images' ? '(含图片分析)' : ''}`
|
|
904
|
+
: '人工确认后发送',
|
|
905
|
+
),
|
|
906
|
+
)
|
|
907
|
+
: null,
|
|
908
|
+
|
|
909
|
+
message.autoCancelled && !replied
|
|
910
|
+
? h(
|
|
911
|
+
'div',
|
|
912
|
+
{ className: 'dsh-dt-hint', style: { color: C.warn, marginTop: 8 } },
|
|
913
|
+
'⏸ 自动回复已关闭,本条不会自动发送(可手动发送下面这条建议)',
|
|
914
|
+
)
|
|
915
|
+
: null,
|
|
916
|
+
|
|
917
|
+
message.error && !(message.reply && message.reply.ok === false)
|
|
918
|
+
? h('div', { className: 'dsh-dt-hint', style: { color: C.error, marginTop: 8 } }, `⚠ ${message.error}`)
|
|
919
|
+
: null,
|
|
920
|
+
|
|
921
|
+
message.kind === 'group' && groupReplyAt !== false && !(message.reply && message.reply.atSender)
|
|
922
|
+
? h(
|
|
923
|
+
'div',
|
|
924
|
+
{ className: 'dsh-dt-hint', 'data-at-hint': '1', style: { marginTop: 8, color: C.brand } },
|
|
925
|
+
`回复时会先 @${message.sender}(谁 @ 我,我就 @ 谁)`,
|
|
926
|
+
)
|
|
927
|
+
: null,
|
|
928
|
+
|
|
929
|
+
suggesting
|
|
930
|
+
? h(
|
|
931
|
+
'div',
|
|
932
|
+
{ style: { marginTop: 10, display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
933
|
+
h('div', { className: 'dsh-dt-skel', style: { height: 30 } }),
|
|
934
|
+
h('div', { className: 'dsh-dt-hint' }, 'AI 正在根据消息来源的上下文生成建议回复…'),
|
|
935
|
+
)
|
|
936
|
+
: null,
|
|
937
|
+
|
|
938
|
+
showComposer && !suggesting
|
|
939
|
+
? h(
|
|
940
|
+
'div',
|
|
941
|
+
null,
|
|
942
|
+
h(
|
|
943
|
+
'div',
|
|
944
|
+
{ className: 'dsh-dt-composer' },
|
|
945
|
+
h(GhostInput, {
|
|
946
|
+
value,
|
|
947
|
+
suggestion,
|
|
948
|
+
disabled: busy,
|
|
949
|
+
placeholder: replied ? '已回复,可继续补充…' : message.kind === 'group' && groupReplyAt !== false ? `回复 @${message.sender},Tab 补全建议…` : '输入回复,Tab 补全建议…',
|
|
950
|
+
onChange: setValue,
|
|
951
|
+
onSubmit: submit,
|
|
952
|
+
ariaLabel: `回复 ${message.sender}`,
|
|
953
|
+
autoFocus: message.status === 'needs-human',
|
|
954
|
+
}),
|
|
955
|
+
h(
|
|
956
|
+
Button,
|
|
957
|
+
{
|
|
958
|
+
variant: 'primary',
|
|
959
|
+
disabled: !canSend,
|
|
960
|
+
onClick: submit,
|
|
961
|
+
title: '发送回复(Enter)',
|
|
962
|
+
},
|
|
963
|
+
busy ? '发送中…' : '发送',
|
|
964
|
+
),
|
|
965
|
+
),
|
|
966
|
+
h(
|
|
967
|
+
'div',
|
|
968
|
+
{ className: 'dsh-dt-foot' },
|
|
969
|
+
suggestion !== ''
|
|
970
|
+
? h(
|
|
971
|
+
'div',
|
|
972
|
+
{ className: 'dsh-dt-hint' },
|
|
973
|
+
h('span', { className: 'dsh-dt-dot', 'data-state': 'online' }),
|
|
974
|
+
`建议置信度 ${confidenceText(message.suggestion.confidence)}`,
|
|
975
|
+
message.suggestion.needsHuman ? ' · 需人工确认' : '',
|
|
976
|
+
Number(message.suggestion.contextCount) > 0
|
|
977
|
+
? ` · 参考本来源 ${Number(message.suggestion.contextCount)} 条上下文`
|
|
978
|
+
: '',
|
|
979
|
+
Number(message.suggestion.imageCount) > 0
|
|
980
|
+
? ` · 已结合 ${Number(message.suggestion.imageCount)} 张图片`
|
|
981
|
+
: message.images && message.images.length > 0
|
|
982
|
+
? ' · 图片未纳入分析'
|
|
983
|
+
: '',
|
|
984
|
+
Array.isArray(message.suggestion.replies) && message.suggestion.replies.length > 1
|
|
985
|
+
? h(
|
|
986
|
+
'span',
|
|
987
|
+
{ className: 'dsh-dt-multi', title: '点「发送」会按顺序连发这几条消息' },
|
|
988
|
+
` · 将分 ${message.suggestion.replies.length} 条依次发送`,
|
|
989
|
+
)
|
|
990
|
+
: null,
|
|
991
|
+
message.suggestion.reason
|
|
992
|
+
? h('span', { style: { opacity: 0.8 } }, ` · ${String(message.suggestion.reason).slice(0, 60)}`)
|
|
993
|
+
: null,
|
|
994
|
+
)
|
|
995
|
+
: h(
|
|
996
|
+
'div',
|
|
997
|
+
{ className: 'dsh-dt-hint' },
|
|
998
|
+
autoReply ? '自动回复未能判断,请手动确认' : '暂无建议,可点击「生成建议」',
|
|
999
|
+
),
|
|
1000
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
1001
|
+
h(
|
|
1002
|
+
Button,
|
|
1003
|
+
{
|
|
1004
|
+
size: 'sm',
|
|
1005
|
+
variant: 'ghost',
|
|
1006
|
+
disabled: busy,
|
|
1007
|
+
onClick: () => onRegenerate(message.id),
|
|
1008
|
+
},
|
|
1009
|
+
suggestion !== '' ? '换一个建议' : '生成建议',
|
|
1010
|
+
),
|
|
1011
|
+
message.needsHuman
|
|
1012
|
+
? h(
|
|
1013
|
+
Button,
|
|
1014
|
+
{ size: 'sm', variant: 'ghost', disabled: busy, onClick: () => onDismiss(message.id) },
|
|
1015
|
+
'忽略',
|
|
1016
|
+
)
|
|
1017
|
+
: null,
|
|
1018
|
+
),
|
|
1019
|
+
)
|
|
1020
|
+
: null,
|
|
1021
|
+
)
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// ------------------------------------------------------------------ 说明内容
|
|
1025
|
+
|
|
1026
|
+
const HELP_ITEMS = [
|
|
1027
|
+
[
|
|
1028
|
+
'授权',
|
|
1029
|
+
'首次使用点右上角「钉钉授权」:默认 loopback 模式会弹出钉钉授权页,扫码或登录即完成,不需要抄授权码;设备流才显示二维码与授权码。',
|
|
1030
|
+
],
|
|
1031
|
+
[
|
|
1032
|
+
'重新授权 / 退出',
|
|
1033
|
+
'已登录时按钮变成「重新授权」:默认会先退出已登录的组织再登录新的组织(配置 loginReset),所以始终只监听你本次授权的组织,不会越授权越多;想彻底断开就点旁边的「退出」。',
|
|
1034
|
+
],
|
|
1035
|
+
['接收', '插件自动登录 dws 后订阅「私信」与「群 @我」两类事件,消息到达即刻推送到本页,无需刷新。'],
|
|
1036
|
+
['消息源', '每条消息记录发送人、来源类型(私信 / 群 @)、群名称与时间;顶部「来源」筛选条按发送人与群聚合统计。'],
|
|
1037
|
+
[
|
|
1038
|
+
'来源筛选',
|
|
1039
|
+
'来源条只占一行:按消息数排序,默认显示前 5 个,其余收进「还有 N 个 ▾」。点开可在面板里搜索来源、面板内滚动、一键清除筛选;当前选中的来源会被置顶,永远看得见。',
|
|
1040
|
+
],
|
|
1041
|
+
[
|
|
1042
|
+
'自动回复开关',
|
|
1043
|
+
'位于收件箱顶部。关闭时每条消息下方都有独立输入框;开启后 AI 先判断能否直接回复,没把握时在主界面弹框等你确认。',
|
|
1044
|
+
],
|
|
1045
|
+
[
|
|
1046
|
+
'可信度阈值',
|
|
1047
|
+
'开关下方的滑杆:建议置信度达到阈值且 AI 判断明确才会自动发出,低于阈值一律转人工确认;拖动即时生效并自动保存(40%–100%)。',
|
|
1048
|
+
],
|
|
1049
|
+
['匹配度', '每条消息都会标出模型对该回复的自评匹配度;自动回复的消息还会注明「达到阈值自动发送」。'],
|
|
1050
|
+
[
|
|
1051
|
+
'群 @ 回复',
|
|
1052
|
+
'群里的 @ 消息回复时会先在正文 @ 回发送人(谁 @ 我,我就 @ 谁),回复气泡上会标出「@发送人」;私信不 @。可用配置 groupReplyAt 关掉。',
|
|
1053
|
+
],
|
|
1054
|
+
[
|
|
1055
|
+
'连续多条',
|
|
1056
|
+
'对方要求「连发几条」时,AI 会把回复拆成 2~5 条短消息依次发出(每条之间隔 0.6 秒);建议提示行会显示「将分 N 条依次发送」,发出的气泡按 1/2/3 编号列出。自己输入时用换行分隔也能拆成多条。上限与间隔可用 multiSendMax / multiSendDelayMs 调整,multiSend 关闭后永远只发一条。',
|
|
1057
|
+
],
|
|
1058
|
+
[
|
|
1059
|
+
'图片消息',
|
|
1060
|
+
'收到的图片会自动下载并展示缩略图;当前模型支持视觉时会连同图片一起交给模型理解,模型不看图时按纯文本回复。',
|
|
1061
|
+
],
|
|
1062
|
+
[
|
|
1063
|
+
'上下文',
|
|
1064
|
+
'每个消息来源(私信按发送人、群 @ 按群)各有一条独立的滑动窗口,只保留最近 5 条:新消息进来就把最早一条挤出去。条数可在上方「自动回复」卡片里的「上下文窗口」下拉框直接改(2/3/5/8/10/15/20 条),也可以改配置项 windowMessages。生成建议时 AI 只看本来源窗口里的内容,所以不同群、不同人的对话不会串在一起;窗口还没攒满时会先用钉钉上该会话的最新消息补齐。',
|
|
1065
|
+
],
|
|
1066
|
+
['阴影建议', '输入框里的浅灰文字是 AI 生成的建议回复:按 Tab 一键补全,也可以直接改写,回车或点「发送」发到钉钉。'],
|
|
1067
|
+
['模型', '建议回复使用你在 DSH 里当前选中的大模型,收件箱卡片与设置页都会实时显示当前模型。'],
|
|
1068
|
+
['快捷键', 'Tab 补全建议,Enter 发送,Esc 收起输入框;弹框里同样适用。'],
|
|
1069
|
+
['发送通道', '回复通过 dws 以你本人的钉钉身份发出:群消息回到原群,私信回到原会话。'],
|
|
1070
|
+
]
|
|
1071
|
+
|
|
1072
|
+
const HELP_STEPS = [
|
|
1073
|
+
['1', '先完成钉钉授权', '点右上角「钉钉授权」,loopback 模式会弹出钉钉授权页,扫码或登录即完成,不用抄授权码;已登录时按钮变「重新授权」,会先退出旧组织再登录新的。'],
|
|
1074
|
+
['2', '选择工作方式', '打开「自动回复」:AI 判断明确就直接替你回复,没把握会在主界面弹框等你确认;关闭它,则每条消息下方都有独立输入框手动回复。'],
|
|
1075
|
+
['3', '按需调整阈值', '滑杆越高越保守:只有置信度达到阈值的建议才会自动发出,其余一律转人工确认;拖动即时生效并自动保存。'],
|
|
1076
|
+
]
|
|
1077
|
+
|
|
1078
|
+
function HelpContent() {
|
|
1079
|
+
return h(
|
|
1080
|
+
'div',
|
|
1081
|
+
{ className: 'dsh-dt-help' },
|
|
1082
|
+
h(
|
|
1083
|
+
'div',
|
|
1084
|
+
{ className: 'dsh-dt-helpsteps' },
|
|
1085
|
+
HELP_STEPS.map(([index, title, body]) =>
|
|
1086
|
+
h(
|
|
1087
|
+
'div',
|
|
1088
|
+
{ key: index, className: 'dsh-dt-helpstep' },
|
|
1089
|
+
h('div', { className: 'dsh-dt-stephead' }, h('i', null, index), h('span', null, title)),
|
|
1090
|
+
h('div', { className: 'dsh-dt-stepbody' }, body),
|
|
1091
|
+
),
|
|
1092
|
+
),
|
|
1093
|
+
),
|
|
1094
|
+
h(
|
|
1095
|
+
'div',
|
|
1096
|
+
{ className: 'dsh-dt-helpgrid' },
|
|
1097
|
+
HELP_ITEMS.map(([title, body]) =>
|
|
1098
|
+
h(
|
|
1099
|
+
'div',
|
|
1100
|
+
{ key: title, className: 'dsh-dt-helpitem' },
|
|
1101
|
+
h('div', { className: 'dsh-dt-helptag' }, title),
|
|
1102
|
+
h('div', { style: { fontSize: 12.5, lineHeight: 1.65, color: C.text } }, body),
|
|
1103
|
+
),
|
|
1104
|
+
),
|
|
1105
|
+
),
|
|
1106
|
+
h(
|
|
1107
|
+
'div',
|
|
1108
|
+
{ className: 'dsh-dt-links' },
|
|
1109
|
+
h(
|
|
1110
|
+
'a',
|
|
1111
|
+
{ href: REPO_URL, target: '_blank', rel: 'noopener noreferrer', title: '在 GitHub 上给这个插件点个 Star' },
|
|
1112
|
+
'★ Star',
|
|
1113
|
+
),
|
|
1114
|
+
h(
|
|
1115
|
+
'a',
|
|
1116
|
+
{ href: `${ISSUES_URL}/new`, target: '_blank', rel: 'noopener noreferrer', title: '反馈问题或提功能建议' },
|
|
1117
|
+
'🐞 提交 Issue',
|
|
1118
|
+
),
|
|
1119
|
+
h('a', { href: NPM_URL, target: '_blank', rel: 'noopener noreferrer', title: '在 npm 上查看版本与安装信息' }, 'npm'),
|
|
1120
|
+
h('span', null, '欢迎点赞或反馈问题'),
|
|
1121
|
+
),
|
|
1122
|
+
)
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// ------------------------------------------------------------------ 收件箱主面板
|
|
1126
|
+
|
|
1127
|
+
function listenerSummary(state) {
|
|
1128
|
+
const listeners = Array.isArray(state && state.listeners) ? state.listeners : []
|
|
1129
|
+
const online = listeners.filter((item) => item.status === 'online')
|
|
1130
|
+
const errors = listeners.filter((item) => item.status === 'error')
|
|
1131
|
+
const expired = Array.isArray(state && state.expiredProfiles) ? state.expiredProfiles.length : 0
|
|
1132
|
+
const expiredNote = expired > 0 ? ` · ${expired} 个组织登录已过期,建议重新授权` : ''
|
|
1133
|
+
if (!state || !state.enabled) return { dot: 'error', text: '插件已禁用', detail: '在设置 → 插件中启用后可用' }
|
|
1134
|
+
if (!state.tool || !state.tool.ok) {
|
|
1135
|
+
return { dot: 'error', text: 'dws 未就绪', detail: state.tool && state.tool.error ? state.tool.error : '请检查 dws 是否已安装并登录' }
|
|
1136
|
+
}
|
|
1137
|
+
if (online.length > 0) {
|
|
1138
|
+
return {
|
|
1139
|
+
dot: 'online',
|
|
1140
|
+
text: `实时监听中 · ${online.length} 个组织`,
|
|
1141
|
+
detail: `以 ${state.selfName || '当前账号'} 身份接收私信与群 @${expiredNote}`,
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (errors.length > 0) {
|
|
1145
|
+
return { dot: 'error', text: '监听异常', detail: `${errors[0].error || '正在重连,请稍候'}${expiredNote}` }
|
|
1146
|
+
}
|
|
1147
|
+
return { dot: 'connecting', text: '正在连接钉钉…', detail: `首次连接需要几秒钟${expiredNote}` }
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function needsAction(message) {
|
|
1151
|
+
if (message.dismissed) return false
|
|
1152
|
+
if (message.reply && message.reply.ok) return false
|
|
1153
|
+
return true
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// 上下文窗口可选项:2–20 条,默认 5 条(与 config.windowMessages 的取值范围一致)。
|
|
1157
|
+
const WINDOW_OPTIONS = [2, 3, 5, 8, 10, 15, 20]
|
|
1158
|
+
|
|
1159
|
+
// 来源筛选条:折叠时只显示「全部来源 + 计数最高的 5 个 + 还有 N 个」,
|
|
1160
|
+
// 不会因为来源变多而把后面的来源悄悄挤出可视区;展开后变成可换行、可搜索、可滚动的面板。
|
|
1161
|
+
const SOURCE_INLINE_MAX = 5
|
|
1162
|
+
|
|
1163
|
+
function sourceLabel(item) {
|
|
1164
|
+
if (!item) return '未知来源'
|
|
1165
|
+
return item.kind === 'group' ? item.conversationTitle || '未命名群聊' : item.sender || item.label || '未知来源'
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function SourceChip({ item, active, onClick }) {
|
|
1169
|
+
return h(
|
|
1170
|
+
'button',
|
|
1171
|
+
{
|
|
1172
|
+
type: 'button',
|
|
1173
|
+
className: 'dsh-dt-src',
|
|
1174
|
+
'data-active': active ? '1' : '0',
|
|
1175
|
+
onClick,
|
|
1176
|
+
title: `${item.kind === 'group' ? '群聊' : '私信'}:${sourceLabel(item)} · ${item.count} 条`,
|
|
1177
|
+
},
|
|
1178
|
+
h('span', {
|
|
1179
|
+
className: 'dsh-dt-dot',
|
|
1180
|
+
'data-state': item.kind === 'group' ? 'online' : 'connecting',
|
|
1181
|
+
style: { background: item.kind === 'group' ? C.warn : C.brand, animation: 'none' },
|
|
1182
|
+
}),
|
|
1183
|
+
h('span', { className: 'dsh-dt-srcname' }, sourceLabel(item)),
|
|
1184
|
+
h('span', { style: { opacity: 0.6, fontSize: 10.5 } }, item.count),
|
|
1185
|
+
)
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function SourceBar({ sources, total, value, onChange }) {
|
|
1189
|
+
// 默认折叠;调试/截图时可在页面里设 window.__DSH_DINGTALK_SOURCES_OPEN__ = true 让它一进来就展开。
|
|
1190
|
+
const [open, setOpen] = useState(
|
|
1191
|
+
() => Boolean(typeof window !== 'undefined' && window.__DSH_DINGTALK_SOURCES_OPEN__),
|
|
1192
|
+
)
|
|
1193
|
+
const [query, setQuery] = useState('')
|
|
1194
|
+
|
|
1195
|
+
const ordered = useMemo(() => {
|
|
1196
|
+
const list = [...(sources || [])]
|
|
1197
|
+
list.sort((a, b) => (b.count || 0) - (a.count || 0) || (b.lastAt || 0) - (a.lastAt || 0))
|
|
1198
|
+
return list
|
|
1199
|
+
}, [sources])
|
|
1200
|
+
|
|
1201
|
+
const selected = ordered.find((item) => item.key === value) || null
|
|
1202
|
+
const inline = useMemo(() => {
|
|
1203
|
+
const head = ordered.slice(0, SOURCE_INLINE_MAX)
|
|
1204
|
+
if (selected && !head.some((item) => item.key === selected.key)) head.unshift(selected)
|
|
1205
|
+
return head
|
|
1206
|
+
}, [ordered, selected])
|
|
1207
|
+
|
|
1208
|
+
const rest = ordered.length - inline.length
|
|
1209
|
+
const keyword = query.trim().toLowerCase()
|
|
1210
|
+
const panelList =
|
|
1211
|
+
keyword === ''
|
|
1212
|
+
? ordered
|
|
1213
|
+
: ordered.filter((item) => `${sourceLabel(item)} ${item.sender || ''} ${item.conversationTitle || ''}`.toLowerCase().includes(keyword))
|
|
1214
|
+
|
|
1215
|
+
return h(
|
|
1216
|
+
'div',
|
|
1217
|
+
null,
|
|
1218
|
+
h(
|
|
1219
|
+
'div',
|
|
1220
|
+
{ className: 'dsh-dt-sources' },
|
|
1221
|
+
h(
|
|
1222
|
+
'button',
|
|
1223
|
+
{
|
|
1224
|
+
type: 'button',
|
|
1225
|
+
className: 'dsh-dt-src',
|
|
1226
|
+
'data-active': value === '' ? '1' : '0',
|
|
1227
|
+
onClick: () => onChange(''),
|
|
1228
|
+
},
|
|
1229
|
+
'全部来源',
|
|
1230
|
+
h('span', { style: { opacity: 0.6 } }, total),
|
|
1231
|
+
),
|
|
1232
|
+
inline.map((item) =>
|
|
1233
|
+
h(SourceChip, {
|
|
1234
|
+
key: item.key,
|
|
1235
|
+
item,
|
|
1236
|
+
active: value === item.key,
|
|
1237
|
+
onClick: () => onChange(value === item.key ? '' : item.key),
|
|
1238
|
+
}),
|
|
1239
|
+
),
|
|
1240
|
+
rest > 0 || open
|
|
1241
|
+
? h(
|
|
1242
|
+
'button',
|
|
1243
|
+
{
|
|
1244
|
+
type: 'button',
|
|
1245
|
+
className: 'dsh-dt-src',
|
|
1246
|
+
'data-more': '1',
|
|
1247
|
+
onClick: () => setOpen((prev) => !prev),
|
|
1248
|
+
title: open ? '收起来源列表' : `还有 ${Math.max(rest, 0)} 个来源,点开查看全部`,
|
|
1249
|
+
},
|
|
1250
|
+
open ? '收起' : `还有 ${rest} 个`,
|
|
1251
|
+
h('span', { style: { opacity: 0.7, fontSize: 10.5 } }, open ? '▴' : '▾'),
|
|
1252
|
+
)
|
|
1253
|
+
: null,
|
|
1254
|
+
),
|
|
1255
|
+
open
|
|
1256
|
+
? h(
|
|
1257
|
+
'div',
|
|
1258
|
+
{ className: 'dsh-dt-srcpanel' },
|
|
1259
|
+
h(
|
|
1260
|
+
'div',
|
|
1261
|
+
{ className: 'dsh-dt-srcpanel-head' },
|
|
1262
|
+
h('span', null, `全部来源(${ordered.length})`),
|
|
1263
|
+
ordered.length > 8
|
|
1264
|
+
? h('input', {
|
|
1265
|
+
className: 'dsh-dt-srcsearch',
|
|
1266
|
+
value: query,
|
|
1267
|
+
placeholder: '按群名或发送人筛选来源…',
|
|
1268
|
+
onChange: (event) => setQuery(event.target.value),
|
|
1269
|
+
})
|
|
1270
|
+
: h('span', { style: { flex: 1 } }),
|
|
1271
|
+
value !== ''
|
|
1272
|
+
? h(
|
|
1273
|
+
Button,
|
|
1274
|
+
{ size: 'sm', variant: 'ghost', onClick: () => onChange('') },
|
|
1275
|
+
'清除筛选',
|
|
1276
|
+
)
|
|
1277
|
+
: null,
|
|
1278
|
+
),
|
|
1279
|
+
panelList.length === 0
|
|
1280
|
+
? h('div', { className: 'dsh-dt-hint' }, '没有匹配的来源')
|
|
1281
|
+
: h(
|
|
1282
|
+
'div',
|
|
1283
|
+
{ className: 'dsh-dt-srcpanel-body' },
|
|
1284
|
+
panelList.map((item) =>
|
|
1285
|
+
h(SourceChip, {
|
|
1286
|
+
key: item.key,
|
|
1287
|
+
item,
|
|
1288
|
+
active: value === item.key,
|
|
1289
|
+
onClick: () => onChange(value === item.key ? '' : item.key),
|
|
1290
|
+
}),
|
|
1291
|
+
),
|
|
1292
|
+
),
|
|
1293
|
+
)
|
|
1294
|
+
: null,
|
|
1295
|
+
)
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
function InboxPanel() {
|
|
1299
|
+
const { state, error } = useBridge()
|
|
1300
|
+
const [tab, setTab] = useState('all')
|
|
1301
|
+
const [query, setQuery] = useState('')
|
|
1302
|
+
const [sourceFilter, setSourceFilter] = useState('')
|
|
1303
|
+
const [helpOpen, setHelpOpen] = useState(false)
|
|
1304
|
+
const [busyId, setBusyId] = useState('')
|
|
1305
|
+
const [thresholdDraft, setThresholdDraft] = useState(null)
|
|
1306
|
+
const [pendingThreshold, setPendingThreshold] = useState(null)
|
|
1307
|
+
const [thresholdError, setThresholdError] = useState('')
|
|
1308
|
+
|
|
1309
|
+
const messages = useMemo(() => (state && Array.isArray(state.messages) ? state.messages : []), [state])
|
|
1310
|
+
const autoReply = Boolean(state && state.autoReply)
|
|
1311
|
+
const summary = listenerSummary(state)
|
|
1312
|
+
|
|
1313
|
+
const minConfidence = state && typeof state.minConfidence === 'number' ? state.minConfidence : 0.72
|
|
1314
|
+
const savedPct = Math.round(minConfidence * 100)
|
|
1315
|
+
// 滑杆用「百分数」当单位,state.minConfidence 是 0~1,两套单位不能相乘(否则 57 → 5700%)。
|
|
1316
|
+
// pendingThreshold:刚提交、还没被宿主确认的值,先显示它,避免「松手就跳回旧值」。
|
|
1317
|
+
useEffect(() => {
|
|
1318
|
+
if (pendingThreshold !== null && savedPct === pendingThreshold) setPendingThreshold(null)
|
|
1319
|
+
}, [pendingThreshold, savedPct])
|
|
1320
|
+
const thresholdPct = Math.round(
|
|
1321
|
+
thresholdDraft !== null ? thresholdDraft : pendingThreshold !== null ? pendingThreshold : savedPct,
|
|
1322
|
+
)
|
|
1323
|
+
const commitThreshold = useCallback((percent) => {
|
|
1324
|
+
const next = Math.max(40, Math.min(100, Math.round(Number(percent) || 0)))
|
|
1325
|
+
setThresholdDraft(null)
|
|
1326
|
+
setPendingThreshold(next)
|
|
1327
|
+
setThresholdError('')
|
|
1328
|
+
return postAction({ type: 'set-min-confidence', value: next / 100 }).then((data) => {
|
|
1329
|
+
const actual =
|
|
1330
|
+
data && data.state && typeof data.state.minConfidence === 'number'
|
|
1331
|
+
? Math.round(data.state.minConfidence * 100)
|
|
1332
|
+
: null
|
|
1333
|
+
if (actual === null || actual !== next) {
|
|
1334
|
+
setThresholdError(
|
|
1335
|
+
`阈值 ${next}% 没能保存(宿主返回 ${actual === null ? '空响应' : `${actual}%`}),请看页面顶部的错误提示。`,
|
|
1336
|
+
)
|
|
1337
|
+
}
|
|
1338
|
+
return data
|
|
1339
|
+
})
|
|
1340
|
+
}, [])
|
|
1341
|
+
// 拖动过程只改本地值(跟手、不打断手势),松手/失焦/键盘调整时才落库。
|
|
1342
|
+
const [dragging, setDragging] = useState(false)
|
|
1343
|
+
const previewThreshold = useCallback((percent) => {
|
|
1344
|
+
const next = Math.max(40, Math.min(100, Math.round(Number(percent) || 0)))
|
|
1345
|
+
setThresholdDraft(next)
|
|
1346
|
+
}, [])
|
|
1347
|
+
const finishThreshold = useCallback(
|
|
1348
|
+
(percent) => {
|
|
1349
|
+
setDragging(false)
|
|
1350
|
+
const next = Math.max(40, Math.min(100, Math.round(Number(percent) || 0)))
|
|
1351
|
+
setThresholdDraft(null)
|
|
1352
|
+
commitThreshold(next)
|
|
1353
|
+
},
|
|
1354
|
+
[commitThreshold],
|
|
1355
|
+
)
|
|
1356
|
+
|
|
1357
|
+
// 上下文窗口长度:每个来源各留最近 N 条,选中即保存(宿主会立刻裁剪已有窗口)。
|
|
1358
|
+
const windowMessages =
|
|
1359
|
+
state && typeof state.windowMessages === 'number' ? Math.round(state.windowMessages) : 5
|
|
1360
|
+
const commitWindow = useCallback((size) => {
|
|
1361
|
+
const next = Math.max(2, Math.min(20, Math.round(Number(size) || 5)))
|
|
1362
|
+
return postAction({ type: 'set-window-messages', value: next })
|
|
1363
|
+
}, [])
|
|
1364
|
+
|
|
1365
|
+
const model = (state && state.model) || null
|
|
1366
|
+
const modelLabel =
|
|
1367
|
+
model && model.model
|
|
1368
|
+
? `${model.model}`
|
|
1369
|
+
: state && state.autoSuggest
|
|
1370
|
+
? '跟随 DSH 当前模型'
|
|
1371
|
+
: '自动建议已关闭'
|
|
1372
|
+
const modelDetail =
|
|
1373
|
+
model && model.model
|
|
1374
|
+
? `${model.provider || '未知 provider'} / ${model.model}|来源:${{
|
|
1375
|
+
dsh: '跟随 DSH 当前模型',
|
|
1376
|
+
config: '插件配置指定',
|
|
1377
|
+
hybrid: '自定义 provider + DSH 模型',
|
|
1378
|
+
none: '未检测到模型',
|
|
1379
|
+
}[model.source] || '跟随 DSH 当前模型'}`
|
|
1380
|
+
: '建议回复会使用 DSH 平台当前正在使用的大模型'
|
|
1381
|
+
|
|
1382
|
+
const login = (state && state.login) || null
|
|
1383
|
+
const notLoggedIn = Boolean(state && Array.isArray(state.profiles) && state.profiles.length === 0)
|
|
1384
|
+
const loginPending = Boolean(login && login.status === 'pending')
|
|
1385
|
+
const orgCount = state && Array.isArray(state.profiles) ? state.profiles.length : 0
|
|
1386
|
+
const expiredCount = state && Array.isArray(state.expiredProfiles) ? state.expiredProfiles.length : 0
|
|
1387
|
+
|
|
1388
|
+
// 重新授权默认会先退出旧组织(loginReset),所以先让用户确认一次,避免误点断掉监听。
|
|
1389
|
+
const startLogin = useCallback(() => {
|
|
1390
|
+
const reset = !state || state.loginReset !== false
|
|
1391
|
+
if (orgCount > 0 && reset) {
|
|
1392
|
+
const confirmed = window.confirm(
|
|
1393
|
+
`重新授权会先退出当前已登录的 ${orgCount} 个钉钉组织,期间实时监听会短暂中断,然后请你在授权页登录新的组织。\n\n继续吗?`,
|
|
1394
|
+
)
|
|
1395
|
+
if (!confirmed) return Promise.resolve({ ok: false, error: 'cancelled' })
|
|
1396
|
+
}
|
|
1397
|
+
return postAction({ type: 'login-start' })
|
|
1398
|
+
}, [state, orgCount])
|
|
1399
|
+
|
|
1400
|
+
const logoutAll = useCallback(() => {
|
|
1401
|
+
const confirmed = window.confirm(
|
|
1402
|
+
`确定退出钉钉登录吗?\n\n会停掉实时监听并执行 dws auth logout(退出全部组织),退出后需要重新授权才能继续接收消息。`,
|
|
1403
|
+
)
|
|
1404
|
+
if (!confirmed) return Promise.resolve({ ok: false, error: 'cancelled' })
|
|
1405
|
+
return postAction({ type: 'logout' })
|
|
1406
|
+
}, [])
|
|
1407
|
+
|
|
1408
|
+
const counts = useMemo(() => {
|
|
1409
|
+
const total = messages.length
|
|
1410
|
+
const dm = messages.filter((item) => item.kind === 'dm').length
|
|
1411
|
+
const group = messages.filter((item) => item.kind === 'group').length
|
|
1412
|
+
const pending = messages.filter(needsAction).length
|
|
1413
|
+
return { total, dm, group, pending }
|
|
1414
|
+
}, [messages])
|
|
1415
|
+
|
|
1416
|
+
const filtered = useMemo(() => {
|
|
1417
|
+
const keyword = query.trim().toLowerCase()
|
|
1418
|
+
return messages.filter((item) => {
|
|
1419
|
+
if (tab === 'dm' && item.kind !== 'dm') return false
|
|
1420
|
+
if (tab === 'group' && item.kind !== 'group') return false
|
|
1421
|
+
if (tab === 'pending' && !needsAction(item)) return false
|
|
1422
|
+
if (sourceFilter !== '' && item.sourceKey !== sourceFilter) return false
|
|
1423
|
+
if (keyword !== '') {
|
|
1424
|
+
const haystack = `${item.sender} ${item.text} ${item.conversationTitle || ''}`.toLowerCase()
|
|
1425
|
+
if (!haystack.includes(keyword)) return false
|
|
1426
|
+
}
|
|
1427
|
+
return true
|
|
1428
|
+
})
|
|
1429
|
+
}, [messages, tab, sourceFilter, query])
|
|
1430
|
+
|
|
1431
|
+
const sources = useMemo(() => (state && Array.isArray(state.sources) ? state.sources.slice(0, 12) : []), [state])
|
|
1432
|
+
|
|
1433
|
+
const handleSend = useCallback(async (id, text) => {
|
|
1434
|
+
setBusyId(id)
|
|
1435
|
+
try {
|
|
1436
|
+
return await postAction({ type: 'send-reply', id, text })
|
|
1437
|
+
} finally {
|
|
1438
|
+
setBusyId('')
|
|
1439
|
+
}
|
|
1440
|
+
}, [])
|
|
1441
|
+
|
|
1442
|
+
const handleRegenerate = useCallback(async (id) => {
|
|
1443
|
+
setBusyId(id)
|
|
1444
|
+
try {
|
|
1445
|
+
return await postAction({ type: 'regenerate', id })
|
|
1446
|
+
} finally {
|
|
1447
|
+
setBusyId('')
|
|
1448
|
+
}
|
|
1449
|
+
}, [])
|
|
1450
|
+
|
|
1451
|
+
const handleDismiss = useCallback((id) => postAction({ type: 'dismiss', id }), [])
|
|
1452
|
+
|
|
1453
|
+
const toggleAuto = useCallback((next) => postAction({ type: 'set-auto-reply', enabled: next }), [])
|
|
1454
|
+
|
|
1455
|
+
const tabs = [
|
|
1456
|
+
{ id: 'all', label: '全部', count: counts.total },
|
|
1457
|
+
{ id: 'dm', label: '私信', count: counts.dm },
|
|
1458
|
+
{ id: 'group', label: '群 @', count: counts.group },
|
|
1459
|
+
{ id: 'pending', label: '待回复', count: counts.pending },
|
|
1460
|
+
]
|
|
1461
|
+
|
|
1462
|
+
return h(
|
|
1463
|
+
'div',
|
|
1464
|
+
{ className: 'dsh-dt-root' },
|
|
1465
|
+
h(Styles),
|
|
1466
|
+
h(
|
|
1467
|
+
'div',
|
|
1468
|
+
{ className: 'dsh-dt-header' },
|
|
1469
|
+
h(
|
|
1470
|
+
'div',
|
|
1471
|
+
{ style: { minWidth: 0 } },
|
|
1472
|
+
h(
|
|
1473
|
+
'div',
|
|
1474
|
+
{ className: 'dsh-dt-title' },
|
|
1475
|
+
h(BrandIcon, { size: 20 }),
|
|
1476
|
+
h('span', { className: 'dsh-dt-dot', 'data-state': summary.dot }),
|
|
1477
|
+
'钉钉消息自动化',
|
|
1478
|
+
),
|
|
1479
|
+
h(
|
|
1480
|
+
'div',
|
|
1481
|
+
{ className: 'dsh-dt-sub' },
|
|
1482
|
+
h('span', null, summary.text),
|
|
1483
|
+
summary.detail ? h('span', { style: { opacity: 0.7 } }, `· ${summary.detail}`) : null,
|
|
1484
|
+
),
|
|
1485
|
+
),
|
|
1486
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
1487
|
+
h(
|
|
1488
|
+
Button,
|
|
1489
|
+
{
|
|
1490
|
+
size: 'sm',
|
|
1491
|
+
variant: notLoggedIn || loginPending ? 'primary' : 'ghost',
|
|
1492
|
+
onClick: startLogin,
|
|
1493
|
+
title:
|
|
1494
|
+
login && login.status === 'pending'
|
|
1495
|
+
? '正在等待钉钉授权,点击重新展示授权方式'
|
|
1496
|
+
: notLoggedIn
|
|
1497
|
+
? '尚未登录钉钉,点击开始扫码授权'
|
|
1498
|
+
: '重新授权:会先退出当前组织,再登录新的组织',
|
|
1499
|
+
},
|
|
1500
|
+
login && login.status === 'pending' ? '授权中…' : notLoggedIn ? '钉钉授权' : '重新授权',
|
|
1501
|
+
),
|
|
1502
|
+
!notLoggedIn && !loginPending
|
|
1503
|
+
? h(
|
|
1504
|
+
Button,
|
|
1505
|
+
{
|
|
1506
|
+
size: 'sm',
|
|
1507
|
+
variant: 'ghost',
|
|
1508
|
+
onClick: logoutAll,
|
|
1509
|
+
title: '退出钉钉登录(dws auth logout),退出后需重新授权',
|
|
1510
|
+
},
|
|
1511
|
+
'退出',
|
|
1512
|
+
)
|
|
1513
|
+
: null,
|
|
1514
|
+
state && state.dryRun
|
|
1515
|
+
? h(
|
|
1516
|
+
Badge,
|
|
1517
|
+
{ tone: 'warn', title: '演练模式:只预览发送内容,不会真正发到钉钉' },
|
|
1518
|
+
'演练模式',
|
|
1519
|
+
)
|
|
1520
|
+
: null,
|
|
1521
|
+
state && state.build && String(state.build).indexOf(CLIENT_BUILD) !== 0
|
|
1522
|
+
? h(
|
|
1523
|
+
Badge,
|
|
1524
|
+
{
|
|
1525
|
+
tone: 'warn',
|
|
1526
|
+
title: `界面代码是 ${CLIENT_BUILD},正在跑的宿主代码是 ${state.build}。重启 DSH 后两端才会一致,否则新功能(如群 @ 回复)不会生效。`,
|
|
1527
|
+
},
|
|
1528
|
+
'宿主待重启',
|
|
1529
|
+
)
|
|
1530
|
+
: null,
|
|
1531
|
+
h(
|
|
1532
|
+
Button,
|
|
1533
|
+
{ size: 'sm', variant: 'ghost', onClick: () => postAction({ type: 'refresh' }), title: '刷新账号与监听状态' },
|
|
1534
|
+
'刷新',
|
|
1535
|
+
),
|
|
1536
|
+
h(
|
|
1537
|
+
Button,
|
|
1538
|
+
{
|
|
1539
|
+
size: 'sm',
|
|
1540
|
+
variant: 'ghost',
|
|
1541
|
+
onClick: () => postAction({ type: 'restart-listeners' }),
|
|
1542
|
+
title: '重启事件监听',
|
|
1543
|
+
},
|
|
1544
|
+
'重启监听',
|
|
1545
|
+
),
|
|
1546
|
+
h(
|
|
1547
|
+
Button,
|
|
1548
|
+
{
|
|
1549
|
+
size: 'sm',
|
|
1550
|
+
variant: helpOpen ? 'primary' : 'ghost',
|
|
1551
|
+
onClick: () => setHelpOpen((prev) => !prev),
|
|
1552
|
+
title: helpOpen ? '回到收件箱列表' : '只看使用说明与自动回复设置',
|
|
1553
|
+
},
|
|
1554
|
+
helpOpen ? '返回收件箱' : '使用说明',
|
|
1555
|
+
),
|
|
1556
|
+
h(
|
|
1557
|
+
Button,
|
|
1558
|
+
{
|
|
1559
|
+
size: 'sm',
|
|
1560
|
+
variant: 'ghost',
|
|
1561
|
+
onClick: () => openExternal(REPO_URL),
|
|
1562
|
+
title: '在 GitHub 上查看源码、点个 Star 支持作者',
|
|
1563
|
+
},
|
|
1564
|
+
'★ Star',
|
|
1565
|
+
),
|
|
1566
|
+
h(
|
|
1567
|
+
Button,
|
|
1568
|
+
{
|
|
1569
|
+
size: 'sm',
|
|
1570
|
+
variant: 'ghost',
|
|
1571
|
+
onClick: () => openExternal(`${ISSUES_URL}/new`),
|
|
1572
|
+
title: '提交 Issue:反馈问题或提功能建议',
|
|
1573
|
+
},
|
|
1574
|
+
'提交 Issue',
|
|
1575
|
+
),
|
|
1576
|
+
h('span', { className: 'dsh-dt-footnote' }, '欢迎点赞或反馈问题'),
|
|
1577
|
+
),
|
|
1578
|
+
|
|
1579
|
+
helpOpen ? null : h(
|
|
1580
|
+
'div',
|
|
1581
|
+
{ className: 'dsh-dt-toolbar' },
|
|
1582
|
+
h(
|
|
1583
|
+
'div',
|
|
1584
|
+
{ className: 'dsh-dt-tabs' },
|
|
1585
|
+
tabs.map((item) =>
|
|
1586
|
+
h(
|
|
1587
|
+
'button',
|
|
1588
|
+
{
|
|
1589
|
+
key: item.id,
|
|
1590
|
+
type: 'button',
|
|
1591
|
+
className: 'dsh-dt-tab',
|
|
1592
|
+
'data-active': tab === item.id ? '1' : '0',
|
|
1593
|
+
onClick: () => setTab(item.id),
|
|
1594
|
+
},
|
|
1595
|
+
item.label,
|
|
1596
|
+
h('span', { className: 'dsh-dt-count' }, item.count),
|
|
1597
|
+
),
|
|
1598
|
+
),
|
|
1599
|
+
),
|
|
1600
|
+
h(
|
|
1601
|
+
'div',
|
|
1602
|
+
{ className: 'dsh-dt-search' },
|
|
1603
|
+
h(
|
|
1604
|
+
'svg',
|
|
1605
|
+
{ width: 13, height: 13, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
|
|
1606
|
+
h('circle', { cx: 7, cy: 7, r: 5, stroke: C.sub, strokeWidth: 1.6 }),
|
|
1607
|
+
h('path', { d: 'M11 11l3.2 3.2', stroke: C.sub, strokeWidth: 1.6, strokeLinecap: 'round' }),
|
|
1608
|
+
),
|
|
1609
|
+
h('input', {
|
|
1610
|
+
value: query,
|
|
1611
|
+
placeholder: '搜索发送人、群名或内容…',
|
|
1612
|
+
onChange: (event) => setQuery(event.target.value),
|
|
1613
|
+
'aria-label': '搜索消息',
|
|
1614
|
+
}),
|
|
1615
|
+
query !== ''
|
|
1616
|
+
? h(
|
|
1617
|
+
'button',
|
|
1618
|
+
{
|
|
1619
|
+
type: 'button',
|
|
1620
|
+
className: 'dsh-dt-btn',
|
|
1621
|
+
'data-variant': 'ghost',
|
|
1622
|
+
'data-size': 'sm',
|
|
1623
|
+
style: { height: 22, padding: '0 6px' },
|
|
1624
|
+
onClick: () => setQuery(''),
|
|
1625
|
+
},
|
|
1626
|
+
'×',
|
|
1627
|
+
)
|
|
1628
|
+
: null,
|
|
1629
|
+
),
|
|
1630
|
+
h(
|
|
1631
|
+
Button,
|
|
1632
|
+
{
|
|
1633
|
+
size: 'sm',
|
|
1634
|
+
variant: 'ghost',
|
|
1635
|
+
onClick: () => {
|
|
1636
|
+
if (typeof window !== 'undefined' && typeof window.confirm === 'function') {
|
|
1637
|
+
if (!window.confirm('确定清空本地收件箱记录吗?不会影响钉钉里的消息。')) return
|
|
1638
|
+
}
|
|
1639
|
+
postAction({ type: 'clear-inbox' })
|
|
1640
|
+
},
|
|
1641
|
+
},
|
|
1642
|
+
'清空',
|
|
1643
|
+
),
|
|
1644
|
+
),
|
|
1645
|
+
|
|
1646
|
+
h(
|
|
1647
|
+
'div',
|
|
1648
|
+
{ className: 'dsh-dt-autocfg', 'data-on': autoReply ? '1' : '0' },
|
|
1649
|
+
h(
|
|
1650
|
+
'div',
|
|
1651
|
+
{
|
|
1652
|
+
style: {
|
|
1653
|
+
width: 34,
|
|
1654
|
+
height: 34,
|
|
1655
|
+
borderRadius: 10,
|
|
1656
|
+
flex: 'none',
|
|
1657
|
+
display: 'flex',
|
|
1658
|
+
alignItems: 'center',
|
|
1659
|
+
justifyContent: 'center',
|
|
1660
|
+
background: autoReply ? 'rgba(46,124,246,.14)' : C.layer2,
|
|
1661
|
+
border: `1px solid ${autoReply ? 'rgba(46,124,246,.28)' : C.border1}`,
|
|
1662
|
+
},
|
|
1663
|
+
},
|
|
1664
|
+
h(
|
|
1665
|
+
'svg',
|
|
1666
|
+
{ width: 17, height: 17, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': 'true' },
|
|
1667
|
+
h('path', {
|
|
1668
|
+
d: 'M4 12a8 8 0 1 1 3.1 6.3L4 20l1.2-3.4A7.96 7.96 0 0 1 4 12Z',
|
|
1669
|
+
stroke: autoReply ? C.brand : C.sub,
|
|
1670
|
+
strokeWidth: 1.7,
|
|
1671
|
+
strokeLinejoin: 'round',
|
|
1672
|
+
}),
|
|
1673
|
+
h('path', {
|
|
1674
|
+
d: 'M9 11h6M9 14.5h3.5',
|
|
1675
|
+
stroke: autoReply ? C.brand : C.sub,
|
|
1676
|
+
strokeWidth: 1.7,
|
|
1677
|
+
strokeLinecap: 'round',
|
|
1678
|
+
}),
|
|
1679
|
+
),
|
|
1680
|
+
),
|
|
1681
|
+
h(
|
|
1682
|
+
'div',
|
|
1683
|
+
{ style: { flex: 1, minWidth: 180 } },
|
|
1684
|
+
h(
|
|
1685
|
+
'div',
|
|
1686
|
+
{ className: 'dsh-dt-autocfg-title' },
|
|
1687
|
+
'自动回复',
|
|
1688
|
+
h(Badge, { tone: autoReply ? 'brand' : 'idle' }, autoReply ? '已开启' : '已关闭'),
|
|
1689
|
+
),
|
|
1690
|
+
h(
|
|
1691
|
+
'div',
|
|
1692
|
+
{ className: 'dsh-dt-autocfg-desc' },
|
|
1693
|
+
autoReply
|
|
1694
|
+
? `收到消息后由 AI 结合上下文直接回复;置信度低于 ${confidenceText(state && state.minConfidence)} 或判断不明确时,会在主界面弹框请你确认。`
|
|
1695
|
+
: '开启后自动判断并回复钉钉消息;关闭时每条消息下方都有独立输入框,可手动选用建议回复。',
|
|
1696
|
+
),
|
|
1697
|
+
),
|
|
1698
|
+
h(Switch, { checked: autoReply, onChange: toggleAuto, label: '自动回复开关' }),
|
|
1699
|
+
h(
|
|
1700
|
+
'div',
|
|
1701
|
+
{ className: 'dsh-dt-autocfg-extra' },
|
|
1702
|
+
h(
|
|
1703
|
+
'div',
|
|
1704
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 9, flexWrap: 'wrap' } },
|
|
1705
|
+
h('span', { className: 'dsh-dt-hint', style: { whiteSpace: 'nowrap' } }, '自动回复阈值'),
|
|
1706
|
+
h(
|
|
1707
|
+
'div',
|
|
1708
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 1 } },
|
|
1709
|
+
h('input', {
|
|
1710
|
+
className: 'dsh-dt-range',
|
|
1711
|
+
type: 'range',
|
|
1712
|
+
min: 40,
|
|
1713
|
+
max: 100,
|
|
1714
|
+
step: 1,
|
|
1715
|
+
value: thresholdPct,
|
|
1716
|
+
disabled: !autoReply,
|
|
1717
|
+
'aria-label': '自动回复可信度阈值',
|
|
1718
|
+
title: autoReply
|
|
1719
|
+
? '建议置信度达到该阈值且判断明确时,AI 直接替你回复'
|
|
1720
|
+
: '开启自动回复后才会生效',
|
|
1721
|
+
onChange: (event) => {
|
|
1722
|
+
setDragging(true)
|
|
1723
|
+
previewThreshold(event.target.value)
|
|
1724
|
+
},
|
|
1725
|
+
onPointerUp: (event) => finishThreshold(event.currentTarget.value),
|
|
1726
|
+
onMouseUp: (event) => finishThreshold(event.currentTarget.value),
|
|
1727
|
+
onTouchEnd: (event) => finishThreshold(event.currentTarget.value),
|
|
1728
|
+
onKeyUp: (event) => finishThreshold(event.currentTarget.value),
|
|
1729
|
+
onBlur: (event) => {
|
|
1730
|
+
if (dragging || thresholdDraft !== null) finishThreshold(event.currentTarget.value)
|
|
1731
|
+
},
|
|
1732
|
+
}),
|
|
1733
|
+
h('div', { className: 'dsh-dt-ticks' }, h('span', null, '40%'), h('span', null, '70%'), h('span', null, '100%')),
|
|
1734
|
+
),
|
|
1735
|
+
h('b', { style: { fontSize: 13, fontVariantNumeric: 'tabular-nums', minWidth: 38, color: autoReply ? C.brand : C.sub } }, `${thresholdPct}%`),
|
|
1736
|
+
),
|
|
1737
|
+
h(
|
|
1738
|
+
'div',
|
|
1739
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 7 } },
|
|
1740
|
+
h('span', { className: 'dsh-dt-hint', style: { whiteSpace: 'nowrap' } }, '上下文窗口'),
|
|
1741
|
+
h(
|
|
1742
|
+
'select',
|
|
1743
|
+
{
|
|
1744
|
+
className: 'dsh-dt-select',
|
|
1745
|
+
value: windowMessages,
|
|
1746
|
+
'aria-label': '每个来源保留的上下文条数',
|
|
1747
|
+
title: '每个消息来源(私信按发送人、群 @ 按群)各自保留最近 N 条消息,作为 AI 回复的上下文',
|
|
1748
|
+
onChange: (event) => commitWindow(Number(event.target.value)),
|
|
1749
|
+
},
|
|
1750
|
+
WINDOW_OPTIONS.map((size) => h('option', { key: size, value: size }, `${size} 条`)),
|
|
1751
|
+
),
|
|
1752
|
+
),
|
|
1753
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
1754
|
+
h(
|
|
1755
|
+
'div',
|
|
1756
|
+
{ className: 'dsh-dt-modelchip', title: modelDetail },
|
|
1757
|
+
h('span', { style: { opacity: 0.75 } }, '模型'),
|
|
1758
|
+
h('b', null, modelLabel),
|
|
1759
|
+
),
|
|
1760
|
+
h(
|
|
1761
|
+
'div',
|
|
1762
|
+
{ className: 'dsh-dt-hint', style: { width: '100%', opacity: autoReply ? 1 : 0.6 } },
|
|
1763
|
+
autoReply
|
|
1764
|
+
? `置信度 ≥ ${thresholdPct}% 且模型判断明确时自动发送;低于阈值会弹框请你确认`
|
|
1765
|
+
: '阈值仅在开启自动回复后生效',
|
|
1766
|
+
),
|
|
1767
|
+
thresholdError !== ''
|
|
1768
|
+
? h('div', { className: 'dsh-dt-hint', style: { width: '100%', color: C.error } }, thresholdError)
|
|
1769
|
+
: null,
|
|
1770
|
+
),
|
|
1771
|
+
),
|
|
1772
|
+
|
|
1773
|
+
helpOpen || sources.length === 0
|
|
1774
|
+
? null
|
|
1775
|
+
: h(SourceBar, {
|
|
1776
|
+
sources,
|
|
1777
|
+
total: counts.total,
|
|
1778
|
+
value: sourceFilter,
|
|
1779
|
+
onChange: setSourceFilter,
|
|
1780
|
+
}),
|
|
1781
|
+
|
|
1782
|
+
helpOpen
|
|
1783
|
+
? h(
|
|
1784
|
+
'div',
|
|
1785
|
+
{ className: 'dsh-dt-helpbox' },
|
|
1786
|
+
h(
|
|
1787
|
+
'div',
|
|
1788
|
+
{ className: 'dsh-dt-helphead' },
|
|
1789
|
+
h('span', { style: { fontSize: 13.5, fontWeight: 680 } }, '使用说明'),
|
|
1790
|
+
h('span', { className: 'dsh-dt-hint' }, '只看说明与自动回复设置,收件箱已隐藏'),
|
|
1791
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
1792
|
+
h(
|
|
1793
|
+
Button,
|
|
1794
|
+
{ size: 'sm', variant: 'ghost', onClick: () => setHelpOpen(false) },
|
|
1795
|
+
'返回收件箱',
|
|
1796
|
+
),
|
|
1797
|
+
),
|
|
1798
|
+
h(HelpContent),
|
|
1799
|
+
)
|
|
1800
|
+
: null,
|
|
1801
|
+
|
|
1802
|
+
!helpOpen && state && state.inboxNotice
|
|
1803
|
+
? h(
|
|
1804
|
+
'div',
|
|
1805
|
+
{ className: 'dsh-dt-notice', style: { margin: '10px 20px 0' } },
|
|
1806
|
+
h('span', null, `ℹ ${state.inboxNotice}`),
|
|
1807
|
+
)
|
|
1808
|
+
: null,
|
|
1809
|
+
|
|
1810
|
+
helpOpen ? null : h(
|
|
1811
|
+
'div',
|
|
1812
|
+
{
|
|
1813
|
+
className: 'dsh-dt-listbox',
|
|
1814
|
+
'data-empty': !state || filtered.length === 0 ? '1' : '0',
|
|
1815
|
+
},
|
|
1816
|
+
!state
|
|
1817
|
+
? h(
|
|
1818
|
+
'div',
|
|
1819
|
+
{ className: 'dsh-dt-list' },
|
|
1820
|
+
error
|
|
1821
|
+
? h(EmptyState, {
|
|
1822
|
+
title: '无法连接插件服务',
|
|
1823
|
+
description: `${error}。请确认插件已在设置中启用,并重启一次 DSH。`,
|
|
1824
|
+
})
|
|
1825
|
+
: h(
|
|
1826
|
+
'div',
|
|
1827
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 11 } },
|
|
1828
|
+
h('div', { className: 'dsh-dt-skel' }),
|
|
1829
|
+
h('div', { className: 'dsh-dt-skel' }),
|
|
1830
|
+
h('div', { className: 'dsh-dt-skel' }),
|
|
1831
|
+
),
|
|
1832
|
+
)
|
|
1833
|
+
: filtered.length === 0
|
|
1834
|
+
? h(
|
|
1835
|
+
'div',
|
|
1836
|
+
{ className: 'dsh-dt-list' },
|
|
1837
|
+
h(EmptyState, {
|
|
1838
|
+
title: messages.length === 0 ? '还没有收到消息' : '当前筛选下没有消息',
|
|
1839
|
+
description:
|
|
1840
|
+
messages.length === 0
|
|
1841
|
+
? '保持页面打开即可。当有人给你发钉钉私信或在群里 @ 你时,消息会实时出现在这里。'
|
|
1842
|
+
: '试试切换「私信 / 群 @ / 待回复」,或清空搜索与来源筛选。',
|
|
1843
|
+
}),
|
|
1844
|
+
)
|
|
1845
|
+
: h(
|
|
1846
|
+
'div',
|
|
1847
|
+
{ className: 'dsh-dt-list' },
|
|
1848
|
+
filtered.map((message) =>
|
|
1849
|
+
h(MessageCard, {
|
|
1850
|
+
key: message.id,
|
|
1851
|
+
message,
|
|
1852
|
+
autoReply,
|
|
1853
|
+
groupReplyAt: state ? state.groupReplyAt !== false : true,
|
|
1854
|
+
busy: busyId === message.id,
|
|
1855
|
+
onSend: handleSend,
|
|
1856
|
+
onRegenerate: handleRegenerate,
|
|
1857
|
+
onDismiss: handleDismiss,
|
|
1858
|
+
}),
|
|
1859
|
+
),
|
|
1860
|
+
),
|
|
1861
|
+
),
|
|
1862
|
+
|
|
1863
|
+
error && state
|
|
1864
|
+
? h(
|
|
1865
|
+
'div',
|
|
1866
|
+
{
|
|
1867
|
+
style: {
|
|
1868
|
+
padding: '8px 20px',
|
|
1869
|
+
borderTop: `1px solid ${C.border1}`,
|
|
1870
|
+
fontSize: 11.5,
|
|
1871
|
+
color: C.error,
|
|
1872
|
+
background: 'rgba(229,72,77,.05)',
|
|
1873
|
+
},
|
|
1874
|
+
},
|
|
1875
|
+
`连接提示:${error}`,
|
|
1876
|
+
)
|
|
1877
|
+
: null,
|
|
1878
|
+
)
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// ------------------------------------------------------------------ 全局弹框
|
|
1882
|
+
|
|
1883
|
+
function AttentionModal() {
|
|
1884
|
+
const { state } = useBridge()
|
|
1885
|
+
const [index, setIndex] = useState(0)
|
|
1886
|
+
const [value, setValue] = useState('')
|
|
1887
|
+
const [busy, setBusy] = useState(false)
|
|
1888
|
+
|
|
1889
|
+
const pending = useMemo(() => {
|
|
1890
|
+
const messages = state && Array.isArray(state.messages) ? state.messages : []
|
|
1891
|
+
return messages.filter(
|
|
1892
|
+
(item) => item.needsHuman && !item.dismissed && !(item.reply && item.reply.ok) && item.status !== 'replied',
|
|
1893
|
+
)
|
|
1894
|
+
}, [state])
|
|
1895
|
+
|
|
1896
|
+
const current = pending.length > 0 ? pending[Math.min(index, pending.length - 1)] : null
|
|
1897
|
+
const currentId = current ? current.id : ''
|
|
1898
|
+
|
|
1899
|
+
useEffect(() => {
|
|
1900
|
+
setValue('')
|
|
1901
|
+
}, [currentId])
|
|
1902
|
+
|
|
1903
|
+
const visible = Boolean(state && state.notifyModal && state.autoReply && current)
|
|
1904
|
+
if (!visible) return null
|
|
1905
|
+
|
|
1906
|
+
const suggestion = current.suggestion && current.suggestion.text ? current.suggestion.text : ''
|
|
1907
|
+
const text = value.trim() !== '' ? value.trim() : suggestion
|
|
1908
|
+
|
|
1909
|
+
const send = async () => {
|
|
1910
|
+
if (text === '' || busy) return
|
|
1911
|
+
setBusy(true)
|
|
1912
|
+
try {
|
|
1913
|
+
await postAction({ type: 'send-reply', id: current.id, text })
|
|
1914
|
+
setValue('')
|
|
1915
|
+
} finally {
|
|
1916
|
+
setBusy(false)
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
const dismiss = async () => {
|
|
1921
|
+
await postAction({ type: 'dismiss', id: current.id })
|
|
1922
|
+
setValue('')
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
const regenerate = async () => {
|
|
1926
|
+
setBusy(true)
|
|
1927
|
+
try {
|
|
1928
|
+
await postAction({ type: 'regenerate', id: current.id })
|
|
1929
|
+
} finally {
|
|
1930
|
+
setBusy(false)
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
return h(
|
|
1935
|
+
'div',
|
|
1936
|
+
{ className: 'dsh-dt-modal-overlay', role: 'dialog', 'aria-modal': 'true' },
|
|
1937
|
+
h(Styles),
|
|
1938
|
+
h(
|
|
1939
|
+
'div',
|
|
1940
|
+
{ className: 'dsh-dt-modal' },
|
|
1941
|
+
h(
|
|
1942
|
+
'div',
|
|
1943
|
+
{ className: 'dsh-dt-modal-title' },
|
|
1944
|
+
h('span', { className: 'dsh-dt-dot', 'data-state': 'connecting' }),
|
|
1945
|
+
'需要你确认的回复',
|
|
1946
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
1947
|
+
pending.length > 1
|
|
1948
|
+
? h(
|
|
1949
|
+
'div',
|
|
1950
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
1951
|
+
h(
|
|
1952
|
+
Button,
|
|
1953
|
+
{
|
|
1954
|
+
size: 'sm',
|
|
1955
|
+
variant: 'ghost',
|
|
1956
|
+
onClick: () => setIndex((prev) => (prev + 1) % pending.length),
|
|
1957
|
+
},
|
|
1958
|
+
'下一条',
|
|
1959
|
+
),
|
|
1960
|
+
h('span', { className: 'dsh-dt-hint' }, `${Math.min(index + 1, pending.length)} / ${pending.length}`),
|
|
1961
|
+
)
|
|
1962
|
+
: null,
|
|
1963
|
+
),
|
|
1964
|
+
h(
|
|
1965
|
+
'div',
|
|
1966
|
+
{ className: 'dsh-dt-modal-sub' },
|
|
1967
|
+
`有 `,
|
|
1968
|
+
h('b', null, current.sender),
|
|
1969
|
+
` 发送的`,
|
|
1970
|
+
h('b', null, current.kind === 'group' ? '群 @ ' : '私信'),
|
|
1971
|
+
`消息`,
|
|
1972
|
+
current.kind === 'group' && current.conversationTitle
|
|
1973
|
+
? h('span', null, `(${current.conversationTitle})`)
|
|
1974
|
+
: null,
|
|
1975
|
+
h('span', { style: { opacity: 0.7 } }, ` · ${timeLabel(current.at)}`),
|
|
1976
|
+
),
|
|
1977
|
+
h('div', { className: 'dsh-dt-modal-quote' }, current.text),
|
|
1978
|
+
current.images && current.images.length > 0
|
|
1979
|
+
? h(MessageImages, { id: current.id, images: current.images })
|
|
1980
|
+
: null,
|
|
1981
|
+
suggestion !== ''
|
|
1982
|
+
? h(
|
|
1983
|
+
'div',
|
|
1984
|
+
{ className: 'dsh-dt-hint', style: { marginTop: 10 } },
|
|
1985
|
+
`建议回复(置信度 ${confidenceText(current.suggestion.confidence)})`,
|
|
1986
|
+
current.suggestion.reason ? ` · ${String(current.suggestion.reason).slice(0, 80)}` : '',
|
|
1987
|
+
)
|
|
1988
|
+
: h('div', { className: 'dsh-dt-hint', style: { marginTop: 10 } }, '暂未生成建议,可直接输入回复'),
|
|
1989
|
+
h(
|
|
1990
|
+
'div',
|
|
1991
|
+
{ style: { marginTop: 8, display: 'flex', gap: 8, alignItems: 'center' } },
|
|
1992
|
+
h(GhostInput, {
|
|
1993
|
+
value,
|
|
1994
|
+
suggestion,
|
|
1995
|
+
disabled: busy,
|
|
1996
|
+
placeholder: '输入回复,Tab 补全建议…',
|
|
1997
|
+
onChange: setValue,
|
|
1998
|
+
onSubmit: send,
|
|
1999
|
+
ariaLabel: '确认回复内容',
|
|
2000
|
+
autoFocus: true,
|
|
2001
|
+
}),
|
|
2002
|
+
h(
|
|
2003
|
+
Button,
|
|
2004
|
+
{ variant: 'primary', disabled: busy || text === '', onClick: send },
|
|
2005
|
+
busy ? '发送中…' : '发送',
|
|
2006
|
+
),
|
|
2007
|
+
),
|
|
2008
|
+
h(
|
|
2009
|
+
'div',
|
|
2010
|
+
{ className: 'dsh-dt-modal-foot' },
|
|
2011
|
+
h('span', { className: 'dsh-dt-hint' }, 'Tab 补全建议', h('span', { className: 'dsh-dt-kbd' }, 'Enter'), '发送'),
|
|
2012
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
2013
|
+
h(Button, { size: 'sm', variant: 'ghost', disabled: busy, onClick: regenerate }, '换一条建议'),
|
|
2014
|
+
h(Button, { size: 'sm', variant: 'ghost', disabled: busy, onClick: dismiss }, '忽略'),
|
|
2015
|
+
),
|
|
2016
|
+
),
|
|
2017
|
+
)
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
// ------------------------------------------------------------------ 授权登录弹框
|
|
2021
|
+
|
|
2022
|
+
function AuthModal() {
|
|
2023
|
+
const { state } = useBridge()
|
|
2024
|
+
const login = (state && state.login) || null
|
|
2025
|
+
const [busy, setBusy] = useState(false)
|
|
2026
|
+
// 拿到授权链接就自动打开一次浏览器授权页(弹窗被拦截时弹框里的二维码仍然可用)。
|
|
2027
|
+
const openedRef = useRef(false)
|
|
2028
|
+
useEffect(() => {
|
|
2029
|
+
const pending = login && login.status === 'pending' ? login.url || '' : ''
|
|
2030
|
+
if (pending === '' || openedRef.current) return
|
|
2031
|
+
openedRef.current = true
|
|
2032
|
+
try {
|
|
2033
|
+
if (typeof window !== 'undefined') window.open(pending, '_blank', 'noopener,noreferrer')
|
|
2034
|
+
} catch {
|
|
2035
|
+
// 忽略:用户仍可扫码或点按钮打开。
|
|
2036
|
+
}
|
|
2037
|
+
}, [login])
|
|
2038
|
+
if (!login || (login.status !== 'pending' && login.status !== 'failed')) return null
|
|
2039
|
+
|
|
2040
|
+
const mode = login.mode === 'device' ? 'device' : 'loopback'
|
|
2041
|
+
const code = login.code || ''
|
|
2042
|
+
const url = login.url || ''
|
|
2043
|
+
const qr = login.qr || ''
|
|
2044
|
+
const copy = async (text) => {
|
|
2045
|
+
try {
|
|
2046
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard) await navigator.clipboard.writeText(text)
|
|
2047
|
+
else if (typeof document !== 'undefined') {
|
|
2048
|
+
const area = document.createElement('textarea')
|
|
2049
|
+
area.value = text
|
|
2050
|
+
document.body.appendChild(area)
|
|
2051
|
+
area.select()
|
|
2052
|
+
document.execCommand('copy')
|
|
2053
|
+
document.body.removeChild(area)
|
|
2054
|
+
}
|
|
2055
|
+
} catch {
|
|
2056
|
+
// 复制失败不阻断流程。
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
const openUrl = () => {
|
|
2060
|
+
if (url === '') return
|
|
2061
|
+
try {
|
|
2062
|
+
if (typeof window !== 'undefined') window.open(url, '_blank', 'noopener,noreferrer')
|
|
2063
|
+
} catch {
|
|
2064
|
+
// 忽略。
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
const cancel = async () => {
|
|
2068
|
+
setBusy(true)
|
|
2069
|
+
try {
|
|
2070
|
+
await postAction({ type: 'login-cancel' })
|
|
2071
|
+
} finally {
|
|
2072
|
+
setBusy(false)
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
// 授权失败:留在弹框里说明原因,并给「重试 / 改用二维码」两条路。
|
|
2077
|
+
if (login.status === 'failed') {
|
|
2078
|
+
return h(
|
|
2079
|
+
'div',
|
|
2080
|
+
{ className: 'dsh-dt-modal-overlay', role: 'dialog', 'aria-modal': 'true' },
|
|
2081
|
+
h(Styles),
|
|
2082
|
+
h(
|
|
2083
|
+
'div',
|
|
2084
|
+
{ className: 'dsh-dt-modal', style: { maxWidth: '460px' } },
|
|
2085
|
+
h(
|
|
2086
|
+
'div',
|
|
2087
|
+
{ className: 'dsh-dt-modal-title' },
|
|
2088
|
+
h('span', { className: 'dsh-dt-dot', 'data-state': 'error' }),
|
|
2089
|
+
'钉钉授权未完成',
|
|
2090
|
+
),
|
|
2091
|
+
h(
|
|
2092
|
+
'div',
|
|
2093
|
+
{ className: 'dsh-dt-modal-sub' },
|
|
2094
|
+
login.message || '授权流程没有走完,请重试。',
|
|
2095
|
+
),
|
|
2096
|
+
login.error
|
|
2097
|
+
? h('div', { className: 'dsh-dt-hint', style: { marginTop: 8, color: C.error } }, String(login.error))
|
|
2098
|
+
: null,
|
|
2099
|
+
h(
|
|
2100
|
+
'div',
|
|
2101
|
+
{ style: { marginTop: 14, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
2102
|
+
h(
|
|
2103
|
+
Button,
|
|
2104
|
+
{
|
|
2105
|
+
variant: 'primary',
|
|
2106
|
+
disabled: busy,
|
|
2107
|
+
onClick: async () => {
|
|
2108
|
+
setBusy(true)
|
|
2109
|
+
try {
|
|
2110
|
+
await postAction({ type: 'login-start' })
|
|
2111
|
+
} finally {
|
|
2112
|
+
setBusy(false)
|
|
2113
|
+
}
|
|
2114
|
+
},
|
|
2115
|
+
},
|
|
2116
|
+
login.mode === 'device' ? '重新获取二维码' : '再试一次',
|
|
2117
|
+
),
|
|
2118
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
2119
|
+
h(Button, { size: 'sm', variant: 'ghost', disabled: busy, onClick: cancel }, '关闭'),
|
|
2120
|
+
),
|
|
2121
|
+
h(
|
|
2122
|
+
'div',
|
|
2123
|
+
{ className: 'dsh-dt-modal-foot' },
|
|
2124
|
+
h(
|
|
2125
|
+
'span',
|
|
2126
|
+
{ className: 'dsh-dt-hint' },
|
|
2127
|
+
login.mode === 'device'
|
|
2128
|
+
? '也可以把配置项 loginMode 改回 loopback,用浏览器扫码授权(不需要授权码)。'
|
|
2129
|
+
: '浏览器打不开或回调端口被拦截时,可把配置项 loginMode 改成 device,用二维码 + 授权码授权。',
|
|
2130
|
+
),
|
|
2131
|
+
),
|
|
2132
|
+
),
|
|
2133
|
+
)
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
return h(
|
|
2137
|
+
'div',
|
|
2138
|
+
{ className: 'dsh-dt-modal-overlay', role: 'dialog', 'aria-modal': 'true' },
|
|
2139
|
+
h(Styles),
|
|
2140
|
+
h(
|
|
2141
|
+
'div',
|
|
2142
|
+
{ className: 'dsh-dt-modal', style: { maxWidth: '460px' } },
|
|
2143
|
+
h(
|
|
2144
|
+
'div',
|
|
2145
|
+
{ className: 'dsh-dt-modal-title' },
|
|
2146
|
+
h('span', { className: 'dsh-dt-dot', 'data-state': 'connecting' }),
|
|
2147
|
+
'钉钉授权登录',
|
|
2148
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
2149
|
+
h(Badge, { tone: 'brand' }, '等待授权'),
|
|
2150
|
+
),
|
|
2151
|
+
h('div', { className: 'dsh-dt-modal-sub' }, login.message || '点击下方按钮,在弹出的钉钉页面里扫码或登录即可完成授权'),
|
|
2152
|
+
mode === 'device'
|
|
2153
|
+
? qr !== ''
|
|
2154
|
+
? h(
|
|
2155
|
+
'div',
|
|
2156
|
+
{ className: 'dsh-dt-qrwrap', style: { marginTop: 12 } },
|
|
2157
|
+
h('img', { className: 'dsh-dt-qr', src: qr, alt: '钉钉授权二维码' }),
|
|
2158
|
+
h('div', { className: 'dsh-dt-hint', style: { textAlign: 'center' } }, '打开钉钉扫一扫,确认授权即可'),
|
|
2159
|
+
)
|
|
2160
|
+
: h('div', { className: 'dsh-dt-skel', style: { height: 168, marginTop: 12, borderRadius: 12 } })
|
|
2161
|
+
: h(
|
|
2162
|
+
'div',
|
|
2163
|
+
{ className: 'dsh-dt-auth', style: { marginTop: 12 } },
|
|
2164
|
+
h('div', { className: 'dsh-dt-auth-icon' }, '①'),
|
|
2165
|
+
h(
|
|
2166
|
+
'div',
|
|
2167
|
+
{ style: { flex: 1, minWidth: 0 } },
|
|
2168
|
+
h('div', { style: { fontWeight: 600, fontSize: 13 } }, '在浏览器里完成一次授权'),
|
|
2169
|
+
h(
|
|
2170
|
+
'div',
|
|
2171
|
+
{ className: 'dsh-dt-hint', style: { marginTop: 3 } },
|
|
2172
|
+
'用钉钉扫码或输入账号密码登录,授权页会回调本机端口自动完成登录。',
|
|
2173
|
+
),
|
|
2174
|
+
h(
|
|
2175
|
+
'div',
|
|
2176
|
+
{ className: 'dsh-dt-hint', style: { marginTop: 2, color: C.success, fontWeight: 600 } },
|
|
2177
|
+
'不需要输入任何授权码',
|
|
2178
|
+
),
|
|
2179
|
+
),
|
|
2180
|
+
h(Button, { variant: 'primary', disabled: url === '', onClick: openUrl }, '打开钉钉授权页面'),
|
|
2181
|
+
),
|
|
2182
|
+
h(
|
|
2183
|
+
'div',
|
|
2184
|
+
{ style: { marginTop: 14, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
2185
|
+
mode === 'device'
|
|
2186
|
+
? h(Button, { variant: 'primary', disabled: url === '', onClick: openUrl }, '用浏览器打开授权页面')
|
|
2187
|
+
: h('span', { className: 'dsh-dt-hint' }, '页面没弹出来?点「复制链接」粘到浏览器打开。'),
|
|
2188
|
+
h('div', { className: 'dsh-dt-spacer' }),
|
|
2189
|
+
url !== '' && mode !== 'device'
|
|
2190
|
+
? h(Button, { size: 'sm', variant: 'ghost', onClick: () => copy(url) }, '复制链接')
|
|
2191
|
+
: null,
|
|
2192
|
+
h(Button, { size: 'sm', variant: 'ghost', disabled: busy, onClick: cancel }, '取消'),
|
|
2193
|
+
),
|
|
2194
|
+
mode === 'device' && (code !== '' || url !== '')
|
|
2195
|
+
? h(
|
|
2196
|
+
'details',
|
|
2197
|
+
{ style: { marginTop: 10 } },
|
|
2198
|
+
h(
|
|
2199
|
+
'summary',
|
|
2200
|
+
{ className: 'dsh-dt-hint', style: { cursor: 'pointer' } },
|
|
2201
|
+
'扫码不方便?手动输入授权码',
|
|
2202
|
+
),
|
|
2203
|
+
code !== ''
|
|
2204
|
+
? h('div', { className: 'dsh-dt-modal-code', style: { marginTop: 8 } }, code)
|
|
2205
|
+
: null,
|
|
2206
|
+
url !== ''
|
|
2207
|
+
? h(
|
|
2208
|
+
'a',
|
|
2209
|
+
{
|
|
2210
|
+
className: 'dsh-dt-modal-link',
|
|
2211
|
+
style: { marginTop: 8, display: 'block' },
|
|
2212
|
+
href: url,
|
|
2213
|
+
target: '_blank',
|
|
2214
|
+
rel: 'noopener noreferrer',
|
|
2215
|
+
},
|
|
2216
|
+
url,
|
|
2217
|
+
)
|
|
2218
|
+
: null,
|
|
2219
|
+
h(
|
|
2220
|
+
'div',
|
|
2221
|
+
{ style: { marginTop: 8, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
2222
|
+
code !== ''
|
|
2223
|
+
? h(Button, { size: 'sm', variant: 'ghost', onClick: () => copy(code) }, '复制授权码')
|
|
2224
|
+
: null,
|
|
2225
|
+
url !== ''
|
|
2226
|
+
? h(Button, { size: 'sm', variant: 'ghost', onClick: () => copy(url) }, '复制链接')
|
|
2227
|
+
: null,
|
|
2228
|
+
),
|
|
2229
|
+
)
|
|
2230
|
+
: null,
|
|
2231
|
+
h(
|
|
2232
|
+
'div',
|
|
2233
|
+
{ className: 'dsh-dt-modal-foot' },
|
|
2234
|
+
h(
|
|
2235
|
+
'span',
|
|
2236
|
+
{ className: 'dsh-dt-hint' },
|
|
2237
|
+
mode === 'device'
|
|
2238
|
+
? '在钉钉里确认后,本窗口会自动关闭并开始实时接收消息(二维码约 15 分钟内有效)。'
|
|
2239
|
+
: '授权页会回调本机端口自动完成登录,之后本窗口自动关闭并开始实时接收消息(链接约 15 分钟内有效)。',
|
|
2240
|
+
),
|
|
2241
|
+
),
|
|
2242
|
+
),
|
|
2243
|
+
)
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function GlobalOverlay() {
|
|
2247
|
+
const { state } = useBridge()
|
|
2248
|
+
// 待确认弹框优先:已经在等用户确认回复时,不再用授权弹框抢焦点。
|
|
2249
|
+
const attention = useMemo(() => {
|
|
2250
|
+
const messages = state && Array.isArray(state.messages) ? state.messages : []
|
|
2251
|
+
return messages.some(
|
|
2252
|
+
(item) => item.needsHuman && !item.dismissed && !(item.reply && item.reply.ok) && item.status !== 'replied',
|
|
2253
|
+
)
|
|
2254
|
+
}, [state])
|
|
2255
|
+
const attentionVisible = Boolean(state && state.notifyModal && state.autoReply && attention)
|
|
2256
|
+
return h('div', null, h(AttentionModal), attentionVisible ? null : h(AuthModal))
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
// ------------------------------------------------------------------ 设置页 / 配置卡片
|
|
2260
|
+
|
|
2261
|
+
function SettingsCard() {
|
|
2262
|
+
const { state, error } = useBridge()
|
|
2263
|
+
const summary = listenerSummary(state)
|
|
2264
|
+
const model = (state && state.model) || null
|
|
2265
|
+
const modelText =
|
|
2266
|
+
model && model.model
|
|
2267
|
+
? `${model.model}(${model.provider || '未知 provider'})`
|
|
2268
|
+
: state && state.autoSuggest
|
|
2269
|
+
? '跟随 DSH 当前模型(未读取到)'
|
|
2270
|
+
: '已关闭自动生成'
|
|
2271
|
+
const login = (state && state.login) || null
|
|
2272
|
+
const loginText =
|
|
2273
|
+
state && Array.isArray(state.profiles) && state.profiles.length > 0
|
|
2274
|
+
? `已登录${state.selfName ? `:${state.selfName}` : ''}`
|
|
2275
|
+
: login && login.status === 'pending'
|
|
2276
|
+
? '等待授权中…'
|
|
2277
|
+
: login && login.status === 'failed'
|
|
2278
|
+
? `授权失败:${login.message || login.error || '请重试'}`
|
|
2279
|
+
: '未登录,请点击「钉钉授权」'
|
|
2280
|
+
const rows = [
|
|
2281
|
+
['连接状态', `${summary.text}${summary.detail ? ` · ${summary.detail}` : ''}`],
|
|
2282
|
+
['钉钉授权', loginText],
|
|
2283
|
+
['当前账号', (state && state.selfName) || h('span', { style: { color: C.sub } }, '未读取到')],
|
|
2284
|
+
['组织 profile', (state && state.currentProfile) || h('span', { style: { color: C.sub } }, '未登录或未读取到')],
|
|
2285
|
+
[
|
|
2286
|
+
'已登录组织',
|
|
2287
|
+
state && Array.isArray(state.profiles) && state.profiles.length > 0
|
|
2288
|
+
? `${state.profiles.length} 个${
|
|
2289
|
+
state.expiredProfiles && state.expiredProfiles.length > 0
|
|
2290
|
+
? `(${state.expiredProfiles.length} 个登录已过期,建议重新授权)`
|
|
2291
|
+
: ''
|
|
2292
|
+
}`
|
|
2293
|
+
: '0 个',
|
|
2294
|
+
],
|
|
2295
|
+
['重新授权前先退出旧组织', state ? (state.loginReset === false ? '已关闭(会保留旧组织、追加新组织)' : '已开启(只保留本次新授权的组织)') : '—'],
|
|
2296
|
+
['自动回复', state ? (state.autoReply ? '已开启(AI 判断后自动发送)' : '已关闭(逐条手动确认)') : '—'],
|
|
2297
|
+
['自动回复阈值', state ? `${confidenceText(state.minConfidence)}(收件箱顶部可调)` : '—'],
|
|
2298
|
+
['建议回复模型', modelText],
|
|
2299
|
+
[
|
|
2300
|
+
'图片识别',
|
|
2301
|
+
state
|
|
2302
|
+
? state.imageRecognition
|
|
2303
|
+
? `已开启(每条最多 ${state.imageMax || 2} 张)${imageCapabilityText(state)}`
|
|
2304
|
+
: '已关闭(图片只显示不分析)'
|
|
2305
|
+
: '—',
|
|
2306
|
+
],
|
|
2307
|
+
[
|
|
2308
|
+
'上下文来源',
|
|
2309
|
+
state
|
|
2310
|
+
? state.remoteContext
|
|
2311
|
+
? `钉钉最新 ${state.remoteContextLimit || 10} 条 + 本地记录,共取 ${state.contextMessages || 6} 条`
|
|
2312
|
+
: `仅本地记录,取 ${state.contextMessages || 6} 条`
|
|
2313
|
+
: '—',
|
|
2314
|
+
],
|
|
2315
|
+
[
|
|
2316
|
+
'上下文窗口',
|
|
2317
|
+
state
|
|
2318
|
+
? `每个来源独立维护最近 ${state.windowMessages || 5} 条(当前已跟踪 ${state.windowCount || 0} 个来源),新消息自动滑入、最早的滑出(收件箱顶部可调)`
|
|
2319
|
+
: '—',
|
|
2320
|
+
],
|
|
2321
|
+
[
|
|
2322
|
+
'群 @ 回复',
|
|
2323
|
+
state ? (state.groupReplyAt === false ? '已关闭(群回复不再 @ 发送人)' : '已开启(群回复先 @ 回发送人)') : '—',
|
|
2324
|
+
],
|
|
2325
|
+
[
|
|
2326
|
+
'连续多条',
|
|
2327
|
+
state
|
|
2328
|
+
? state.multiSend === false
|
|
2329
|
+
? '已关闭(一次只发一条)'
|
|
2330
|
+
: `已开启(最多 ${state.multiSendMax || 5} 条,间隔 ${state.multiSendDelayMs || 600}ms)`
|
|
2331
|
+
: '—',
|
|
2332
|
+
],
|
|
2333
|
+
['dws 版本', state && state.tool && state.tool.version ? state.tool.version : '未检测到'],
|
|
2334
|
+
[
|
|
2335
|
+
'宿主版本',
|
|
2336
|
+
state && state.build
|
|
2337
|
+
? String(state.build).indexOf(CLIENT_BUILD) === 0
|
|
2338
|
+
? state.build
|
|
2339
|
+
: `${state.build}(与界面 ${CLIENT_BUILD} 不一致,请重启 DSH)`
|
|
2340
|
+
: '未上报(宿主代码较旧)',
|
|
2341
|
+
],
|
|
2342
|
+
[
|
|
2343
|
+
'最近请求',
|
|
2344
|
+
state && state.lastError
|
|
2345
|
+
? h('span', { style: { color: C.error } }, state.lastError)
|
|
2346
|
+
: state && Array.isArray(state.requests) && state.requests.length > 0
|
|
2347
|
+
? `${state.requests[state.requests.length - 1].method} → ${state.requests[state.requests.length - 1].status}`
|
|
2348
|
+
: '—',
|
|
2349
|
+
],
|
|
2350
|
+
['消息保留', '本地保留最近若干条,可随时在收件箱清空'],
|
|
2351
|
+
]
|
|
2352
|
+
|
|
2353
|
+
return h(
|
|
2354
|
+
'div',
|
|
2355
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
2356
|
+
h('div', { style: { fontSize: 13.5, fontWeight: 650 } }, '钉钉消息自动化'),
|
|
2357
|
+
h(
|
|
2358
|
+
'div',
|
|
2359
|
+
{ style: { fontSize: 12, color: C.sub, marginTop: 4, lineHeight: 1.6 } },
|
|
2360
|
+
'实时接收钉钉私信与群 @ 消息,按发送人记录来源;AI 生成建议回复,可选择自动回复或逐条确认。',
|
|
2361
|
+
),
|
|
2362
|
+
// 页面最顶端展示当前建议回复所用的模型(实时跟随 DSH 平台模型)。
|
|
2363
|
+
h(
|
|
2364
|
+
'div',
|
|
2365
|
+
{ className: 'dsh-dt-modelchip', style: { marginTop: 10, alignSelf: 'flex-start' } },
|
|
2366
|
+
h('span', { style: { opacity: 0.75 } }, '当前使用模型'),
|
|
2367
|
+
h('b', null, modelText),
|
|
2368
|
+
),
|
|
2369
|
+
h(
|
|
2370
|
+
'dl',
|
|
2371
|
+
{ className: 'dsh-dt-kv' },
|
|
2372
|
+
rows.map(([key, value]) =>
|
|
2373
|
+
h('div', { key, style: { display: 'contents' } }, h('dt', null, key), h('dd', null, value)),
|
|
2374
|
+
),
|
|
2375
|
+
),
|
|
2376
|
+
error
|
|
2377
|
+
? h('div', { style: { fontSize: 12, color: C.error, marginTop: 10 } }, `连接提示:${error}`)
|
|
2378
|
+
: null,
|
|
2379
|
+
h(
|
|
2380
|
+
'div',
|
|
2381
|
+
{ style: { display: 'flex', gap: 8, marginTop: 14, flexWrap: 'wrap' } },
|
|
2382
|
+
h(
|
|
2383
|
+
Button,
|
|
2384
|
+
{ size: 'sm', variant: 'primary', onClick: () => postAction({ type: 'login-start' }) },
|
|
2385
|
+
'钉钉授权 / 重新登录',
|
|
2386
|
+
),
|
|
2387
|
+
state && Array.isArray(state.profiles) && state.profiles.length > 0
|
|
2388
|
+
? h(Button, { size: 'sm', onClick: () => postAction({ type: 'logout' }) }, '退出钉钉登录')
|
|
2389
|
+
: null,
|
|
2390
|
+
h(Button, { size: 'sm', onClick: () => postAction({ type: 'refresh' }) }, '刷新状态'),
|
|
2391
|
+
h(Button, { size: 'sm', onClick: () => postAction({ type: 'restart-listeners' }) }, '重启监听'),
|
|
2392
|
+
),
|
|
2393
|
+
h('div', { style: { fontSize: 12, fontWeight: 620, marginTop: 18 } }, '使用说明'),
|
|
2394
|
+
h(HelpContent),
|
|
2395
|
+
h(
|
|
2396
|
+
'div',
|
|
2397
|
+
{ style: { fontSize: 11.5, color: C.sub, marginTop: 14, lineHeight: 1.6 } },
|
|
2398
|
+
'详细文档见插件目录 docs/使用说明.md;配置项在下方「插件配置」中修改后需重启 DSH 生效。',
|
|
2399
|
+
),
|
|
2400
|
+
)
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
function SettingsSection() {
|
|
2404
|
+
return h('div', { style: { padding: '4px 0' } }, h(Styles), h(SettingsCard))
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
function PluginConfigCard() {
|
|
2408
|
+
return h(
|
|
2409
|
+
'div',
|
|
2410
|
+
{ style: { padding: '2px 0' } },
|
|
2411
|
+
h(Styles),
|
|
2412
|
+
h(
|
|
2413
|
+
'div',
|
|
2414
|
+
{ style: { fontSize: 12, color: C.sub, marginBottom: 10, lineHeight: 1.6 } },
|
|
2415
|
+
'以下为宿主侧配置(监听开关、置信度阈值、模型选择等),保存后需重启 DSH 生效;收件箱顶部的「自动回复」开关可在运行时即时切换。',
|
|
2416
|
+
),
|
|
2417
|
+
h(SettingsCard),
|
|
2418
|
+
)
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
// ------------------------------------------------------------------ 品牌图标
|
|
2422
|
+
|
|
2423
|
+
const ICON_URL = `${API}/icon`
|
|
2424
|
+
|
|
2425
|
+
/**
|
|
2426
|
+
* 插件图标:优先用 icon.png 里的彩色机器人图(由宿主 GET /icon 提供),
|
|
2427
|
+
* 加载失败时退回单色矢量图,保证任何主题下都有图标可看。
|
|
2428
|
+
*/
|
|
2429
|
+
function BrandIcon(props) {
|
|
2430
|
+
const size = props && Number(props.size) > 0 ? Number(props.size) : 18
|
|
2431
|
+
const [failed, setFailed] = useState(false)
|
|
2432
|
+
const radius = Math.max(4, Math.round(size * 0.26))
|
|
2433
|
+
if (!failed) {
|
|
2434
|
+
return h('img', {
|
|
2435
|
+
src: ICON_URL,
|
|
2436
|
+
width: size,
|
|
2437
|
+
height: size,
|
|
2438
|
+
alt: '钉钉消息自动化',
|
|
2439
|
+
draggable: false,
|
|
2440
|
+
onError: () => setFailed(true),
|
|
2441
|
+
style: {
|
|
2442
|
+
width: `${size}px`,
|
|
2443
|
+
height: `${size}px`,
|
|
2444
|
+
borderRadius: `${radius}px`,
|
|
2445
|
+
objectFit: 'cover',
|
|
2446
|
+
display: 'block',
|
|
2447
|
+
flex: 'none',
|
|
2448
|
+
boxShadow: '0 1px 3px rgba(16,24,40,.22)',
|
|
2449
|
+
},
|
|
2450
|
+
})
|
|
2451
|
+
}
|
|
2452
|
+
return h(
|
|
2453
|
+
'svg',
|
|
2454
|
+
{
|
|
2455
|
+
width: size,
|
|
2456
|
+
height: size,
|
|
2457
|
+
viewBox: '0 0 48 48',
|
|
2458
|
+
fill: 'none',
|
|
2459
|
+
'aria-hidden': 'true',
|
|
2460
|
+
style: { display: 'block', flex: 'none' },
|
|
2461
|
+
},
|
|
2462
|
+
h('path', {
|
|
2463
|
+
d: 'M24 4C12.4 4 3 12.2 3 22.3c0 5.7 3 10.8 7.8 14.2v7.4c0 .9 1 1.4 1.7.9l8.1-5.3c1.1.2 2.3.3 3.4.3 11.6 0 21-8.2 21-18.3S35.6 4 24 4Z',
|
|
2464
|
+
fill: 'currentColor',
|
|
2465
|
+
fillOpacity: 0.16,
|
|
2466
|
+
stroke: 'currentColor',
|
|
2467
|
+
strokeWidth: 2.2,
|
|
2468
|
+
strokeLinejoin: 'round',
|
|
2469
|
+
}),
|
|
2470
|
+
h('circle', { cx: 31.5, cy: 15.5, r: 5, fill: 'currentColor' }),
|
|
2471
|
+
h('circle', { cx: 31.5, cy: 15.5, r: 1.6, fill: 'var(--dsw-alias-bg-base, #fff)' }),
|
|
2472
|
+
)
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
// ------------------------------------------------------------------ 侧边栏图标
|
|
2476
|
+
|
|
2477
|
+
function SidebarIcon(props) {
|
|
2478
|
+
const size = props && Number(props.size) > 0 ? Number(props.size) : 18
|
|
2479
|
+
return h(BrandIcon, { size })
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// ------------------------------------------------------------------ 注册
|
|
2483
|
+
|
|
2484
|
+
return {
|
|
2485
|
+
inject: ['slots', 'connection'],
|
|
2486
|
+
apply(ctx) {
|
|
2487
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
2488
|
+
ctx.slots.register(
|
|
2489
|
+
{ name: 'sidebar.panellist', id: PANEL_KEY, order: 46, label: '钉钉消息自动化' },
|
|
2490
|
+
SidebarIcon,
|
|
2491
|
+
),
|
|
2492
|
+
)
|
|
2493
|
+
|
|
2494
|
+
ctx.slots.inject('main', () =>
|
|
2495
|
+
ctx.slots.register({ name: 'main', key: PANEL_KEY }, InboxPanel),
|
|
2496
|
+
)
|
|
2497
|
+
|
|
2498
|
+
ctx.slots.inject('shell.overlay', () =>
|
|
2499
|
+
ctx.slots.register(
|
|
2500
|
+
{ name: 'shell.overlay', id: 'dingtalk-attention', order: 80, label: '钉钉待确认回复' },
|
|
2501
|
+
GlobalOverlay,
|
|
2502
|
+
),
|
|
2503
|
+
)
|
|
2504
|
+
|
|
2505
|
+
ctx.slots.inject('settings.section', () =>
|
|
2506
|
+
ctx.slots.register(
|
|
2507
|
+
{ name: 'settings.section', id: 'dingtalk-bridge-settings', order: 42, label: '钉钉消息自动化' },
|
|
2508
|
+
SettingsSection,
|
|
2509
|
+
),
|
|
2510
|
+
)
|
|
2511
|
+
|
|
2512
|
+
ctx.slots.inject('plugins.bundle.config', () =>
|
|
2513
|
+
ctx.slots.register({ name: 'plugins.bundle.config', key: PACKAGE_NAME }, PluginConfigCard),
|
|
2514
|
+
)
|
|
2515
|
+
},
|
|
2516
|
+
}
|
|
2517
|
+
},
|
|
2518
|
+
})
|
|
2519
|
+
|