@xmanrui/dsh-im 0.7.0 → 0.7.2
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/lib/index.js +119 -121
- package/package.json +1 -1
- package/src/channels/dingtalk/dingtalk-bridge.mjs +423 -8
- package/src/channels/dingtalk/harness-client.mjs +16 -366
- package/src/channels/discord/discord-api.mjs +1 -1
- package/src/channels/discord/discord-runtime.mjs +11 -1
- package/src/channels/discord/harness-client.mjs +10 -2
- package/src/channels/feishu/bridge.mjs +571 -50
- package/src/channels/feishu/feishu-runtime.mjs +41 -1
- package/src/channels/feishu/harness-client.mjs +16 -335
- package/src/channels/qq/harness-client.mjs +10 -2
- package/src/channels/qq/qq-bridge.mjs +428 -28
- package/src/channels/qq/qq-runtime.mjs +14 -3
- package/src/channels/shared/harness-approval.mjs +472 -0
- package/src/channels/shared/harness-client.mjs +858 -0
- package/src/channels/shared/harness-question.mjs +85 -0
- package/src/channels/shared/text-harness-bridge.mjs +486 -24
- package/src/channels/slack/harness-client.mjs +10 -2
- package/src/channels/slack/slack-runtime.mjs +11 -1
- package/src/channels/telegram/harness-client.mjs +10 -2
- package/src/channels/telegram/telegram-runtime.mjs +15 -4
- package/src/channels/wecom/harness-client.mjs +10 -2
- package/src/channels/wecom/wecom-bridge.mjs +434 -14
- package/src/channels/wecom/wecom-runtime.mjs +6 -0
- package/src/channels/weixin/harness-client.mjs +16 -326
- package/src/channels/weixin/weixin-api.mjs +1 -1
- package/src/channels/weixin/weixin-bridge.mjs +451 -22
- package/src/channels/weixin/weixin-runtime.mjs +56 -7
- package/src/channels/whatsapp/harness-client.mjs +10 -2
- package/src/channels/whatsapp/whatsapp-runtime.mjs +1 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function nonEmptyString(value) {
|
|
2
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function validHarnessQuestion(question) {
|
|
6
|
+
return question && typeof question.id === 'string' && typeof question.question === 'string'
|
|
7
|
+
&& (question.header === undefined || typeof question.header === 'string')
|
|
8
|
+
&& (question.detail === undefined || typeof question.detail === 'string')
|
|
9
|
+
&& (question.multiSelect === undefined || typeof question.multiSelect === 'boolean')
|
|
10
|
+
&& (question.options === undefined || (Array.isArray(question.options)
|
|
11
|
+
&& question.options.every((option) => (
|
|
12
|
+
option && typeof option.label === 'string'
|
|
13
|
+
&& (option.description === undefined || typeof option.description === 'string')
|
|
14
|
+
))));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function harnessQuestionText(question, index, total, { requiresMention = false } = {}) {
|
|
18
|
+
const lines = [];
|
|
19
|
+
const progress = total > 1 ? `(${index + 1}/${total})` : '';
|
|
20
|
+
lines.push(`DeepSeek Harness 需要你补充信息${progress}:`);
|
|
21
|
+
if (nonEmptyString(question.header)) lines.push('', question.header.trim());
|
|
22
|
+
lines.push('', nonEmptyString(question.question) ?? '请输入你的回答。');
|
|
23
|
+
if (nonEmptyString(question.detail)) lines.push('', question.detail.trim());
|
|
24
|
+
|
|
25
|
+
const options = Array.isArray(question.options) ? question.options : [];
|
|
26
|
+
if (options.length > 0) {
|
|
27
|
+
lines.push('');
|
|
28
|
+
options.forEach((option, optionIndex) => {
|
|
29
|
+
const label = typeof option?.label === 'string' ? option.label : '';
|
|
30
|
+
const description = nonEmptyString(option?.description);
|
|
31
|
+
lines.push(`${optionIndex + 1}. ${label}${description ? ` — ${description}` : ''}`);
|
|
32
|
+
});
|
|
33
|
+
lines.push('', question.multiSelect === true
|
|
34
|
+
? '请回复选项序号或文字;多选用逗号分隔,也可补充其他内容。'
|
|
35
|
+
: '请回复一个选项序号或文字,也可直接输入其他答案。');
|
|
36
|
+
} else {
|
|
37
|
+
lines.push('', '请直接回复你的答案。');
|
|
38
|
+
}
|
|
39
|
+
if (requiresMention) lines.push('', '群聊中请 @机器人 后发送答案。');
|
|
40
|
+
return lines.join('\n');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function optionLabel(token, options) {
|
|
44
|
+
const normalized = token.trim();
|
|
45
|
+
if (!normalized) return null;
|
|
46
|
+
if (/^\d+$/.test(normalized)) {
|
|
47
|
+
const option = options[Number(normalized) - 1];
|
|
48
|
+
return typeof option?.label === 'string' ? option.label : null;
|
|
49
|
+
}
|
|
50
|
+
const exact = options.find((option) => option?.label === normalized);
|
|
51
|
+
return typeof exact?.label === 'string' ? exact.label : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function harnessAnswerForQuestion(question, text) {
|
|
55
|
+
const options = Array.isArray(question.options) ? question.options : [];
|
|
56
|
+
if (options.length === 0) {
|
|
57
|
+
return { id: question.id, selected: [], custom: text };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const wholeLabel = optionLabel(text, options);
|
|
61
|
+
if (question.multiSelect !== true) {
|
|
62
|
+
return wholeLabel
|
|
63
|
+
? { id: question.id, selected: [wholeLabel] }
|
|
64
|
+
: { id: question.id, selected: [], custom: text };
|
|
65
|
+
}
|
|
66
|
+
if (wholeLabel) return { id: question.id, selected: [wholeLabel] };
|
|
67
|
+
|
|
68
|
+
const selected = [];
|
|
69
|
+
const custom = [];
|
|
70
|
+
for (const token of text.split(/[,,、;;\n]+/)) {
|
|
71
|
+
const value = token.trim();
|
|
72
|
+
if (!value) continue;
|
|
73
|
+
const label = optionLabel(value, options);
|
|
74
|
+
if (label) {
|
|
75
|
+
if (!selected.includes(label)) selected.push(label);
|
|
76
|
+
} else {
|
|
77
|
+
custom.push(value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
id: question.id,
|
|
82
|
+
selected,
|
|
83
|
+
...(custom.length > 0 ? { custom: custom.join('、') } : {}),
|
|
84
|
+
};
|
|
85
|
+
}
|