dsh-plugin-dingtalk-bridge 0.4.2 → 0.4.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/README.md +2 -1
- package/client.js +17 -3
- package/docs//344/275/277/347/224/250/350/257/264/346/230/216.md +26 -0
- package/package.json +1 -1
- package/src/host/service.js +48 -6
- package/src/host/suggest.js +13 -0
package/README.md
CHANGED
|
@@ -207,12 +207,13 @@ npm i -g dsh-plugin-dingtalk-bridge@0.4.0 # 或装到 profile 的 dependencies
|
|
|
207
207
|
| 来源(群 / 发送人)太多,胶囊被截断吗 | 不会。来源条只占一行:前 5 个 + 「还有 N 个 ▾」,点开是完整面板(可搜索、内滚、清除筛选),选中的来源置顶。 |
|
|
208
208
|
| AI 回复好像只看一条消息,太片面 | 每个来源有独立滑动窗口(默认最近 5 条,`windowMessages` 可调),含对方连续发言与我发过的回复;没攒满时用钉钉最新 10 条补齐。刚换新联系人时上下文少是正常的。 |
|
|
209
209
|
| 接口返回 401 / 403 | 401:钉钉登录态过期,点 **钉钉授权** 重新登录。403:被 DSH 的 Host/Origin 护栏拒绝(跨站或会话失效),刷新页面重开面板,不要绕过前端直接调接口。 |
|
|
210
|
+
| 发送报「请求参数不能为空」/ 输入框里是一大段 JSON | 0.4.3 已修:模型返回 `reply: ""`(常见于看不见图片)时不再把整段 JSON 当草稿;卡片改为「需人工确认」并提示原因,输入框等你手写,宿主也会在发送前拦下「像 JSON 的正文」。 |
|
|
210
211
|
|
|
211
212
|
## 开发与自测
|
|
212
213
|
|
|
213
214
|
```bash
|
|
214
215
|
npm run check # node --check 全部源码
|
|
215
|
-
npm test # 单元测试:
|
|
216
|
+
npm test # 单元测试:94 个用例,使用临时 DSH_HOME,不写真实状态
|
|
216
217
|
npm run smoke:index # 校验 index.js 契约:Config 校验、prefix 路由注册、effect 数量、清理
|
|
217
218
|
npm run smoke # 真机监听冒烟:dws 版本、profile、listener 状态、GET /state
|
|
218
219
|
npm run smoke:login # 两种授权模式:loopback(链接含 127.0.0.1、无授权码)→ device(授权码 + PNG 二维码)
|
package/client.js
CHANGED
|
@@ -24,7 +24,7 @@ window.__ModuleLoader__.load({
|
|
|
24
24
|
const POLL_MS = 5000
|
|
25
25
|
const SOFT_POLL_MS = 30000
|
|
26
26
|
// 与 package.json 的 version 保持一致:宿主上报的 build 前缀对不上,说明 DSH 还在跑旧宿主代码。
|
|
27
|
-
const CLIENT_BUILD = '0.4.
|
|
27
|
+
const CLIENT_BUILD = '0.4.3'
|
|
28
28
|
// 源码仓库(GitHub):Star 与 Issue 入口都指向这里
|
|
29
29
|
const REPO_URL = 'https://github.com/gcggcg/dsh-plugin-dingtalk-bridge'
|
|
30
30
|
const ISSUES_URL = `${REPO_URL}/issues`
|
|
@@ -954,6 +954,14 @@ window.__ModuleLoader__.load({
|
|
|
954
954
|
)
|
|
955
955
|
: null,
|
|
956
956
|
|
|
957
|
+
showComposer && !suggesting && suggestion === '' && message.suggestion && message.suggestion.ok === false
|
|
958
|
+
? h(
|
|
959
|
+
'div',
|
|
960
|
+
{ className: 'dsh-dt-hint', 'data-no-suggestion': '1', style: { marginTop: 8, color: C.warn } },
|
|
961
|
+
`模型没给出可发送的建议:${message.suggestion.reason || '需要你手动回复'}`,
|
|
962
|
+
)
|
|
963
|
+
: null,
|
|
964
|
+
|
|
957
965
|
showComposer && !suggesting
|
|
958
966
|
? h(
|
|
959
967
|
'div',
|
|
@@ -965,7 +973,13 @@ window.__ModuleLoader__.load({
|
|
|
965
973
|
value,
|
|
966
974
|
suggestion,
|
|
967
975
|
disabled: busy,
|
|
968
|
-
placeholder: replied
|
|
976
|
+
placeholder: replied
|
|
977
|
+
? '已回复,可继续补充…'
|
|
978
|
+
: suggestion !== ''
|
|
979
|
+
? message.kind === 'group' && groupReplyAt !== false
|
|
980
|
+
? `回复 @${message.sender},Tab 补全建议…`
|
|
981
|
+
: '输入回复,Tab 补全建议…'
|
|
982
|
+
: '模型没给出建议,请手动输入回复…',
|
|
969
983
|
onChange: setValue,
|
|
970
984
|
onSubmit: submit,
|
|
971
985
|
ariaLabel: `回复 ${message.sender}`,
|
|
@@ -2193,7 +2207,7 @@ window.__ModuleLoader__.load({
|
|
|
2193
2207
|
value,
|
|
2194
2208
|
suggestion,
|
|
2195
2209
|
disabled: busy,
|
|
2196
|
-
placeholder: '输入回复,Tab 补全建议…',
|
|
2210
|
+
placeholder: suggestion !== '' ? '输入回复,Tab 补全建议…' : '模型没给出建议,请手动输入回复…',
|
|
2197
2211
|
onChange: setValue,
|
|
2198
2212
|
onSubmit: send,
|
|
2199
2213
|
ariaLabel: '确认回复内容',
|
|
@@ -1762,6 +1762,32 @@ node scripts/duplicate-smoke.mjs <你的 openDingTalkId>
|
|
|
1762
1762
|
|
|
1763
1763
|
> 拆分的判断权在模型:内容确实只有一句话时它会保持单条,这是刻意设计,避免把一句话拆成多条骚扰对方。
|
|
1764
1764
|
|
|
1765
|
+
### 10.22 发送时报「请求参数不能为空」/ 输入框里出现一大段 JSON
|
|
1766
|
+
|
|
1767
|
+
0.4.3 起已修复,遇到时先确认版本(设置页「宿主版本」≥ `0.4.3`)。
|
|
1768
|
+
|
|
1769
|
+
**现象**:消息卡片显示「发送失败:请求参数不能为空」,或者输入框里的灰色建议是一整段
|
|
1770
|
+
`{"reply":"","confidence":0.0,"needsHuman":true,…}`。
|
|
1771
|
+
|
|
1772
|
+
**原因**:模型按约定返回了 JSON,但 `reply` 是空串(最常见于「对方只发了图片,而当前模型不支持看图」)。
|
|
1773
|
+
旧版本会把这段 JSON 当成草稿塞进输入框;而 dws 发消息时会把正文包进 `{"content": …}` 的结构化消息体,
|
|
1774
|
+
正文本身就是 JSON 时服务端解析出空内容,于是报「请求参数不能为空」。
|
|
1775
|
+
|
|
1776
|
+
**现在的行为**:
|
|
1777
|
+
|
|
1778
|
+
| 环节 | 0.4.3 的处理 |
|
|
1779
|
+
| --- | --- |
|
|
1780
|
+
| 解析模型输出 | `reply` 为空时不再退化成「原文草稿」,而是标记 `format: 'json-empty'`、`needsHuman: true`,保留模型的 `reason` |
|
|
1781
|
+
| 消息卡片 | 状态显示 **需人工确认**(不是刺眼的「处理失败」),并提示「模型没给出可发送的建议:<原因>」 |
|
|
1782
|
+
| 输入框 | 灰字建议为空,placeholder 变为「模型没给出建议,请手动输入回复…」,「发送」按钮在你输入内容前保持禁用 |
|
|
1783
|
+
| 发送前兜底 | 如果正文仍像模型原始 JSON,宿主会直接拦下并提示「回复内容看起来是模型的原始 JSON,不是能直接发送的文本」,不会再打到钉钉 |
|
|
1784
|
+
|
|
1785
|
+
**你可以怎么做**:
|
|
1786
|
+
|
|
1787
|
+
1. 直接手写一句回复(图片内容需要你自己看一眼);
|
|
1788
|
+
2. 想让它自己看图,就换一个支持图片输入的模型(设置页「图片识别」一行会显示当前模型是否支持);
|
|
1789
|
+
3. 点「换一条建议」重试,有时模型第二次会给出文字版回复。
|
|
1790
|
+
|
|
1765
1791
|
## 11. 隐私与安全说明
|
|
1766
1792
|
|
|
1767
1793
|
### 11.1 数据落在哪里
|
package/package.json
CHANGED
package/src/host/service.js
CHANGED
|
@@ -21,7 +21,7 @@ import { buildSuggestPrompt, generateSuggestion, formatClock } from './suggest.j
|
|
|
21
21
|
|
|
22
22
|
export const ROUTE_PREFIX = '/api/dingtalk-bridge'
|
|
23
23
|
/** 每次改动宿主行为就换个标记:界面与 http-debug.log 都会带上,用来确认「跑的是新代码」。 */
|
|
24
|
-
export const HOST_BUILD = '0.4.
|
|
24
|
+
export const HOST_BUILD = '0.4.3-20261118T1410'
|
|
25
25
|
|
|
26
26
|
/** 私信(单聊)全部消息。 */
|
|
27
27
|
const O2O_KEY = 'user_im_message_receive_o2o_all'
|
|
@@ -56,6 +56,27 @@ export function looksLikeMissingCommand(text) {
|
|
|
56
56
|
)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* 判断一段回复正文是不是「模型返回的原始 JSON」。
|
|
61
|
+
*
|
|
62
|
+
* 为什么需要:dws 发消息时会把 `--text` 的值包进 `{"content": …}` 的结构化消息体,
|
|
63
|
+
* 如果正文本身就是一段 JSON(且没有 content 字段),服务端解析后内容为空,
|
|
64
|
+
* 就会报「请求参数不能为空」——用户完全看不懂这个错。
|
|
65
|
+
*/
|
|
66
|
+
export function looksLikeJsonEnvelope(text) {
|
|
67
|
+
const raw = String(text ?? '').trim()
|
|
68
|
+
if (!raw.startsWith('{') || !raw.endsWith('}')) return false
|
|
69
|
+
try {
|
|
70
|
+
const payload = JSON.parse(raw)
|
|
71
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return false
|
|
72
|
+
return ['reply', 'replies', 'needsHuman', 'needs_human', 'confidence', 'reason'].some(
|
|
73
|
+
(key) => key in payload,
|
|
74
|
+
)
|
|
75
|
+
} catch {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
59
80
|
function asBool(value, fallback) {
|
|
60
81
|
return typeof value === 'boolean' ? value : fallback
|
|
61
82
|
}
|
|
@@ -2202,10 +2223,12 @@ export class DingTalkBridgeService {
|
|
|
2202
2223
|
|
|
2203
2224
|
// 手动触发的「换一条建议 / 生成建议」只更新建议本身,绝不代替用户发送。
|
|
2204
2225
|
if (manual) {
|
|
2205
|
-
|
|
2206
|
-
|
|
2226
|
+
// 「模型按格式回了、但 reply 是空串」(例如它看不见图片)不是错误,
|
|
2227
|
+
// 只是需要人来写,所以标成 needs-human,而不是刺眼的「处理失败」。
|
|
2228
|
+
current.status = result.ok ? 'suggested' : result.format === 'json-empty' ? 'needs-human' : 'failed'
|
|
2229
|
+
current.needsHuman = result.ok ? false : result.format === 'json-empty' && this.config.notifyModal
|
|
2207
2230
|
current.dismissed = false
|
|
2208
|
-
current.error = result.ok ? '' : result.reason
|
|
2231
|
+
current.error = result.ok ? '' : result.format === 'json-empty' ? '' : result.reason
|
|
2209
2232
|
this.broadcast()
|
|
2210
2233
|
this.saveState().catch(() => {})
|
|
2211
2234
|
return current
|
|
@@ -2225,9 +2248,10 @@ export class DingTalkBridgeService {
|
|
|
2225
2248
|
})
|
|
2226
2249
|
}
|
|
2227
2250
|
} else {
|
|
2228
|
-
|
|
2251
|
+
// 自动回复没开:有建议就等人确认(suggested),模型明确说「给不出」就标 needs-human。
|
|
2252
|
+
current.status = result.ok ? 'suggested' : result.format === 'json-empty' ? 'needs-human' : 'failed'
|
|
2229
2253
|
current.needsHuman = false
|
|
2230
|
-
current.error = result.ok ? '' : result.reason
|
|
2254
|
+
current.error = result.ok ? '' : result.format === 'json-empty' ? '' : result.reason
|
|
2231
2255
|
// 自动回复在生成过程中被关闭、或这条消息早于本次开启时间:只留建议,不自动发送。
|
|
2232
2256
|
if (this.state.autoReplyTouched && result.ok && !current.autoCancelled) {
|
|
2233
2257
|
current.autoCancelled = !this.state.autoReply || !this.canAutoReply(current)
|
|
@@ -2245,6 +2269,24 @@ export class DingTalkBridgeService {
|
|
|
2245
2269
|
const body = composeReplyBody({ record, text, replyPrefix: this.config.replyPrefix, atSender })
|
|
2246
2270
|
if (body === '') return false
|
|
2247
2271
|
|
|
2272
|
+
// 防呆:模型偶尔会把整段 JSON 当正文返回(例如 reply 为空、只有 reason 的情况)。
|
|
2273
|
+
// 那串东西发到钉钉会被当成结构化消息体,服务端直接报「请求参数不能为空」,
|
|
2274
|
+
// 所以在这里拦下,换成一句人能看懂的错误。
|
|
2275
|
+
if (looksLikeJsonEnvelope(body)) {
|
|
2276
|
+
record.reply = {
|
|
2277
|
+
text: body.slice(0, 400),
|
|
2278
|
+
at: Date.now(),
|
|
2279
|
+
atSender,
|
|
2280
|
+
ok: false,
|
|
2281
|
+
error: '回复内容看起来是模型的原始 JSON,不是能直接发送的文本。请点「换一条建议」,或手动输入回复后再发送。',
|
|
2282
|
+
auto,
|
|
2283
|
+
}
|
|
2284
|
+
record.status = 'failed'
|
|
2285
|
+
this.broadcast()
|
|
2286
|
+
await this.saveState().catch(() => {})
|
|
2287
|
+
return false
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2248
2290
|
// 自动回复在「模型思考的这几秒」里可能已被用户关掉,或这条消息早于本次开启时间:
|
|
2249
2291
|
// 发之前再判一次状态,避免关掉开关后仍然把回复发出去。
|
|
2250
2292
|
if (auto && !this.canAutoReply(record)) {
|
package/src/host/suggest.js
CHANGED
|
@@ -105,6 +105,19 @@ export function parseSuggestion(text) {
|
|
|
105
105
|
format: 'json',
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
// 模型按约定返回了 JSON,但 reply 是空串(典型:只有图片、它看不见图)。
|
|
110
|
+
// 这时绝不能把整段 JSON 当成草稿塞进输入框——那串东西既不是人话,
|
|
111
|
+
// 发到钉钉还会被当成结构化消息体,报「请求参数不能为空」。
|
|
112
|
+
return {
|
|
113
|
+
ok: false,
|
|
114
|
+
reply: '',
|
|
115
|
+
replies: [],
|
|
116
|
+
confidence: clampConfidence(payload.confidence ?? payload.score),
|
|
117
|
+
needsHuman: true,
|
|
118
|
+
reason: String(payload.reason ?? payload.note ?? '模型没有给出可发送的回复内容,需要你手动回复').slice(0, 240),
|
|
119
|
+
format: 'json-empty',
|
|
120
|
+
}
|
|
108
121
|
}
|
|
109
122
|
|
|
110
123
|
const fallback = cleanReply(raw)
|