@michengai/dsh-im-connect 1.0.42 → 1.0.43
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 +9 -0
- package/CHANGELOG.zh-CN.md +9 -0
- package/README.de.md +1 -1
- package/README.en.md +4 -2
- package/README.es.md +1 -1
- package/README.fr.md +1 -1
- package/README.ja.md +1 -1
- package/README.md +4 -2
- package/README.pt.md +1 -1
- package/README.ru.md +1 -1
- package/README.zh-CN.md +4 -2
- package/client.js +1 -1
- package/lib/channels/feishu.d.ts +8 -0
- package/lib/channels/feishu.d.ts.map +1 -1
- package/lib/channels/feishu.js +295 -0
- package/lib/channels/feishu.js.map +1 -1
- package/lib/client.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +3 -1
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/channels/feishu.ts +333 -2
- package/src/index.ts +1 -1
- package/src/manager.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.43] - 2026-11-17
|
|
4
|
+
|
|
5
|
+
### Feishu & Lark Thinking Process
|
|
6
|
+
|
|
7
|
+
- **Native thinking process bubbles**: Added support for displaying model reasoning (Thinking Process) in Feishu and Lark. Direct messages and main group chats use official native thinking process bubbles that can be expanded to review the complete chain of thought.
|
|
8
|
+
- **In-thread collapsible fallback**: In group message threads, reasoning automatically falls back to an expandable card panel (`collapsible_panel`), ensuring thought processes stay within the thread without leaking to the main lobby; smoothly falls back to cards if the tenant lacks native permissions.
|
|
9
|
+
- **Long reasoning & complex emoji display**: Improved presentation for long reasoning steps and composite emojis (such as diverse family and skin-tone emoji sequences), preventing split characters, garbled text, or corrupted symbols when displaying lengthy thought processes.
|
|
10
|
+
- **How to enable**: Navigate to Settings → IM Connect → Feishu/Lark account settings, and set "Thinking process display" to "Collapsed" (defaults to system preference).
|
|
11
|
+
|
|
3
12
|
## [1.0.42] - 2026-11-17
|
|
4
13
|
|
|
5
14
|
### Feishu Threads & Reply Experience
|
package/CHANGELOG.zh-CN.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## [1.0.43] - 2026-11-17
|
|
4
|
+
|
|
5
|
+
### 飞书与 Lark 思考过程展示
|
|
6
|
+
|
|
7
|
+
- **原生思考过程支持**:飞书与 Lark 渠道支持折叠展示模型的思考过程(Thinking Process)。在私聊与群大厅普通消息中,采用官方原生思考过程气泡展示,可展开查看完整推理思维链。
|
|
8
|
+
- **话题内平滑折叠卡片**:群聊话题回复串(Thread)中自动平滑降级为折叠卡片展示思考过程,确保思维链留在话题串内,绝不出串污染群公屏;租户未开通原生权限时同样平滑折叠展示。
|
|
9
|
+
- **长思维链与复杂表情保护**:优化长思考过程的分段展示与表情符号解析,完整保护复合表情(如包含多种肤色与多成员的 Emoji 组合),彻底避免分段时出现乱码或文字渲染割裂。
|
|
10
|
+
- **开启方式**:进入「设置 → 即时通讯 → 飞书/Lark 账号详情」,将「展示思考过程」选项设为「折叠展示」(默认跟随系统)。
|
|
11
|
+
|
|
3
12
|
## [1.0.42] - 2026-11-17
|
|
4
13
|
|
|
5
14
|
### 飞书话题与回复体验
|
package/README.de.md
CHANGED
|
@@ -101,7 +101,7 @@ Erreichbar über die Verwaltung unter **Plugins → @michengai/dsh-im-connect**:
|
|
|
101
101
|
|
|
102
102
|
### 4. Einklappbare Denkprozess-Anzeige (`thinkingDisplay`)
|
|
103
103
|
- **Standard**: Aus (`off`)
|
|
104
|
-
- **Funktion**: Übermittelt den Denkprozess des Modells auf Telegram als einklappbaren Zitatblock (`<blockquote expandable>`).
|
|
104
|
+
- **Funktion**: Übermittelt den Denkprozess des Modells auf Telegram als einklappbaren Zitatblock (`<blockquote expandable>`) sowie auf Feishu/Lark als nativen Denkprozess bzw. einklappbare Karte in Threads.
|
|
105
105
|
|
|
106
106
|
### 5. Feishu-Thread-Sitzungsisolation (`threadSessions`)
|
|
107
107
|
- **Standard**: Deaktiviert (`false`)
|
package/README.en.md
CHANGED
|
@@ -297,7 +297,9 @@ Native configuration options are provided here. Their values are persisted in `c
|
|
|
297
297
|
|
|
298
298
|
### 4. Collapsible thinking message (`thinkingDisplay`)
|
|
299
299
|
- **Default**: off (`mode: 'off'`).
|
|
300
|
-
- **What it does**: when enabled, the model's reasoning is
|
|
300
|
+
- **What it does**: when enabled, the model's reasoning is presented in an expandable form:
|
|
301
|
+
- **Telegram**: sent as a separate collapsible quote (`<blockquote expandable>`), about three lines collapsed, tap "show more" to expand; edited in place during the turn and retitled "🧠 Thought process" when the turn ends.
|
|
302
|
+
- **Feishu / Lark**: sent as an official native thinking-process bubble (`/open-apis/im/v1/message_cot`) for direct messages and main chat; seamlessly falls back to a collapsible card (`collapsible_panel`) within group message threads or when the tenant lacks native CoT permission, preventing reasoning from leaking outside threads.
|
|
301
303
|
- **Example** (plugin config slot):
|
|
302
304
|
```yaml
|
|
303
305
|
thinkingDisplay:
|
|
@@ -306,7 +308,7 @@ Native configuration options are provided here. Their values are persisted in `c
|
|
|
306
308
|
intervalMs: 2000 # minimum interval between refreshes
|
|
307
309
|
maxChars: 3500 # per-message cap; longer text is truncated and noted
|
|
308
310
|
```
|
|
309
|
-
- **Channel and UI support**: implemented for Telegram; can be enabled in **Settings → IM Assistant →
|
|
311
|
+
- **Channel and UI support**: implemented for Telegram, Feishu, and Lark; can be enabled in **Settings → IM Assistant → Account Details** by selecting **Collapsed** in the **Show thinking process** dropdown. Other channels ignore the setting and keep the existing status line.
|
|
310
312
|
- **Boundaries and privacy**: collapsing is client-side display, not access control; everyone who can read the group message can expand the reasoning. Enable only where sharing reasoning is intentional. Thinking is not counted as final-answer delivery or included in automatic recovery.
|
|
311
313
|
- **Resources and lifecycle**: off/unsupported channels retain no raw reasoning. When enabled, each turn retains at most a 4096 UTF-16-unit prefix plus a scalar character count. Pending refreshes coalesce to the latest snapshot; cancellation, rebinding, muting, unloading and turn replacement prevent stale output.
|
|
312
314
|
- **Ranges**: `minChars` 0–4096 (also applied on final), `intervalMs` 1000–60000, `maxChars` 200–4096. Finite out-of-range values are clamped, nonfinite values use defaults. HTML escaping, labels, wrappers and truncation notes all fit the budget without splitting emoji surrogate pairs.
|
package/README.es.md
CHANGED
|
@@ -101,7 +101,7 @@ Disponible desde el panel de administración en **Complementos → @michengai/ds
|
|
|
101
101
|
|
|
102
102
|
### 4. Mensaje de pensamiento plegable (`thinkingDisplay`)
|
|
103
103
|
- **Predeterminado**: Desactivado (`off`)
|
|
104
|
-
- **Función**: Envía la cadena de pensamiento del modelo en Telegram
|
|
104
|
+
- **Función**: Envía la cadena de pensamiento del modelo en Telegram (`<blockquote expandable>`) y Feishu/Lark (proceso de pensamiento nativo o tarjeta plegable en hilos).
|
|
105
105
|
|
|
106
106
|
### 5. Aislamiento de sesiones de hilos en Feishu (`threadSessions`)
|
|
107
107
|
- **Predeterminado**: Desactivado (`false`)
|
package/README.fr.md
CHANGED
|
@@ -101,7 +101,7 @@ Gérée depuis le panneau **Extensions → @michengai/dsh-im-connect** :
|
|
|
101
101
|
|
|
102
102
|
### 4. Affichage repliable de la réflexion (`thinkingDisplay`)
|
|
103
103
|
- **Défaut** : Désactivé (`off`)
|
|
104
|
-
- **Fonction** : Transmet le cheminement de pensée du modèle sous forme de bloc de citation repliable Telegram (`<blockquote expandable>`).
|
|
104
|
+
- **Fonction** : Transmet le cheminement de pensée du modèle sous forme de bloc de citation repliable Telegram (`<blockquote expandable>`) ou de bulle native / carte repliable Feishu/Lark.
|
|
105
105
|
|
|
106
106
|
### 5. Isolation des sessions de fil Feishu (`threadSessions`)
|
|
107
107
|
- **Défaut** : Désactivé (`false`)
|
package/README.ja.md
CHANGED
|
@@ -158,7 +158,7 @@ dsh plugin --profile web add @michengai/dsh-im-connect --registry=https://regist
|
|
|
158
158
|
|
|
159
159
|
### 4. 思考プロセスの折りたたみ表示 (`thinkingDisplay`)
|
|
160
160
|
- **デフォルト**: オフ (`off`)
|
|
161
|
-
- **機能**: モデルの思考プロセスを Telegram
|
|
161
|
+
- **機能**: モデルの思考プロセスを Telegram(折りたたみ引用ブロック `<blockquote expandable>`)および Feishu/Lark(ネイティブ思考プロセスおよびスレッド内カード折りたたみ)として送信し、タップで展開できるようにします。
|
|
162
162
|
|
|
163
163
|
### 5. 飛書(Feishu)スレッドセッション分離 (`threadSessions`)
|
|
164
164
|
- **デフォルト**: 無効 (`false`)
|
package/README.md
CHANGED
|
@@ -297,7 +297,9 @@ dsh --profile web --dump-config
|
|
|
297
297
|
|
|
298
298
|
### 4. 思考过程折叠消息 (`thinkingDisplay`)
|
|
299
299
|
- **默认状态**:关闭(`mode: 'off'`)
|
|
300
|
-
-
|
|
300
|
+
- **功能说明**:开启后,模型的思考过程会单独呈现:
|
|
301
|
+
- **Telegram**:发成一条「可折叠引用块」消息(`<blockquote expandable>`),默认显示约三行,点「显示更多」展开;同一回合就地编辑,回合结束时标题变为「🧠 思考过程」。
|
|
302
|
+
- **飞书 / Lark**:私聊与群大厅普通消息走飞书官方原生思考过程气泡(`/open-apis/im/v1/message_cot`);群话题回复串(Thread)或租户无原生 CoT 权限时自动平滑降级为飞书交互卡片折叠面板(`collapsible_panel`),确保过程绝不出串污染群大厅。
|
|
301
303
|
- **配置示例**(插件配置槽位):
|
|
302
304
|
```yaml
|
|
303
305
|
thinkingDisplay:
|
|
@@ -306,7 +308,7 @@ dsh --profile web --dump-config
|
|
|
306
308
|
intervalMs: 2000 # 两次刷新的最小间隔
|
|
307
309
|
maxChars: 3500 # 单条上限,超出截断并注明
|
|
308
310
|
```
|
|
309
|
-
- **渠道与界面支持**:目前由 Telegram 实现,可在「设置 → IM助理 →
|
|
311
|
+
- **渠道与界面支持**:目前由 Telegram、飞书与 Lark 实现,可在「设置 → IM助理 → 账号详情」中通过「展示思考过程」下拉选择「折叠展示」一键开启;其他渠道会忽略该配置,只保留原有状态行。
|
|
310
312
|
- **边界与隐私**:折叠是客户端展示,不是访问控制,群内所有能看到消息的人均能点击展开思考内容。请只在明确允许公开展示思维链的部署中开启;思考消息不会被算作最终答案的送达或自动补发内容。
|
|
311
313
|
- **资源与生命周期**:关闭或渠道不支持时不缓存思考原文;开启时每回合最多保留 4096 个 UTF-16 单元的前缀和总字数。刷新合并为最新快照,停止、换绑、静音、卸载及下一回合会阻止过期输出。
|
|
312
314
|
- **参数范围**:`minChars` 为 0–4096(结束时同样适用),`intervalMs` 为 1000–60000,`maxChars` 为 200–4096;超界值收敛到范围,非有限数字使用默认值。实际 HTML 转义、标题、标签与截断提示均计入预算,不切开 emoji 代理对。
|
package/README.pt.md
CHANGED
|
@@ -101,7 +101,7 @@ Acessível no painel em **Plugins → @michengai/dsh-im-connect**:
|
|
|
101
101
|
|
|
102
102
|
### 4. Bloco recolhível de raciocínio (`thinkingDisplay`)
|
|
103
103
|
- **Padrão**: Desativado (`off`)
|
|
104
|
-
- **Função**: Envia a cadeia de pensamento no Telegram
|
|
104
|
+
- **Função**: Envia a cadeia de pensamento no Telegram (`<blockquote expandable>`) e Feishu/Lark (processo nativo de pensamento ou cartão recolhível em tópicos).
|
|
105
105
|
|
|
106
106
|
### 5. Isolamento de sessões de tópicos no Feishu (`threadSessions`)
|
|
107
107
|
- **Padrão**: Desativado (`false`)
|
package/README.ru.md
CHANGED
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
|
|
102
102
|
### 4. Сворачиваемый блок цепочки мыслей (`thinkingDisplay`)
|
|
103
103
|
- **По умолчанию**: Отключено (`off`)
|
|
104
|
-
- **Назначение**: Передает процесс рассуждений модели в Telegram
|
|
104
|
+
- **Назначение**: Передает процесс рассуждений модели в Telegram (сворачиваемая цитата `<blockquote expandable>`) и Feishu/Lark (нативный процесс CoT или сворачиваемая карточка в тредах).
|
|
105
105
|
|
|
106
106
|
### 5. Изоляция сессий тредов в Feishu (`threadSessions`)
|
|
107
107
|
- **По умолчанию**: Отключено (`false`)
|
package/README.zh-CN.md
CHANGED
|
@@ -297,7 +297,9 @@ dsh --profile web --dump-config
|
|
|
297
297
|
|
|
298
298
|
### 4. 思考过程折叠消息 (`thinkingDisplay`)
|
|
299
299
|
- **默认状态**:关闭(`mode: 'off'`)
|
|
300
|
-
-
|
|
300
|
+
- **功能说明**:开启后,模型的思考过程会单独呈现:
|
|
301
|
+
- **Telegram**:发成一条「可折叠引用块」消息(`<blockquote expandable>`),默认显示约三行,点「显示更多」展开;同一回合就地编辑,回合结束时标题变为「🧠 思考过程」。
|
|
302
|
+
- **飞书 / Lark**:私聊与群大厅普通消息走飞书官方原生思考过程气泡(`/open-apis/im/v1/message_cot`);群话题回复串(Thread)或租户无原生 CoT 权限时自动平滑降级为飞书交互卡片折叠面板(`collapsible_panel`),确保过程绝不出串污染群大厅。
|
|
301
303
|
- **配置示例**(插件配置槽位):
|
|
302
304
|
```yaml
|
|
303
305
|
thinkingDisplay:
|
|
@@ -306,7 +308,7 @@ dsh --profile web --dump-config
|
|
|
306
308
|
intervalMs: 2000 # 两次刷新的最小间隔
|
|
307
309
|
maxChars: 3500 # 单条上限,超出截断并注明
|
|
308
310
|
```
|
|
309
|
-
- **渠道与界面支持**:目前由 Telegram 实现,可在「设置 → IM助理 →
|
|
311
|
+
- **渠道与界面支持**:目前由 Telegram、飞书与 Lark 实现,可在「设置 → IM助理 → 账号详情」中通过「展示思考过程」下拉选择「折叠展示」一键开启;其他渠道会忽略该配置,只保留原有状态行。
|
|
310
312
|
- **边界与隐私**:折叠是客户端展示,不是访问控制,群内所有能看到消息的人均能点击展开思考内容。请只在明确允许公开展示思维链的部署中开启;思考消息不会被算作最终答案的送达或自动补发内容。
|
|
311
313
|
- **资源与生命周期**:关闭或渠道不支持时不缓存思考原文;开启时每回合最多保留 4096 个 UTF-16 单元的前缀和总字数。刷新合并为最新快照,停止、换绑、静音、卸载及下一回合会阻止过期输出。
|
|
312
314
|
- **参数范围**:`minChars` 为 0–4096(结束时同样适用),`intervalMs` 为 1000–60000,`maxChars` 为 200–4096;超界值收敛到范围,非有限数字使用默认值。实际 HTML 转义、标题、标签与截断提示均计入预算,不切开 emoji 代理对。
|
package/client.js
CHANGED
|
@@ -4671,7 +4671,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
|
|
|
4671
4671
|
h(AccountSettingsPicker, {
|
|
4672
4672
|
value: draft,
|
|
4673
4673
|
onChange: applySettings,
|
|
4674
|
-
thinkingDisplaySupported: account.platform === "telegram",
|
|
4674
|
+
thinkingDisplaySupported: account.platform === "telegram" || account.platform === "feishu" || account.platform === "lark",
|
|
4675
4675
|
segmentReplySupported: account.segmentReplySupported !== false,
|
|
4676
4676
|
catalog,
|
|
4677
4677
|
permissions,
|
package/lib/channels/feishu.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { ChannelAdapter, ImMedia } from '../engine/types.js';
|
|
2
2
|
/** 飞书一张卡片最多 5 个 table 元素,超了整个写入会被拒(230099 / ErrCode 11310),旧卡片内容会卡住。 */
|
|
3
3
|
export declare const FEISHU_CARD_MAX_TABLES = 5;
|
|
4
|
+
export declare const FEISHU_COT_API = "/open-apis/im/v1/message_cot";
|
|
5
|
+
export declare const FEISHU_COT_COMPLETE_API = "/open-apis/im/v1/message_cot/complete";
|
|
6
|
+
/** 飞书 message_cot 单个事件内容字符上限保护,避免 10001 AppendCOTEvents: event[0] content too long */
|
|
7
|
+
export declare const FEISHU_COT_CHUNK_SIZE = 800;
|
|
8
|
+
/** 按 Unicode 字形簇(Grapheme Cluster)安全切分文本,严禁切开 Emoji 代理对或 ZWJ 复合表情 */
|
|
9
|
+
export declare function chunkByGraphemes(text: string, maxChunkLength: number): string[];
|
|
10
|
+
/** 保持历史兼容别名 */
|
|
11
|
+
export declare const chunkByCodePoints: typeof chunkByGraphemes;
|
|
4
12
|
/** 按表格数量拆正文,保证每张卡不超上限,且不会把表格切一半。 */
|
|
5
13
|
export declare function splitByTableLimit(text: string, maxTables?: number): string[];
|
|
6
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feishu.d.ts","sourceRoot":"","sources":["../../src/channels/feishu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"feishu.d.ts","sourceRoot":"","sources":["../../src/channels/feishu.ts"],"names":[],"mappings":"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"}
|
package/lib/channels/feishu.js
CHANGED
|
@@ -10,6 +10,53 @@ import { fileMedia, MAX_CHANNEL_IMAGES } from './channel-image-download.js';
|
|
|
10
10
|
import { markdownTableOffsets } from '../engine/split.js';
|
|
11
11
|
/** 飞书一张卡片最多 5 个 table 元素,超了整个写入会被拒(230099 / ErrCode 11310),旧卡片内容会卡住。 */
|
|
12
12
|
export const FEISHU_CARD_MAX_TABLES = 5;
|
|
13
|
+
export const FEISHU_COT_API = '/open-apis/im/v1/message_cot';
|
|
14
|
+
export const FEISHU_COT_COMPLETE_API = '/open-apis/im/v1/message_cot/complete';
|
|
15
|
+
/** 飞书 message_cot 单个事件内容字符上限保护,避免 10001 AppendCOTEvents: event[0] content too long */
|
|
16
|
+
export const FEISHU_COT_CHUNK_SIZE = 800;
|
|
17
|
+
/** 按 Unicode 字形簇(Grapheme Cluster)安全切分文本,严禁切开 Emoji 代理对或 ZWJ 复合表情 */
|
|
18
|
+
export function chunkByGraphemes(text, maxChunkLength) {
|
|
19
|
+
if (text.length <= maxChunkLength)
|
|
20
|
+
return [text];
|
|
21
|
+
const chunks = [];
|
|
22
|
+
let currentChunk = '';
|
|
23
|
+
let units;
|
|
24
|
+
if (typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function') {
|
|
25
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
26
|
+
units = {
|
|
27
|
+
*[Symbol.iterator]() {
|
|
28
|
+
for (const { segment } of segmenter.segment(text)) {
|
|
29
|
+
yield segment;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
units = text;
|
|
36
|
+
}
|
|
37
|
+
for (const unit of units) {
|
|
38
|
+
if (currentChunk.length + unit.length > maxChunkLength && currentChunk.length > 0) {
|
|
39
|
+
chunks.push(currentChunk);
|
|
40
|
+
currentChunk = '';
|
|
41
|
+
}
|
|
42
|
+
currentChunk += unit;
|
|
43
|
+
}
|
|
44
|
+
if (currentChunk.length > 0) {
|
|
45
|
+
chunks.push(currentChunk);
|
|
46
|
+
}
|
|
47
|
+
return chunks;
|
|
48
|
+
}
|
|
49
|
+
/** 保持历史兼容别名 */
|
|
50
|
+
export const chunkByCodePoints = chunkByGraphemes;
|
|
51
|
+
function cotEvent(eventType, content, state) {
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
const ts = state ? (state.lastCotTimestamp = Math.max(now, (state.lastCotTimestamp ?? 0) + 1)) : now;
|
|
54
|
+
return {
|
|
55
|
+
event_type: eventType,
|
|
56
|
+
content: JSON.stringify(content),
|
|
57
|
+
timestamp: String(ts),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
13
60
|
/** 按表格数量拆正文,保证每张卡不超上限,且不会把表格切一半。 */
|
|
14
61
|
export function splitByTableLimit(text, maxTables = FEISHU_CARD_MAX_TABLES) {
|
|
15
62
|
const value = text ?? '';
|
|
@@ -383,6 +430,247 @@ export function createFeishuChannel(id, config, log, loadSdk) {
|
|
|
383
430
|
let statusText = '未连接';
|
|
384
431
|
let lifecycle;
|
|
385
432
|
const label = id === 'lark' ? 'Lark' : '飞书';
|
|
433
|
+
const openThinking = new Map();
|
|
434
|
+
const activeThinking = new Set();
|
|
435
|
+
/** 思考过程投递:非话题(私聊/群大厅)走飞书原生 message_cot;话题回复串(thread)或权限不足时平滑降级为折叠卡片 */
|
|
436
|
+
async function publishThinking(chatId, text, options) {
|
|
437
|
+
if (!client || !lifecycle || lifecycle.signal.aborted || options?.signal?.aborted || options?.isCurrent?.() === false)
|
|
438
|
+
return;
|
|
439
|
+
const key = JSON.stringify([chatId, options?.streamId ?? 'legacy']);
|
|
440
|
+
let state = openThinking.get(key);
|
|
441
|
+
if (!state) {
|
|
442
|
+
if (!text.trim())
|
|
443
|
+
return;
|
|
444
|
+
const scope = new AbortController();
|
|
445
|
+
const signal = options?.signal ? AbortSignal.any([scope.signal, options.signal, lifecycle.signal]) : AbortSignal.any([scope.signal, lifecycle.signal]);
|
|
446
|
+
const { threadId } = parseFeishuChatId(chatId);
|
|
447
|
+
// 话题回复串(thread)内直接走折叠卡片,避免污染群大厅;大厅与私聊优先尝试原生 CoT
|
|
448
|
+
const initialMode = threadId ? 'card' : 'cot';
|
|
449
|
+
state = {
|
|
450
|
+
key,
|
|
451
|
+
chatId,
|
|
452
|
+
mode: initialMode,
|
|
453
|
+
sentChars: 0,
|
|
454
|
+
sealed: false,
|
|
455
|
+
scope,
|
|
456
|
+
guard: { signal, isCurrent: options?.isCurrent },
|
|
457
|
+
detach: () => { },
|
|
458
|
+
};
|
|
459
|
+
const current = state;
|
|
460
|
+
const cancel = () => {
|
|
461
|
+
current.pending = undefined;
|
|
462
|
+
if (openThinking.get(key) === current)
|
|
463
|
+
openThinking.delete(key);
|
|
464
|
+
activeThinking.delete(current);
|
|
465
|
+
current.detach();
|
|
466
|
+
};
|
|
467
|
+
current.detach = () => signal.removeEventListener('abort', cancel);
|
|
468
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
469
|
+
openThinking.set(key, current);
|
|
470
|
+
activeThinking.add(current);
|
|
471
|
+
}
|
|
472
|
+
if (state.failed) {
|
|
473
|
+
if (options?.final) {
|
|
474
|
+
openThinking.delete(key);
|
|
475
|
+
activeThinking.delete(state);
|
|
476
|
+
state.detach();
|
|
477
|
+
}
|
|
478
|
+
throw state.failed;
|
|
479
|
+
}
|
|
480
|
+
state.pending = { text, options };
|
|
481
|
+
if (options?.final === true) {
|
|
482
|
+
state.sealed = true;
|
|
483
|
+
if (openThinking.get(key) === state)
|
|
484
|
+
openThinking.delete(key);
|
|
485
|
+
}
|
|
486
|
+
if (!state.running) {
|
|
487
|
+
const current = state;
|
|
488
|
+
const drain = () => current.running = Promise.resolve().then(async () => {
|
|
489
|
+
while (current.pending) {
|
|
490
|
+
const next = current.pending;
|
|
491
|
+
current.pending = undefined;
|
|
492
|
+
current.guard.signal.throwIfAborted();
|
|
493
|
+
if (current.guard.isCurrent?.() === false)
|
|
494
|
+
break;
|
|
495
|
+
if (!client)
|
|
496
|
+
break;
|
|
497
|
+
const { chatId: targetChatId } = parseFeishuChatId(chatId);
|
|
498
|
+
const runId = next.options?.streamId ?? 'turn';
|
|
499
|
+
const label = next.options?.label ?? (next.options?.final ? '🧠 思考过程' : '🧠 思考中…');
|
|
500
|
+
// 文本预算与截断处理(对齐 maxChars 与 truncated 契约)
|
|
501
|
+
const requestedMaxChars = typeof next.options?.maxChars === 'number' && Number.isFinite(next.options.maxChars)
|
|
502
|
+
? next.options.maxChars
|
|
503
|
+
: 3500;
|
|
504
|
+
const maxChars = Math.min(4096, Math.max(200, Math.floor(requestedMaxChars)));
|
|
505
|
+
const TRUNCATED_NOTE = '\n\n…(已截断,完整内容见网页会话)';
|
|
506
|
+
let processedText = next.text;
|
|
507
|
+
let isTruncated = next.options?.truncated === true;
|
|
508
|
+
if (processedText.length > maxChars) {
|
|
509
|
+
let end = 0;
|
|
510
|
+
const budget = Math.max(0, maxChars - TRUNCATED_NOTE.length);
|
|
511
|
+
for (const char of processedText) {
|
|
512
|
+
if (end + char.length > budget)
|
|
513
|
+
break;
|
|
514
|
+
end += char.length;
|
|
515
|
+
}
|
|
516
|
+
processedText = processedText.slice(0, end);
|
|
517
|
+
isTruncated = true;
|
|
518
|
+
}
|
|
519
|
+
if (isTruncated && !processedText.endsWith(TRUNCATED_NOTE)) {
|
|
520
|
+
processedText += TRUNCATED_NOTE;
|
|
521
|
+
}
|
|
522
|
+
// 1. 尝试原生 CoT 模式
|
|
523
|
+
if (current.mode === 'cot') {
|
|
524
|
+
try {
|
|
525
|
+
if (!current.cotId) {
|
|
526
|
+
const res = await client.request({
|
|
527
|
+
method: 'POST',
|
|
528
|
+
url: `${FEISHU_COT_API}?receive_id_type=chat_id`,
|
|
529
|
+
data: {
|
|
530
|
+
receive_id: targetChatId,
|
|
531
|
+
cot_hidden: false,
|
|
532
|
+
enable_badge: false,
|
|
533
|
+
update_feed_rank: false,
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
if (!res || isRejectedCode(res.code) || !res.data?.cot_id || !res.data?.message_id) {
|
|
537
|
+
log(`[${id}] 原生 message_cot 创建失败 (code=${res?.code}),降级为卡片折叠显示`);
|
|
538
|
+
current.mode = 'card';
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
current.cotId = res.data.cot_id;
|
|
542
|
+
current.cotMessageId = res.data.message_id;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (current.mode === 'cot' && current.cotId && current.cotMessageId) {
|
|
546
|
+
const delta = processedText.slice(current.sentChars);
|
|
547
|
+
const events = [];
|
|
548
|
+
const reasoningMessageId = `reasoning-${runId}`;
|
|
549
|
+
if (!current.reasoningStarted) {
|
|
550
|
+
events.push(cotEvent('RUN_STARTED', { threadId: targetChatId, runId }, current));
|
|
551
|
+
events.push(cotEvent('REASONING_MESSAGE_START', { messageId: reasoningMessageId, role: 'reasoning' }, current));
|
|
552
|
+
current.reasoningStarted = true;
|
|
553
|
+
}
|
|
554
|
+
if (delta.length > 0) {
|
|
555
|
+
const chunks = chunkByGraphemes(delta, FEISHU_COT_CHUNK_SIZE);
|
|
556
|
+
for (const chunk of chunks) {
|
|
557
|
+
events.push(cotEvent('REASONING_MESSAGE_CONTENT', { messageId: reasoningMessageId, delta: chunk }, current));
|
|
558
|
+
}
|
|
559
|
+
current.sentChars = processedText.length;
|
|
560
|
+
}
|
|
561
|
+
if (next.options?.final) {
|
|
562
|
+
events.push(cotEvent('REASONING_MESSAGE_END', { messageId: reasoningMessageId }, current));
|
|
563
|
+
events.push(cotEvent('RUN_FINISHED', { threadId: targetChatId, runId, status: 'done' }, current));
|
|
564
|
+
}
|
|
565
|
+
if (events.length > 0) {
|
|
566
|
+
const putRes = await client.request({
|
|
567
|
+
method: 'PUT',
|
|
568
|
+
url: FEISHU_COT_API,
|
|
569
|
+
data: {
|
|
570
|
+
cot_id: current.cotId,
|
|
571
|
+
message_id: current.cotMessageId,
|
|
572
|
+
events,
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
if (!putRes || isRejectedCode(putRes.code)) {
|
|
576
|
+
log(`[${id}] 原生 CoT 事件写入被拒 (code=${putRes?.code}, msg=${putRes?.msg}),降级为卡片折叠`);
|
|
577
|
+
current.mode = 'card';
|
|
578
|
+
}
|
|
579
|
+
else if (next.options?.final) {
|
|
580
|
+
try {
|
|
581
|
+
const completeRes = await client.request({
|
|
582
|
+
method: 'POST',
|
|
583
|
+
url: `${FEISHU_COT_COMPLETE_API}/${current.cotId}?message_id=${current.cotMessageId}&reason=done`,
|
|
584
|
+
});
|
|
585
|
+
if (!completeRes || isRejectedCode(completeRes.code)) {
|
|
586
|
+
log(`[${id}] 原生 CoT 完成收口通知被拒 (code=${completeRes?.code}, msg=${completeRes?.msg})`);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
catch (completeErr) {
|
|
590
|
+
log(`[${id}] 原生 CoT 完成收口通知异常: ${completeErr instanceof Error ? completeErr.message : String(completeErr)}`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
if (throttledResponse(error))
|
|
598
|
+
return;
|
|
599
|
+
log(`[${id}] 原生 CoT 发送异常: ${error instanceof Error ? error.message : String(error)},降级为卡片折叠`);
|
|
600
|
+
current.mode = 'card';
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
// 2. 卡片折叠模式(话题内、或原生 CoT 降级)
|
|
604
|
+
if (current.mode === 'card') {
|
|
605
|
+
try {
|
|
606
|
+
const cardContent = JSON.stringify({
|
|
607
|
+
schema: '2.0',
|
|
608
|
+
config: { wide_screen_mode: true },
|
|
609
|
+
body: {
|
|
610
|
+
elements: [
|
|
611
|
+
{
|
|
612
|
+
tag: 'collapsible_panel',
|
|
613
|
+
header: {
|
|
614
|
+
title: { tag: 'plain_text', content: label },
|
|
615
|
+
},
|
|
616
|
+
border: { color: 'grey' },
|
|
617
|
+
expanded: false,
|
|
618
|
+
elements: [
|
|
619
|
+
{ tag: 'markdown', content: processedText },
|
|
620
|
+
],
|
|
621
|
+
},
|
|
622
|
+
],
|
|
623
|
+
},
|
|
624
|
+
});
|
|
625
|
+
if (cardContent !== current.lastCardContent) {
|
|
626
|
+
if (!current.cardMessageId) {
|
|
627
|
+
const sent = await postFeishuMessage(client, chatId, 'interactive', cardContent, line => log(`[${id}] ${line}`));
|
|
628
|
+
if (!isRejectedCode(sent?.code) && sent?.data?.message_id) {
|
|
629
|
+
current.cardMessageId = sent.data.message_id;
|
|
630
|
+
current.lastCardContent = cardContent;
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
log(`[${id}] 思考卡片创建被拒 (code=${sent?.code})`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
const patchRes = await client.im.message.patch({
|
|
638
|
+
path: { message_id: current.cardMessageId },
|
|
639
|
+
data: { content: cardContent },
|
|
640
|
+
});
|
|
641
|
+
if (!isRejectedCode(patchRes?.code)) {
|
|
642
|
+
current.lastCardContent = cardContent;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
if (throttledResponse(error))
|
|
649
|
+
return;
|
|
650
|
+
log(`[${id}] 思考卡片发送或更新异常: ${error instanceof Error ? error.message : String(error)}`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}).catch(error => {
|
|
655
|
+
current.failed = error;
|
|
656
|
+
current.pending = undefined;
|
|
657
|
+
throw error;
|
|
658
|
+
}).finally(() => {
|
|
659
|
+
current.running = undefined;
|
|
660
|
+
const canceled = current.guard.signal.aborted || current.guard.isCurrent?.() === false;
|
|
661
|
+
if (!current.failed && !canceled && current.pending)
|
|
662
|
+
return drain();
|
|
663
|
+
if (current.sealed || canceled) {
|
|
664
|
+
if (openThinking.get(key) === current)
|
|
665
|
+
openThinking.delete(key);
|
|
666
|
+
activeThinking.delete(current);
|
|
667
|
+
current.detach();
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
drain();
|
|
671
|
+
}
|
|
672
|
+
return state.running;
|
|
673
|
+
}
|
|
386
674
|
return {
|
|
387
675
|
id,
|
|
388
676
|
label,
|
|
@@ -491,6 +779,12 @@ export function createFeishuChannel(id, config, log, loadSdk) {
|
|
|
491
779
|
lifecycle = undefined;
|
|
492
780
|
ws?.close({ force: true });
|
|
493
781
|
ws = undefined;
|
|
782
|
+
for (const thinking of activeThinking) {
|
|
783
|
+
thinking.scope.abort();
|
|
784
|
+
thinking.detach();
|
|
785
|
+
}
|
|
786
|
+
openThinking.clear();
|
|
787
|
+
activeThinking.clear();
|
|
494
788
|
statusText = '已停止';
|
|
495
789
|
},
|
|
496
790
|
canDeliverDeferred() { return statusText === '长连接已建立'; },
|
|
@@ -631,6 +925,7 @@ export function createFeishuChannel(id, config, log, loadSdk) {
|
|
|
631
925
|
requireDiagnostic(typeof bot?.open_id === 'string' && bot.open_id);
|
|
632
926
|
})];
|
|
633
927
|
},
|
|
928
|
+
sendThinking: publishThinking,
|
|
634
929
|
status() { return statusText; },
|
|
635
930
|
};
|
|
636
931
|
}
|