@michengai/dsh-im-connect 1.0.45 → 1.0.47
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/CHANGELOG.md +16 -0
- package/CHANGELOG.zh-CN.md +16 -0
- package/README.en.md +4 -4
- package/README.ja.md +1 -1
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/client.js +1 -31
- package/lib/channels/feishu.d.ts +20 -1
- package/lib/channels/feishu.d.ts.map +1 -1
- package/lib/channels/feishu.js +90 -32
- package/lib/channels/feishu.js.map +1 -1
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +1 -0
- package/lib/channels/telegram.js.map +1 -1
- package/lib/channels/thinking-block.d.ts +2 -1
- package/lib/channels/thinking-block.d.ts.map +1 -1
- package/lib/channels/thinking-block.js +3 -2
- package/lib/channels/thinking-block.js.map +1 -1
- package/lib/client.js +1 -31
- package/lib/engine/command-messages.d.ts +1 -1
- package/lib/engine/command-messages.js +1 -1
- package/lib/engine/command-permissions.d.ts +1 -1
- package/lib/engine/command-permissions.d.ts.map +1 -1
- package/lib/engine/command-permissions.js +1 -1
- package/lib/engine/command-permissions.js.map +1 -1
- package/lib/engine/file-input.js +1 -1
- package/lib/engine/message-progress.d.ts.map +1 -1
- package/lib/engine/message-progress.js +0 -2
- package/lib/engine/message-progress.js.map +1 -1
- package/lib/engine/router.d.ts +0 -1
- package/lib/engine/router.d.ts.map +1 -1
- package/lib/engine/router.js +0 -2
- package/lib/engine/router.js.map +1 -1
- package/lib/engine/thinking-display.d.ts +1 -1
- package/lib/engine/thinking-display.d.ts.map +1 -1
- package/lib/engine/thinking-display.js +18 -5
- package/lib/engine/thinking-display.js.map +1 -1
- package/lib/engine/types.d.ts +6 -0
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/engine/types.js +4 -1
- package/lib/engine/types.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/package.json +16 -16
- package/src/channels/feishu.ts +109 -32
- package/src/channels/telegram.ts +1 -0
- package/src/channels/thinking-block.ts +4 -2
- package/src/engine/command-messages.ts +1 -1
- package/src/engine/command-permissions.ts +1 -1
- package/src/engine/file-input.ts +1 -1
- package/src/engine/message-progress.ts +0 -2
- package/src/engine/router.ts +1 -1
- package/src/engine/thinking-display.ts +19 -6
- package/src/engine/types.ts +8 -0
- package/src/index.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-im-connect",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"description": "DSH IM Connect — 将主流即时通讯平台接入本机 DeepSeek Harness · Connect major messaging platforms to local DeepSeek Harness agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.22.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"license": "Apache-2.0",
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": "^22.19.0 || >=24.0.0",
|
|
74
|
-
"dsh": ">=0.2.
|
|
74
|
+
"dsh": ">=0.2.2-rc.1 <0.3.0-0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@larksuiteoapi/node-sdk": "^1.36.0",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
86
|
-
"@deepseek-ai/dsh-agent": ">=0.2.
|
|
87
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.
|
|
88
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.
|
|
89
|
-
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.
|
|
90
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.
|
|
91
|
-
"@deepseek-ai/dsh-host-webserver": ">=0.2.
|
|
86
|
+
"@deepseek-ai/dsh-agent": ">=0.2.2-rc.1 <0.3.0-0",
|
|
87
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.1 <0.3.0-0",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.1 <0.3.0-0",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-rc.1 <0.3.0-0",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.1 <0.3.0-0",
|
|
91
|
+
"@deepseek-ai/dsh-host-webserver": ">=0.2.2-rc.1 <0.3.0-0",
|
|
92
92
|
"@deepseek-ai/schemastery": "^3.18.2",
|
|
93
93
|
"react": "^18.2.0"
|
|
94
94
|
},
|
|
@@ -99,13 +99,13 @@
|
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@deepseek-ai/cordis": "4.1.0",
|
|
102
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
103
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.
|
|
104
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.
|
|
105
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.
|
|
106
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.
|
|
107
|
-
"@deepseek-ai/dsh-error": "0.2.2-rc.
|
|
108
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.
|
|
102
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.5",
|
|
103
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.5",
|
|
104
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
|
|
105
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.5",
|
|
106
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.5",
|
|
107
|
+
"@deepseek-ai/dsh-error": "0.2.2-rc.5",
|
|
108
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.5",
|
|
109
109
|
"@deepseek-ai/schemastery": "3.19.0",
|
|
110
110
|
"@types/node": "^22.10.0",
|
|
111
111
|
"@types/qrcode": "^1.5.6",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"react": "^18.3.1",
|
|
114
114
|
"react-dom": "^18.3.1",
|
|
115
115
|
"typescript": "5.9.3",
|
|
116
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
116
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.5"
|
|
117
117
|
},
|
|
118
118
|
"dsh": {
|
|
119
119
|
"manifestVersion": 1,
|
package/src/channels/feishu.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { choiceSendError, ChoiceSendError } from '../engine/choice-delivery.js'
|
|
|
3
3
|
import { afterPartialDelivery, DeliveryRejected } from '../engine/deferred-delivery.js'
|
|
4
4
|
import { diagnosticJson, platformResult, probe, requireDiagnostic } from './diagnostics.js'
|
|
5
5
|
import { fileOperation } from './file-send.js'
|
|
6
|
-
import type
|
|
6
|
+
import { DEFAULT_TRUNCATED_NOTE, DEFAULT_THINKING_MAX_CHARS, type ChannelAdapter, type ImMedia, type ImMessage, type ThinkingOptions } from '../engine/types.js'
|
|
7
7
|
import { quietSdkLogger } from '../engine/quiet-logger.js'
|
|
8
8
|
import { KeyedSerialQueue } from '../engine/keyed-queue.js'
|
|
9
9
|
import { timeoutSignal } from '../engine/abort.js'
|
|
@@ -17,28 +17,37 @@ export const FEISHU_COT_API = '/open-apis/im/v1/message_cot'
|
|
|
17
17
|
export const FEISHU_COT_COMPLETE_API = '/open-apis/im/v1/message_cot/complete'
|
|
18
18
|
/** 飞书 message_cot 单个事件内容字符上限保护,避免 10001 AppendCOTEvents: event[0] content too long */
|
|
19
19
|
export const FEISHU_COT_CHUNK_SIZE = 800
|
|
20
|
+
/** 飞书原生 message_cot 流式推理长思维链最大安全预算(64K 字符),防止极端异常溢出 */
|
|
21
|
+
export const FEISHU_COT_MAX_CHARS = 65_536
|
|
22
|
+
/** 飞书卡片折叠面板(话题回复串内或降级兜底)安全字符预算,避免 30KB JSON 物理超限(8000 中文字约为 24KB UTF-8) */
|
|
23
|
+
export const FEISHU_CARD_THINKING_MAX_CHARS = 8_000
|
|
24
|
+
/** 飞书卡片折叠面板内容最大安全 UTF-8 字节上限(30KB = 30720 字节,预留约 4.7KB 给卡片外壳 JSON) */
|
|
25
|
+
export const FEISHU_CARD_THINKING_MAX_BYTES = 26_000
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
export function chunkByGraphemes(text: string, maxChunkLength: number): string[] {
|
|
23
|
-
if (text.length <= maxChunkLength) return [text]
|
|
24
|
-
const chunks: string[] = []
|
|
25
|
-
let currentChunk = ''
|
|
27
|
+
export const TRUNCATED_NOTE = '\n\n' + DEFAULT_TRUNCATED_NOTE
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
/** 安全获取 Unicode 字形簇(Grapheme Cluster)可迭代对象,在不支持 Intl.Segmenter 时安全退化为码点遍历 */
|
|
30
|
+
export function getGraphemeUnits(text: string): Iterable<string> {
|
|
28
31
|
if (typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function') {
|
|
29
32
|
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
|
|
30
|
-
|
|
33
|
+
return {
|
|
31
34
|
*[Symbol.iterator]() {
|
|
32
35
|
for (const { segment } of segmenter.segment(text)) {
|
|
33
36
|
yield segment
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
39
|
}
|
|
37
|
-
} else {
|
|
38
|
-
units = text
|
|
39
40
|
}
|
|
41
|
+
return text
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 按 Unicode 字形簇(Grapheme Cluster)安全切分文本,严禁切开 Emoji 代理对或 ZWJ 复合表情 */
|
|
45
|
+
export function chunkByGraphemes(text: string, maxChunkLength: number): string[] {
|
|
46
|
+
if (text.length <= maxChunkLength) return [text]
|
|
47
|
+
const chunks: string[] = []
|
|
48
|
+
let currentChunk = ''
|
|
40
49
|
|
|
41
|
-
for (const unit of
|
|
50
|
+
for (const unit of getGraphemeUnits(text)) {
|
|
42
51
|
if (currentChunk.length + unit.length > maxChunkLength && currentChunk.length > 0) {
|
|
43
52
|
chunks.push(currentChunk)
|
|
44
53
|
currentChunk = ''
|
|
@@ -54,6 +63,53 @@ export function chunkByGraphemes(text: string, maxChunkLength: number): string[]
|
|
|
54
63
|
/** 保持历史兼容别名 */
|
|
55
64
|
export const chunkByCodePoints = chunkByGraphemes
|
|
56
65
|
|
|
66
|
+
/**
|
|
67
|
+
* 针对思考内容按字符预算与可选字节预算进行字形簇安全截断,并在截断时追加提示后缀。
|
|
68
|
+
*
|
|
69
|
+
* 注:maxBytes 预算按原始 UTF-8 文本字节估算(不含 JSON 转义增量);
|
|
70
|
+
* 卡片折叠面板预留了约 4.7KB 裕量应对卡片外壳与潜在字符转义。
|
|
71
|
+
*/
|
|
72
|
+
export function clipThinkingText(
|
|
73
|
+
text: string,
|
|
74
|
+
maxChars: number,
|
|
75
|
+
maxBytes?: number,
|
|
76
|
+
note = TRUNCATED_NOTE,
|
|
77
|
+
forceTruncate = false,
|
|
78
|
+
): { text: string; truncated: boolean } {
|
|
79
|
+
if (!text) return { text: '', truncated: false }
|
|
80
|
+
let targetChars = maxChars
|
|
81
|
+
if (typeof maxBytes === 'number' && maxBytes > 0 && Buffer.byteLength(text, 'utf8') > maxBytes) {
|
|
82
|
+
targetChars = Math.min(targetChars, Math.floor(maxBytes / 3))
|
|
83
|
+
}
|
|
84
|
+
const overLength = text.length > targetChars
|
|
85
|
+
const overBytes = typeof maxBytes === 'number' && maxBytes > 0 && Buffer.byteLength(text, 'utf8') > maxBytes
|
|
86
|
+
if (!overLength && !overBytes && !forceTruncate) {
|
|
87
|
+
return { text, truncated: false }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const budget = Math.max(0, targetChars - note.length)
|
|
91
|
+
let end = 0
|
|
92
|
+
for (const unit of getGraphemeUnits(text)) {
|
|
93
|
+
if (end + unit.length > budget) break
|
|
94
|
+
end += unit.length
|
|
95
|
+
}
|
|
96
|
+
let clipped = text.slice(0, end)
|
|
97
|
+
if (typeof maxBytes === 'number' && maxBytes > 0) {
|
|
98
|
+
const noteBytes = Buffer.byteLength(note, 'utf8')
|
|
99
|
+
const maxContentBytes = Math.max(0, maxBytes - noteBytes)
|
|
100
|
+
while (clipped.length > 0 && Buffer.byteLength(clipped, 'utf8') > maxContentBytes) {
|
|
101
|
+
const last = clipped.length - 1
|
|
102
|
+
const isLow = clipped.charCodeAt(last) >= 0xdc00 && clipped.charCodeAt(last) <= 0xdfff
|
|
103
|
+
const step = isLow && last > 0 && clipped.charCodeAt(last - 1) >= 0xd800 && clipped.charCodeAt(last - 1) <= 0xdbff ? 2 : 1
|
|
104
|
+
clipped = clipped.slice(0, -step)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
text: clipped.endsWith(note) ? clipped : clipped + note,
|
|
109
|
+
truncated: true,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
57
113
|
interface CotEvent {
|
|
58
114
|
event_type: string
|
|
59
115
|
content: string
|
|
@@ -518,27 +574,42 @@ export function createFeishuChannel(id: 'feishu' | 'lark', config: FeishuConfig,
|
|
|
518
574
|
const runId = next.options?.streamId ?? 'turn'
|
|
519
575
|
const label = next.options?.label ?? (next.options?.final ? '🧠 思考过程' : '🧠 思考中…')
|
|
520
576
|
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
const maxChars = Math.min(4096, Math.max(200, Math.floor(requestedMaxChars)))
|
|
526
|
-
const TRUNCATED_NOTE = '\n\n…(已截断,完整内容见网页会话)'
|
|
527
|
-
|
|
577
|
+
// 文本预算与截断策略:
|
|
578
|
+
// 1. 原生 message_cot 模式为流式事件流,专用于承载大模型长思维链,绝不在 3,500/4,096 字符人为腰斩截断;
|
|
579
|
+
// 默认支持 65,536 字符的长思维链安全预算,即使 options.truncated 为 true 也依然维持 65,536 预算。
|
|
580
|
+
// 2. 卡片折叠模式(话题回复串内或降级兜底)受单条卡片 JSON 30KB 物理上限约束,采用 8,000 字符与 26KB 字节双重安全预算。
|
|
528
581
|
let processedText = next.text
|
|
529
|
-
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
582
|
+
|
|
583
|
+
if (current.mode === 'cot') {
|
|
584
|
+
const explicitBudget = typeof next.options?.maxChars === 'number' && Number.isFinite(next.options.maxChars) && next.options.maxChars > 0
|
|
585
|
+
? Math.floor(next.options.maxChars)
|
|
586
|
+
: FEISHU_COT_MAX_CHARS
|
|
587
|
+
// 原生 message_cot 专用于承载大模型长思维链,默认享有 65,536 字符长预算;
|
|
588
|
+
// 只有当调用方显式指定了更小的严格预算(如测试用例或用户显式配置收紧)时才收紧,
|
|
589
|
+
// 默认单条消息预算(3500/DEFAULT_THINKING_MAX_CHARS)不应被人为腰斩截断。
|
|
590
|
+
const cotBudget = explicitBudget === DEFAULT_THINKING_MAX_CHARS
|
|
591
|
+
? FEISHU_COT_MAX_CHARS
|
|
592
|
+
: Math.min(FEISHU_COT_MAX_CHARS, Math.max(200, explicitBudget))
|
|
593
|
+
const res = clipThinkingText(
|
|
594
|
+
processedText,
|
|
595
|
+
cotBudget,
|
|
596
|
+
undefined,
|
|
597
|
+
TRUNCATED_NOTE,
|
|
598
|
+
Boolean(next.options?.truncated),
|
|
599
|
+
)
|
|
600
|
+
processedText = res.text
|
|
601
|
+
} else {
|
|
602
|
+
const cardBudget = typeof next.options?.maxChars === 'number' && Number.isFinite(next.options.maxChars) && next.options.maxChars > 0
|
|
603
|
+
? Math.min(FEISHU_CARD_THINKING_MAX_CHARS, Math.max(200, Math.floor(next.options.maxChars)))
|
|
604
|
+
: FEISHU_CARD_THINKING_MAX_CHARS
|
|
605
|
+
const res = clipThinkingText(
|
|
606
|
+
processedText,
|
|
607
|
+
cardBudget,
|
|
608
|
+
FEISHU_CARD_THINKING_MAX_BYTES,
|
|
609
|
+
TRUNCATED_NOTE,
|
|
610
|
+
Boolean(next.options?.truncated),
|
|
611
|
+
)
|
|
612
|
+
processedText = res.text
|
|
542
613
|
}
|
|
543
614
|
|
|
544
615
|
// 1. 尝试原生 CoT 模式
|
|
@@ -628,6 +699,11 @@ export function createFeishuChannel(id: 'feishu' | 'lark', config: FeishuConfig,
|
|
|
628
699
|
// 2. 卡片折叠模式(话题内、或原生 CoT 降级)
|
|
629
700
|
if (current.mode === 'card') {
|
|
630
701
|
try {
|
|
702
|
+
let cardMarkdown = processedText
|
|
703
|
+
if (cardMarkdown.length > FEISHU_CARD_THINKING_MAX_CHARS || Buffer.byteLength(cardMarkdown, 'utf8') > FEISHU_CARD_THINKING_MAX_BYTES) {
|
|
704
|
+
const res = clipThinkingText(cardMarkdown, FEISHU_CARD_THINKING_MAX_CHARS, FEISHU_CARD_THINKING_MAX_BYTES)
|
|
705
|
+
cardMarkdown = res.text
|
|
706
|
+
}
|
|
631
707
|
const cardContent = JSON.stringify({
|
|
632
708
|
schema: '2.0',
|
|
633
709
|
config: { wide_screen_mode: true },
|
|
@@ -641,7 +717,7 @@ export function createFeishuChannel(id: 'feishu' | 'lark', config: FeishuConfig,
|
|
|
641
717
|
border: { color: 'grey' },
|
|
642
718
|
expanded: false,
|
|
643
719
|
elements: [
|
|
644
|
-
{ tag: 'markdown', content:
|
|
720
|
+
{ tag: 'markdown', content: cardMarkdown },
|
|
645
721
|
],
|
|
646
722
|
},
|
|
647
723
|
],
|
|
@@ -935,6 +1011,7 @@ export function createFeishuChannel(id: 'feishu' | 'lark', config: FeishuConfig,
|
|
|
935
1011
|
requireDiagnostic(typeof bot?.open_id === 'string' && bot.open_id)
|
|
936
1012
|
})]
|
|
937
1013
|
},
|
|
1014
|
+
maxThinkingChars: FEISHU_COT_MAX_CHARS,
|
|
938
1015
|
sendThinking: publishThinking,
|
|
939
1016
|
status() { return statusText },
|
|
940
1017
|
}
|
package/src/channels/telegram.ts
CHANGED
|
@@ -1038,6 +1038,7 @@ export function createTelegramChannel(config: TelegramConfig, log: (line: string
|
|
|
1038
1038
|
}
|
|
1039
1039
|
},
|
|
1040
1040
|
sendThinking: publishThinking,
|
|
1041
|
+
maxThinkingChars: 4096,
|
|
1041
1042
|
setMessageHandler(h) { handler = h },
|
|
1042
1043
|
setTopicEditHandler(h) { onTopicEdited = h },
|
|
1043
1044
|
async diagnose(signal) {
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
* 渲染放在这里是为了可单测:转义、长度收敛、折叠标签都不依赖网络。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { DEFAULT_TRUNCATED_NOTE, DEFAULT_THINKING_MAX_CHARS } from '../engine/types.js'
|
|
10
|
+
|
|
9
11
|
/** 单条 Telegram 消息的字符上限;留出余量给标签与截断提示。 */
|
|
10
12
|
export const THINKING_BODY_LIMIT = 3_500
|
|
11
13
|
|
|
12
14
|
/** 渠道没给上限时使用的默认值。 */
|
|
13
|
-
export
|
|
15
|
+
export { DEFAULT_THINKING_MAX_CHARS }
|
|
14
16
|
|
|
15
|
-
const TRUNCATED_NOTE =
|
|
17
|
+
const TRUNCATED_NOTE = DEFAULT_TRUNCATED_NOTE
|
|
16
18
|
|
|
17
19
|
/** 转义 Telegram HTML 模式要求的字符。 */
|
|
18
20
|
export function escapeTelegramHtml(value: string): string {
|
|
@@ -82,7 +82,7 @@ export const commandEnglish = {
|
|
|
82
82
|
"接下来可以:": "Next steps:",
|
|
83
83
|
"暂无可选项,可返回菜单选择其他操作。": "No options are available. Return to the menu for other actions.",
|
|
84
84
|
"点击按钮或发送对应命令;按钮 15 分钟内有效,普通文字继续聊天。": "Click a button or send its command. Buttons are valid for 15 minutes; ordinary text continues the conversation.",
|
|
85
|
-
"当前 DSH 不支持 Chat 文件输入,请升级到 0.
|
|
85
|
+
"当前 DSH 不支持 Chat 文件输入,请升级到 0.2.2-rc.1 或更新的兼容版本后重新发送。": "This DSH version does not support Chat file input. Upgrade to 0.2.2-rc.1 or a newer supported version and resend.",
|
|
86
86
|
"一次最多发送 4 个文件,累计不超过 20 MiB。": "Send up to 4 files at a time, totaling no more than 20 MiB.",
|
|
87
87
|
"文件输入失败,整条消息未提交。请检查文件大小和格式后重新发送,或在网页 Chat 上传。": "File input failed; the message was not submitted. Check the size and format and resend, or upload in web Chat.",
|
|
88
88
|
|
|
@@ -29,7 +29,7 @@ export function normalizeCommandPermissions(input: unknown): CommandPermissions
|
|
|
29
29
|
return { dm: scope(source.dm), group: scope(source.group) }
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export function canExecuteCommand(policy: CommandPermissions, kind: 'dm' | 'group',
|
|
32
|
+
export function canExecuteCommand(policy: CommandPermissions, kind: 'dm' | 'group', _userId?: string): boolean {
|
|
33
33
|
// 旧测试包的用户例外仅保留格式兼容,执行权限统一由聊天类型开关决定。
|
|
34
34
|
return policy[kind].enabled
|
|
35
35
|
}
|
package/src/engine/file-input.ts
CHANGED
|
@@ -10,7 +10,7 @@ export async function filePromptParts(host: { get(name: string): unknown }, sess
|
|
|
10
10
|
const signal = timeoutSignal(120_000, parent)
|
|
11
11
|
signal.throwIfAborted()
|
|
12
12
|
const upload = host.get('fileUploads') as { uploadStream?: (request: { sessionId: string; data: AsyncIterable<Uint8Array>; name?: string; signal: AbortSignal }) => Promise<{ receiptId: string }> } | undefined
|
|
13
|
-
if (!upload?.uploadStream) throw new FileInputError(replyText('当前 DSH 不支持 Chat 文件输入,请升级到 0.
|
|
13
|
+
if (!upload?.uploadStream) throw new FileInputError(replyText('当前 DSH 不支持 Chat 文件输入,请升级到 0.2.2-rc.1 或更新的兼容版本后重新发送。'))
|
|
14
14
|
if (media.length > 4) throw new FileInputError(replyText('一次最多发送 4 个文件,累计不超过 20 MiB。'))
|
|
15
15
|
let total = 0
|
|
16
16
|
const parts: Array<{ type: 'file'; receiptId: string }> = []
|
|
@@ -4,8 +4,6 @@ import { fileOperation } from './abort.js'
|
|
|
4
4
|
|
|
5
5
|
/** 状态更新默认预算:只够一次请求,超时就放弃,正文不等它。 */
|
|
6
6
|
const DEFAULT_STATUS_TIMEOUT_MS = 2000
|
|
7
|
-
/** 终态(完成 / 失败 / 取消)的默认预算:缺省跟随状态预算,慢渠道可通过 finalStatusReactionTimeoutMs 覆盖放宽。 */
|
|
8
|
-
const DEFAULT_FINAL_TIMEOUT_MS = 2000
|
|
9
7
|
/**
|
|
10
8
|
* typing 心跳的默认预算。必须覆盖一次冷连接握手 + 平台往返(本机实测 2.2–2.4 秒);
|
|
11
9
|
* 2 秒的上限会在请求送达前就取消它,「正在输入」因此整段消失。渠道可用
|
package/src/engine/router.ts
CHANGED
|
@@ -68,7 +68,7 @@ export class SessionRouter {
|
|
|
68
68
|
constructor(
|
|
69
69
|
private readonly ctx: AgentHost,
|
|
70
70
|
private readonly store: SessionMapStore,
|
|
71
|
-
|
|
71
|
+
config: EngineConfig,
|
|
72
72
|
private readonly log: (line: string) => void,
|
|
73
73
|
private readonly resolveConfig: (channelId: string) => EngineConfig = () => config,
|
|
74
74
|
options: { disposeTimeoutMs?: number; onDeliveryStopped?: (binding: ChatBinding) => void } = {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { DEFAULT_THINKING_MAX_CHARS, type ChannelAdapter, type ThinkingOptions } from './types.js'
|
|
2
2
|
|
|
3
3
|
export interface ThinkingDisplayConfig {
|
|
4
4
|
mode: 'off' | 'collapsed'
|
|
@@ -19,7 +19,7 @@ export function normalizeThinkingDisplay(value: unknown): ThinkingDisplayConfig
|
|
|
19
19
|
mode: input.mode === 'collapsed' ? 'collapsed' : 'off',
|
|
20
20
|
minChars: number('minChars', 120, 0, 4096),
|
|
21
21
|
intervalMs: number('intervalMs', 2000, 1000, 60000),
|
|
22
|
-
maxChars: number('maxChars',
|
|
22
|
+
maxChars: number('maxChars', DEFAULT_THINKING_MAX_CHARS, 200, 4096),
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -41,6 +41,7 @@ interface Lifecycle {
|
|
|
41
41
|
streamId: string
|
|
42
42
|
prefix: string
|
|
43
43
|
total: number
|
|
44
|
+
bufferLimit: number
|
|
44
45
|
/** Numeric surrogate metadata, never an unbounded second reasoning buffer. */
|
|
45
46
|
high?: number
|
|
46
47
|
closed: boolean
|
|
@@ -67,9 +68,17 @@ export class ThinkingDisplayTracker {
|
|
|
67
68
|
this.identities.set(target.key, { sessionId: target.sessionId, turn: target.turn })
|
|
68
69
|
const config = normalizeThinkingDisplay(target.config)
|
|
69
70
|
if (config.mode !== 'collapsed' || !target.channel.sendThinking || !target.isCurrent()) return
|
|
71
|
+
const channelLimit = target.channel.maxThinkingChars
|
|
72
|
+
?? (target.channel.id === 'feishu' || target.channel.id === 'lark' ? 65536 : 4096)
|
|
73
|
+
const raw = target.config && typeof target.config === 'object' ? target.config as Record<string, unknown> : {}
|
|
74
|
+
// 原生长思维链渠道(如飞书/Lark)享有 64K 原生流式预算;
|
|
75
|
+
// 只有当用户显式配置收紧预算(< 3500)时,才收紧缓冲预算;
|
|
76
|
+
// 生产环境中默认或普通单条消息上限(3500/4096)不应截断原生长思维链。
|
|
77
|
+
const tight = typeof raw.maxChars === 'number' && Number.isFinite(raw.maxChars) && raw.maxChars < DEFAULT_THINKING_MAX_CHARS
|
|
78
|
+
const bufferLimit = tight ? Math.min(channelLimit, config.maxChars) : channelLimit
|
|
70
79
|
this.states.set(target.key, {
|
|
71
80
|
target, config, scope: new AbortController(), streamId: `${target.sessionId}:${this.identity}:${++this.generation}`,
|
|
72
|
-
prefix: '', total: 0, closed: false, final: false,
|
|
81
|
+
prefix: '', total: 0, bufferLimit, closed: false, final: false,
|
|
73
82
|
})
|
|
74
83
|
}
|
|
75
84
|
|
|
@@ -99,7 +108,7 @@ export class ThinkingDisplayTracker {
|
|
|
99
108
|
state.high = last
|
|
100
109
|
addition = addition.slice(0, -1)
|
|
101
110
|
}
|
|
102
|
-
const room =
|
|
111
|
+
const room = state.bufferLimit - state.prefix.length
|
|
103
112
|
let prefix = addition.slice(0, room)
|
|
104
113
|
const end = prefix.charCodeAt(prefix.length - 1)
|
|
105
114
|
if (end >= 0xd800 && end <= 0xdbff) prefix = prefix.slice(0, -1)
|
|
@@ -174,10 +183,14 @@ export class ThinkingDisplayTracker {
|
|
|
174
183
|
|
|
175
184
|
private send(state: Lifecycle, final: boolean): Promise<void> {
|
|
176
185
|
if (!this.valid(state)) return Promise.resolve()
|
|
186
|
+
// 渠道能力高于普通单条上限时(如飞书 64K 原生流式通道),按 bufferLimit 下发;普通单条渠道(<= 4096)在 bufferLimit 与 config.maxChars 之间取较小值
|
|
187
|
+
const maxChars = state.bufferLimit > 4096
|
|
188
|
+
? state.bufferLimit
|
|
189
|
+
: Math.min(state.bufferLimit, state.config.maxChars)
|
|
177
190
|
const options: ThinkingOptions = {
|
|
178
|
-
final, label: state.target.label(final, state.total), maxChars
|
|
191
|
+
final, label: state.target.label(final, state.total), maxChars,
|
|
179
192
|
streamId: state.streamId, signal: state.scope.signal, isCurrent: () => this.valid(state),
|
|
180
|
-
truncated: state.closed
|
|
193
|
+
truncated: Boolean(state.closed),
|
|
181
194
|
}
|
|
182
195
|
try {
|
|
183
196
|
const work = state.target.channel.sendThinking!(state.target.chatId, state.prefix, options)
|
package/src/engine/types.ts
CHANGED
|
@@ -104,6 +104,8 @@ export interface ChannelAdapter {
|
|
|
104
104
|
setTopicEditHandler?(handler: (chatId: string, name: string) => void): void
|
|
105
105
|
/** 企业微信等回调通道不能等合并窗口,必须立刻处理。 */
|
|
106
106
|
skipMerge?: boolean
|
|
107
|
+
/** 渠道支持的最大思考内容字符预算;未声明时由引擎按默认安全上限(单条 4,096,原生流式 65,536)兜底。 */
|
|
108
|
+
maxThinkingChars?: number
|
|
107
109
|
/**
|
|
108
110
|
* 把模型的思考过程发成一条可在聊天里折叠/展开的消息(近似网页里收起的思考行)。
|
|
109
111
|
*
|
|
@@ -113,6 +115,12 @@ export interface ChannelAdapter {
|
|
|
113
115
|
sendThinking?(chatId: string, text: string, options?: ThinkingOptions): Promise<void>
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
/** 思考过程截断提示语(基础文案)。 */
|
|
119
|
+
export const DEFAULT_TRUNCATED_NOTE = '…(已截断,完整内容见网页会话)'
|
|
120
|
+
|
|
121
|
+
/** 思考过程单条消息的默认最大字符预算(普通单条消息渠道如 Telegram 适用)。 */
|
|
122
|
+
export const DEFAULT_THINKING_MAX_CHARS = 3_500
|
|
123
|
+
|
|
116
124
|
/** 思考过程消息的渲染参数;标题由引擎按宿主语言生成。 */
|
|
117
125
|
export interface ThinkingOptions {
|
|
118
126
|
/** 本次输出的唯一身份;引擎为每个会话回合生成,不得跨回合复用。 */
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { homedir } from 'node:os'
|
|
|
7
7
|
import { join } from 'node:path'
|
|
8
8
|
import { mkdirSync } from 'node:fs'
|
|
9
9
|
import { ChannelManager } from './manager.js'
|
|
10
|
-
import type
|
|
10
|
+
import { DEFAULT_THINKING_MAX_CHARS, type EngineConfig } from './engine/types.js'
|
|
11
11
|
import type { TopicMode } from './engine/topic-title.js'
|
|
12
12
|
import { createRotatingFileAppender } from './engine/file-log.js'
|
|
13
13
|
import { withReplyLocale } from './engine/command-locale.js'
|
|
@@ -60,7 +60,7 @@ export const Config: Schema<PluginConfig> = Schema.object({
|
|
|
60
60
|
mode: Schema.union(['off', 'collapsed']).default('off').description('思考过程投递:off 关闭,collapsed 发成可折叠消息。'),
|
|
61
61
|
minChars: Schema.number().default(120).description('累计到这个字数才发第一条思考消息。'),
|
|
62
62
|
intervalMs: Schema.number().default(2000).description('两次思考消息刷新之间的最小间隔(毫秒)。'),
|
|
63
|
-
maxChars: Schema.number().default(
|
|
63
|
+
maxChars: Schema.number().default(DEFAULT_THINKING_MAX_CHARS).description('单条思考消息允许的最大字符数(原生流式长思维链渠道如飞书除外,享有 64K 原生流式预算)。'),
|
|
64
64
|
}).description('思考过程折叠消息;需要渠道实现 sendThinking(目前支持 Telegram、飞书与 Lark)。'),
|
|
65
65
|
})
|
|
66
66
|
|