dsh-im-lark 0.1.3 → 0.1.5
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.en.md +179 -0
- package/README.md +14 -4
- package/assets/hero.en.png +0 -0
- package/assets/hero.zh.png +0 -0
- package/docs/adr/0008-/347/213/254/347/253/213/346/250/241/345/274/217send/346/214/211/344/274/232/350/257/235/345/272/217/345/217/267/346/212/225/351/200/222.md +31 -0
- package/docs/adr/0009-/347/213/254/347/253/213/346/250/241/345/274/217switch/345/210/207/346/215/242/345/271/266/346/240/207/350/256/260/345/233/236/345/244/215/346/235/245/346/272/220.md +38 -0
- package/docs/adr/0010-/347/213/254/347/253/213/346/250/241/345/274/217/345/211/215/345/217/260/344/274/232/350/257/235/344/270/216switch-0.md +27 -0
- package/docs/adr/README.md +3 -0
- package/lib/client.js +2 -2
- package/lib/src/host/approvals.js +3 -3
- package/lib/src/host/bridge.js +38 -2
- package/lib/src/host/claim.js +1 -0
- package/lib/src/host/done-align.js +32 -0
- package/lib/src/host/inbound-pipeline.js +28 -48
- package/lib/src/host/index.js +13 -4
- package/lib/src/host/long-tasks.js +1 -1
- package/lib/src/host/prompt-content.js +21 -0
- package/lib/src/host/questions.js +6 -4
- package/lib/src/host/reactions.js +15 -0
- package/lib/src/host/reminders.js +10 -4
- package/lib/src/host/session-list.js +164 -0
- package/lib/src/host/session-text.js +22 -0
- package/lib/src/host/session-watch.js +194 -0
- package/lib/src/host/stack.js +22 -1
- package/lib/src/host/standalone-command.js +74 -0
- package/lib/src/host/standalone-send.js +97 -0
- package/lib/src/host/standalone-sessions.js +41 -0
- package/lib/src/host/standalone-switch.js +133 -0
- package/lib/src/host/standalone-types.js +7 -0
- package/lib/src/host/standalone.js +143 -135
- package/lib/src/host/state/direct.js +84 -13
- package/lib/src/host/state/files.js +2 -1
- package/lib/src/host/state/listing.js +65 -0
- package/lib/src/shared/version.js +1 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -1
package/README.en.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# dsh-im-lark
|
|
2
|
+
|
|
3
|
+
[简体中文](README.md) · **English**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Connect a Feishu / Lark bot to DeepSeek Harness: DM the bot in Feishu and it is the same as chatting in the Web UI.
|
|
8
|
+
|
|
9
|
+
Two independent modes:
|
|
10
|
+
|
|
11
|
+
| Mode | Switch | Needs the core | Behaviour |
|
|
12
|
+
| --- | --- | --- | --- |
|
|
13
|
+
| **Standalone** (default) | Connect Feishu, turn off "Use my super agent" | No | The plugin creates its own session and you chat in Feishu directly; text commands, question and approval reminders are handled by the plugin |
|
|
14
|
+
| **Core** | Connect Feishu + Use my super agent | Yes | Feishu becomes another entry point to the Web UI: messages, commands and reminders all go to the core |
|
|
15
|
+
|
|
16
|
+
The two modes are mutually exclusive: the core is used only when "Use my super agent" is on and the core service is running; otherwise everything stays standalone, so a message is never handled twice. The core switch on the panel is disabled when the core is not installed.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Inbound**: text, rich text, images, files; voice, video and stickers get an explicit notice instead of being dropped silently
|
|
21
|
+
- **Outbound**: Markdown cards and images; long answers are split by both character count and card size limits
|
|
22
|
+
- **Quoted replies**: answers quote the message that triggered them, in DMs and groups alike
|
|
23
|
+
- **Processing feedback**: an incoming message gets a `Get` reaction first; `DONE` is added to the original message only after the answer is actually delivered, and the two stay side by side. Being queued is not completion (the core queues the message and runs the task asynchronously). In core mode the plugin follows the core's `completes` markers (stall notices, dispatch receipts and transfer confirmations never carry them; cancelled, failed, approval-rejected or token-limit-truncated rounds do not carry them either, because they have no normal answer; older cores do not send them at all). Standalone mode aligns reactions per turn, and reminder answers are marked at settlement time (when only some questions are answered the reminder is still waiting, so no `DONE`). On failure only `Get` remains — never a false "done". Each message is marked once. Feishu has no official "typing" API
|
|
24
|
+
- **Card updates**: streaming answers update the same card in place; after platform limits (14 days, 5 QPS per card) a new card is sent
|
|
25
|
+
- **Interactive cards**: in core mode, **single-question** single- and multi-select questions are answered in Feishu and the result is returned to the core; in standalone mode single questions are also sent as cards (single and multi select are both checkboxes, distinguished by copy, and must be submitted), everything else stays a text reminder. Multi-question and approval prompts are notice-only and must be answered in the Web UI (the core requires all questions in one submission, which card callbacks cannot do per question); both support an "other" input
|
|
26
|
+
- **Groups**: only messages that @mention the bot are handled (only the @-scoped group permissions are requested); the whole group is never read
|
|
27
|
+
- **Task reminders**: in standalone mode, a long turn (30 minutes by default) sends a reminder with elapsed time and conclusion when it ends; a failed or externally aborted turn is reported immediately with the original error. A stop pressed by the owner is not a failure
|
|
28
|
+
- **Panel**: create an app with one scan on the Web plugin page, or enter App ID / App Secret manually; see connection state, toggle send/receive and core mode, change message behaviour; in standalone mode, adjust in-turn steering, session workspace, question/approval reminders and long-task reminders
|
|
29
|
+
|
|
30
|
+
> Question cards (checkboxes + submit + "other" input) have been verified in a real Feishu tenant in both standalone and core mode: single and multi select are distinguished by card copy, and a submission returns the checked options plus the "other" input. Rejected answers give visible feedback in both modes: a card that can still be answered is **re-rendered whole** with the reason (Feishu form submissions are one-shot; a text-only hint would leave the card unclickable) so you can re-select and submit; a card that can no longer be answered becomes invalid and loses its checkboxes. `Get` / `DONE` reactions and card layout vary slightly with tenant settings; what you see is what the platform does.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
Stable releases go to `latest`, prereleases to channel tags (`stage` / `rc`); they never overwrite each other:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# stable
|
|
38
|
+
dsh plugin --profile web add dsh-im-lark
|
|
39
|
+
|
|
40
|
+
# prerelease
|
|
41
|
+
dsh plugin --profile web add dsh-im-lark@stage
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
From source (development):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install
|
|
48
|
+
npm run build
|
|
49
|
+
dsh plugin --profile web add file:/absolute/path/dsh-im-lark
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A `file:` dependency is an **injected copy**: once installed into the profile's `node_modules` it is decoupled from the repo. After changing code run `npm run build`, then remove and re-add to sync the running host.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
dsh plugin --profile web remove dsh-im-lark
|
|
56
|
+
dsh plugin --profile web add file:/absolute/path/dsh-im-lark
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
No need to restart `dsh web` after reinstalling: the host half is hot-reloaded, so just refresh the browser. Open **Settings → Lark Bot** (or **Plugins → dsh-im-lark**) to enter credentials.
|
|
60
|
+
|
|
61
|
+
### Create an app by QR code
|
|
62
|
+
|
|
63
|
+
On the panel, under "App credentials", click "Create app by QR code", scan the QR code with Feishu and confirm on your phone. Credentials are saved and the connection starts automatically; the QR code is valid for 1 hour and can be used by one user only.
|
|
64
|
+
|
|
65
|
+
The created app still needs its permissions and event subscriptions confirmed (next section). If the long connection never receives messages, first check that "Event subscriptions" uses the **long connection** mode and that `im.message.receive_v1` is subscribed.
|
|
66
|
+
|
|
67
|
+
## Feishu setup
|
|
68
|
+
|
|
69
|
+
1. Create an **enterprise self-built app** on the [Feishu Open Platform](https://open.feishu.cn/app) and copy its App ID and App Secret.
|
|
70
|
+
2. **Add app capability → Bot**.
|
|
71
|
+
3. Under **Permissions**, enable:
|
|
72
|
+
- `im:message.p2p_msg:readonly` (receive DM messages)
|
|
73
|
+
- `im:message.group_at_msg:readonly` (receive group messages that @mention the bot)
|
|
74
|
+
- `im:message:send_as_bot` (send messages as the bot)
|
|
75
|
+
- `im:resource` (upload/download images and files)
|
|
76
|
+
- Reaction permissions (optional): the reaction-related scopes in the console. Missing them does not break the main flow; the "processing" hint degrades to not being sent
|
|
77
|
+
4. **Events & callbacks**:
|
|
78
|
+
- "Event subscriptions": choose the **long connection** mode and subscribe to `im.message.receive_v1`;
|
|
79
|
+
- "Callback configuration": add `card.action.trigger` (needed for card interactions), also over the long connection
|
|
80
|
+
5. **Publish a version** and wait for admin approval; before publishing only the developer can use it.
|
|
81
|
+
|
|
82
|
+
> Long-connection mode needs no public URL and no request URL. Each app allows up to 50 long connections; with multiple instances **only one** connection receives events, so do not scale horizontally by running several processes.
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
Static config lives in the profile patch; restart to apply:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
- id: dsh-im-lark
|
|
90
|
+
name: dsh-im-lark
|
|
91
|
+
config:
|
|
92
|
+
domain: feishu # feishu (default) or lark (international)
|
|
93
|
+
maxText: 2000 # max characters per message; longer text is split automatically
|
|
94
|
+
typingIndicator: true # Get on receipt; DONE on the original message after delivery (Get is never removed)
|
|
95
|
+
replyStatus: false # append model, elapsed time and tokens to the answer
|
|
96
|
+
directBusyMode: steer # a message arriving mid-turn in standalone mode: steer / queue (legacy interrupt migrates to steer)
|
|
97
|
+
directWorkspaceId: '' # workspace id for standalone sessions; empty uses the auto-created default
|
|
98
|
+
questionReminders: true # standalone: send a Feishu reminder when a question or approval is waiting
|
|
99
|
+
questionDelayMinutes: 5 # how long to wait before reminding (0–120): answering in the Web UI within this window avoids it
|
|
100
|
+
longTaskReminders: true # standalone: send a completion reminder when a turn exceeds the threshold
|
|
101
|
+
longTaskMinutes: 30 # long-task threshold (1–1440 minutes)
|
|
102
|
+
failureReminders: true # standalone: report a failed or externally aborted turn immediately
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Items editable in the panel are written to `$DSH_HOME/.dsh-im-lark/config.json` and survive a reinstall. Credentials live in `credentials.json` (directory 0700, file 0600); logs and errors only ever show the last six characters of the App ID. The panel shows the full App ID and binding time; the Secret is never echoed.
|
|
106
|
+
|
|
107
|
+
## Standalone commands
|
|
108
|
+
|
|
109
|
+
| Command | Effect |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `/help` | List commands |
|
|
112
|
+
| `/new` | Start a new session |
|
|
113
|
+
| `/sessions [page]` | List recent sessions and their numbers (excluding the front session), 10 per page |
|
|
114
|
+
| `/switch <index, 0, front, or session id>` | Switch the current session; `0` and `front` return to the front session |
|
|
115
|
+
| `/status` | Current session and runtime state |
|
|
116
|
+
| `/stop` | Abort the running turn |
|
|
117
|
+
| `/trace` | Model and elapsed time of the last answer |
|
|
118
|
+
| `/send <index, 0, or session id> <text>` | Send to that session; its answer comes back here. `0` is the front session. Images allowed |
|
|
119
|
+
|
|
120
|
+
`/send` is queued, so it does not interrupt the target session's running turn; sending to the current session behaves like a normal message. A `/switch` binding and its prefix survive restarts and are cleared by `/new`; after switching to a non-front session, replies are prefixed with `**session name>**`, and returning to the front session (index `0`) drops it. The front session is always index `0` and is omitted from `/sessions`, so returning to it does not produce a self-referential list. Switching is refused while that session still has a `/send` waiting for its answer. If an older `direct.json` has no front-session record, `/switch 0` asks you to start a new session with `/new`.
|
|
121
|
+
|
|
122
|
+
## CLI and slash command
|
|
123
|
+
|
|
124
|
+
- **`/lark`** (Web input box): `/lark <text>` sends a piece of text to your own Feishu; `/lark status` shows whether credentials and the recipient are ready. No model involved.
|
|
125
|
+
- **`dsh-lark-send`** (terminal / scripts): `dsh-lark-send text <text>`, `status`, `help`. The recipient is always the owner and there is no `--to`; exit codes `0` success, `1` send failure, `2` bad arguments.
|
|
126
|
+
|
|
127
|
+
The recipient is always the "owner": in standalone mode the first person who DMs the bot in Feishu, in core mode the user bound by the core. With no owner yet it reports an explicit error.
|
|
128
|
+
|
|
129
|
+
## Scope notes
|
|
130
|
+
|
|
131
|
+
- Standalone: while a question or tool approval is waiting for the owner, the plugin sends a Feishu reminder (delay configurable): single questions with options are answered by tapping the card; multi-question, approval and free-form input still use text (reply with a number or the option text). Long-task completion reminders remain the core's job.
|
|
132
|
+
- Standalone: received files only get a notice; their contents are not fed into the session. Images are attached as input.
|
|
133
|
+
- In core mode `DONE` first translates the inbound `messageId` from the core into a platform message id; that table keeps only the latest 500 entries (bounded to avoid unbounded memory): after a plugin restart, or when a message is reported complete more than 500 inbound messages later, the id cannot be resolved and no `DONE` is added — this only affects the completion reaction, never answer delivery.
|
|
134
|
+
- IM cards only carry single-question, option-based interactions; multi-question, approval and free-form input go back to the Web UI, avoiding cards that look clickable but can never be completed.
|
|
135
|
+
|
|
136
|
+
## Limits (platform-determined, not implementation choices)
|
|
137
|
+
|
|
138
|
+
- Event handling must return within **3 seconds**; heavy work is always done asynchronously
|
|
139
|
+
- Text message body ≤ 150 KB, card ≤ 30 KB; the platform rejects anything larger
|
|
140
|
+
- 5 QPS for sending (per user / per group); the plugin rate-limits and backs off internally
|
|
141
|
+
- A card can be PATCHed for 14 days at 5 QPS per card; after that a new message is sent
|
|
142
|
+
- Images ≤ 10 MB, files ≤ 30 MB; checked locally before upload
|
|
143
|
+
- Message editing has a count limit, and the recall window is set by the admin (commonly 24 hours)
|
|
144
|
+
- No official "typing" API, so reactions are the only weak hint
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
npm run typecheck # type check (test files included)
|
|
150
|
+
npm test # unit tests
|
|
151
|
+
npm run build # tsc for the host + esbuild bundle for the client
|
|
152
|
+
npm run verify # verify artifacts, dependency allowlist, insert-only patch
|
|
153
|
+
npm run check # all four above
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Layout:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
index.ts entry, re-exports src/host/index.ts
|
|
160
|
+
src/host/ host side: connection, inbound, outbound, cards, bridge, standalone sessions, panel RPC
|
|
161
|
+
src/client/ Web panel (React, bundled into lib/client.js)
|
|
162
|
+
src/shared/ constants and version shared by both sides
|
|
163
|
+
locale/ panel copy
|
|
164
|
+
docs/design/ design document
|
|
165
|
+
docs/protocol/ Feishu open-platform facts (with source links)
|
|
166
|
+
docs/adr/ architecture decision records
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Read `AGENTS.md` before changing code (file size, log redaction, no new dependencies, and other hard rules).
|
|
170
|
+
|
|
171
|
+
### Gate and release
|
|
172
|
+
|
|
173
|
+
`npm run check` is the full local gate and the tests are self-contained: they do not depend on the private `dsh-my-superagent` core, and public CI runs the same set.
|
|
174
|
+
|
|
175
|
+
Releases are handled by `.github/workflows/release.yml` on main ([ADR-0007](docs/adr/0007-发布流程与版本通道.md)): the version is kept in sync in three places (`package.json`, the lock file, `src/shared/version.ts`), stable release notes live in `docs/releases/v<version>.md`, prereleases skip `docs/releases/` and get their notes generated by the workflow. A push to main tags, publishes to npm and creates the Release automatically: prereleases only go to npm channel tags (`stage` / `rc`), `latest` is reserved for stable releases.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# dsh-im-lark
|
|
2
2
|
|
|
3
|
+
**简体中文** · [English](README.en.md)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
3
7
|
把飞书 / Lark 机器人接到 DeepSeek Harness:在飞书里私聊机器人,等于在 Web 端对话。
|
|
4
8
|
|
|
5
9
|
两条互相独立的使用路径:
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
- **入站**:文本、富文本、图片、文件;语音/视频/表情包等给一句明确提示,不静默丢弃
|
|
18
22
|
- **出站**:Markdown 卡片、图片;长回答按字符与卡片体积双上限切段
|
|
19
23
|
- **引用回复**:回答引用触发它的那条消息,单聊与群里都成立
|
|
20
|
-
- **处理反馈**:收到消息先打 `Get
|
|
24
|
+
- **处理反馈**:收到消息先打 `Get`(收到)表情,**回答真正送达后**才在原消息追加 `DONE`,两个标记并排保留——入队不算完成(核心把消息入队后任务才异步跑);核心模式按核心的 `completes` 完成标记打(停滞、派发回执、转投确认等都不带;取消、失败、审批被拒、超出 token 上限而中断的回合也不带,因为它们没有正常答复;旧核心不打),独立模式按回合对齐,提醒作答在**结算**后当场打(多题只答一半时提醒还在等,不盖 `DONE`);失败只保留 `Get`,不留「已完成」的假信号;同一消息只补一次。飞书没有官方「正在输入」接口
|
|
21
25
|
- **卡片更新**:流式回答原地更新同一张卡片;超过平台限制(14 天、单卡 5 QPS)后改发新卡
|
|
22
26
|
- **交互卡片**:核心模式的**单问题**单选题与多选题在飞书里勾选后提交,结果交回核心;
|
|
23
27
|
独立模式的单题提问同样发卡片(单选/多选都是勾选器,靠文案区分,必须点提交),其余仍走
|
|
@@ -98,7 +102,7 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
98
102
|
config:
|
|
99
103
|
domain: feishu # feishu(默认)或 lark(国际版)
|
|
100
104
|
maxText: 2000 # 单条消息字符上限,超出自动切段
|
|
101
|
-
typingIndicator: true # 收到打 Get
|
|
105
|
+
typingIndicator: true # 收到打 Get;回答送达后原消息追加 DONE(Get 不撤)
|
|
102
106
|
replyStatus: false # 回答末尾附加模型、耗时、token
|
|
103
107
|
directBusyMode: steer # 独立会话里回合进行中又来消息:steer 插话 / queue 排队(旧值 interrupt 会迁移成 steer)
|
|
104
108
|
directWorkspaceId: '' # 独立会话的工作区 id;留空用自动创建的默认工作区
|
|
@@ -117,11 +121,14 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
117
121
|
| --- | --- |
|
|
118
122
|
| `/help` | 命令列表 |
|
|
119
123
|
| `/new` | 开新会话 |
|
|
120
|
-
| `/sessions` |
|
|
124
|
+
| `/sessions [页码]` | 列出最近会话与序号(不含前台会话),每页 10 个 |
|
|
125
|
+
| `/switch <序号、0、front 或会话 id>` | 切换当前会话;`0` 与 `front` 回到前台会话 |
|
|
121
126
|
| `/status` | 当前会话与运行状态 |
|
|
122
127
|
| `/stop` | 中止正在跑的回合 |
|
|
123
128
|
| `/trace` | 查看上一条回答的模型与耗时 |
|
|
124
|
-
| `/send
|
|
129
|
+
| `/send <序号、0 或会话 id> <内容>` | 发到指定会话,那一轮的回答回到这里;`0` 是前台会话;可附图 |
|
|
130
|
+
|
|
131
|
+
`/send` 用排队提交,不打断目标会话正在跑的回合;目标是当前会话时与直接发消息一致。`/switch` 的换绑与前缀会跨重启保留,`/new` 会清掉;切到非前台会话后,回复前会加 `**会话名>**`,切回前台(序号 `0`)后前缀消失。前台会话固定为序号 `0`,不出现在 `/sessions` 里,避免回到前台后列表里又套一个自己。目标会话还有 `/send` 在等回答时不允许切换。旧版 `direct.json` 没有前台记录时,`/switch 0` 会提示用 `/new` 重新建会话。
|
|
125
132
|
|
|
126
133
|
## 命令行与斜杠命令
|
|
127
134
|
|
|
@@ -137,6 +144,9 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
137
144
|
- 独立模式:问题与工具授权在等主人时,插件发飞书提醒(延迟可调):单题有选项的直接
|
|
138
145
|
点卡片作答,多题/审批/自由输入仍用文字(回序号或选项文字)。长任务完成提醒仍由核心负责。
|
|
139
146
|
- 独立模式收到文件只给一句提示,不把文件内容送进会话;图片会作为输入附上。
|
|
147
|
+
- 核心模式的 `DONE` 要先把握手的入站 `messageId` 翻成平台消息 id,这张表只留最近 500 条
|
|
148
|
+
(有界,防常驻内存增长):插件重启后,或一条消息在 500 条之后才被核心报完成,
|
|
149
|
+
就翻不到平台 id、不打 `DONE`——只影响完成表情,不影响答案送达。
|
|
140
150
|
- IM 卡片只承载单问题、有选项的交互;多问题/审批/自由输入交回 Web 端,避免出现
|
|
141
151
|
「点了按钮但永远答不完」的卡。
|
|
142
152
|
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 0008 独立模式 /send 按会话序号投递
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
独立模式最初的 `/send <文本>` 只是把文本回显到当前聊天,与核心模式的
|
|
6
|
+
`/send <序号或会话 id> <内容>` 同名不同义;`/sessions` 又用序号来切换绑定会话,
|
|
7
|
+
无法向其它会话发消息。主人要接着某个旧会话说话,只能先切换,回答也只会回到
|
|
8
|
+
切换后的绑定会话。
|
|
9
|
+
|
|
10
|
+
## 决策
|
|
11
|
+
|
|
12
|
+
- `/sessions [页码]` 只列会话(每页 10 个),每次列出一份新快照并落盘 `sessions.json`,
|
|
13
|
+
序号在下次 `/sessions` 之前不变;不再切换绑定。
|
|
14
|
+
- `/send <序号或会话 id> <内容>` 用 `queue` 提交到目标会话,登记观察者等它 `turn/end`,
|
|
15
|
+
把最后一条 assistant 文本发回发起命令的聊天;命令消息的 `DONE` 等回答真正送达后再补。
|
|
16
|
+
- 目标是当前绑定会话时走普通提交流程,不另开观察者,避免同一轮发两份回答。
|
|
17
|
+
- 目标会话正在跑时,先到的 `turn/end` 属于上一轮,跳过;30 分钟没结束就不再等并回一条提示。
|
|
18
|
+
- 序号快照按 `$DSH_HOME/.dsh-im-lark/` 下的私密文件保存(`sessions.json`)。
|
|
19
|
+
|
|
20
|
+
## 后果
|
|
21
|
+
|
|
22
|
+
- `/sessions <序号>` 不再切换会话;要接着某个旧会话说话用 `/send <序号> <内容>`。
|
|
23
|
+
- `/send` 从自测命令变成真正的跨会话投递;内容按原文提交,不再压平换行。
|
|
24
|
+
- `/stop` 仍只停当前绑定会话,不能停 `/send` 的目标会话;需要时再扩展。
|
|
25
|
+
- `/trace` 仍是「上一条回答的模型与耗时」,没有跟随核心的跟踪语义。
|
|
26
|
+
|
|
27
|
+
## 备选
|
|
28
|
+
|
|
29
|
+
- 保留回显、改名为 `/echo`:只能自测,不解决与核心同名不同义的问题。
|
|
30
|
+
- 只发不回收回答:与核心「结果回到这里」的语义不一致,主人还得去 Web 端看结果。
|
|
31
|
+
- 让 `/sessions <序号>` 同时切换并复用编号:一个参数两种含义,容易误操作,未采用。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 0009 独立模式 /switch 切换会话并标记回复来源
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
0008 把 `/sessions` 收成只读列表、`/send` 做跨会话投递后,独立模式没有「换一个
|
|
6
|
+
会话接着聊」的命令:每次都要 `/send <序号> <内容>`,回答虽然回到当前聊天,但下一句
|
|
7
|
+
又落回原来的绑定会话。主人同时跟进几个会话时,也看不出某条回答来自哪个会话。
|
|
8
|
+
|
|
9
|
+
## 决策
|
|
10
|
+
|
|
11
|
+
- `/switch <序号或会话 id>` 复用 `/sessions` 的快照与 `resolveSessionRef`,按序号或
|
|
12
|
+
id 前缀换绑;序号仍只在下次 `/sessions` 时更新。
|
|
13
|
+
- 换绑到其它会话时清空 `DoneAlign`、复位运行态:旧会话的 `turn/end` 会被绑定校验
|
|
14
|
+
丢弃,残留的待结算条目只会被新会话的回合错认。切到当前会话没有换绑,不清队列。
|
|
15
|
+
- 目标会话还有 `/send` 在等回答时拒绝切换,避免同一轮出现两条投递路径;目标已不在
|
|
16
|
+
当前会话列表里时也拒绝,提示重新 `/sessions`。
|
|
17
|
+
- 换绑后,绑定会话路径的每条回复前加 `**会话名>**`;`/send` 的回答已有
|
|
18
|
+
`来自会话「X」:`,不再重复加前缀。
|
|
19
|
+
- 标记以 `switched: true` 落盘在 `direct.json`,跨重启保留;`/new` 清除绑定即清除
|
|
20
|
+
前缀。`session/title` 事件只在绑定仍指向该会话时更新当前标题,避免切走后改错名字;
|
|
21
|
+
0010 起另记前台会话的标题,切走后前台改名也会跟上。
|
|
22
|
+
- 标题压平空白、截断到 32 字符,并转义会打断 `**…**` 的 Markdown 字符;没有标题时
|
|
23
|
+
用「未命名会话」。
|
|
24
|
+
|
|
25
|
+
## 后果
|
|
26
|
+
|
|
27
|
+
- `/sessions` 保持只读;切换是显式命令,不再靠序号命令兼做两件事。
|
|
28
|
+
- 前缀只影响发回飞书的显示,不写进会话内容,也不改变模型看到的输入。
|
|
29
|
+
- 宿主不推 `session/title` 时前缀可能停留在旧标题;标题缺失时显示「未命名会话」。
|
|
30
|
+
- `/switch` 只换绑定,不会停止旧会话正在跑的回合;旧回合的回答不再发到飞书,需要时
|
|
31
|
+
到 Web 端查看。
|
|
32
|
+
|
|
33
|
+
## 备选
|
|
34
|
+
|
|
35
|
+
- 让 `/sessions <序号>` 同时切换:与 0008 的只读快照冲突,一个参数两种含义,未采用。
|
|
36
|
+
- 所有独立模式回复都加前缀(含 `/send` 回答):与「来自会话」重复,也分不清回答归属,
|
|
37
|
+
未采用。
|
|
38
|
+
- 前缀只放内存:重启后主人又失去会话标识,与「跨重启保留」的目标不符。
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 0010 独立模式的前台会话与 /switch 0
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
0009 加了 `/switch`,但「最初绑定的会话」只是 `direct.json` 里的 `sessionId`,没有单独的名字。切到别的会话后,`/sessions` 会把原会话当成普通一行列出来;切回去后它仍是当前会话,列表里继续列着它自己,形成「回到前台再列会话,又看到前台」的套娃。另外也没有稳定的返回路径:只能从列表里按序号找,列表一变就找不到了。
|
|
6
|
+
|
|
7
|
+
## 决策
|
|
8
|
+
|
|
9
|
+
- 在 `direct.json` 里单独记前台:`frontSessionId` 与 `frontTitle`。旧版没有这两个字段时,未切换过的绑定按前台迁移;已经切走又没有前台记录的,`/switch 0` 与 `/send 0` 明确提示用 `/new` 重建。
|
|
10
|
+
- 前台固定为序号 `0`,别名 `0` 与 `front`(大小写不敏感),`/switch` 与 `/send` 都认。`/sessions` 的快照和显示都排除前台,序号只对应其它会话,避免切回前台后列表里再套一个自己;精确的前台会话 id 也按回前台处理。
|
|
11
|
+
- `/switch 0`/`front` 回到前台时不写 `switched`,回复前缀随之消失;切到非前台会话才写 `switched: true`。`/new` 清掉绑定,也清掉前台。
|
|
12
|
+
- 切走期间收到前台会话的 `session/title` 时更新 `frontTitle`;回到前台时优先用列表里的最新标题,列表没给才用记住的标题。
|
|
13
|
+
- 换到其它会话(含回到前台)清空 `DoneAlign` 并复位运行态;切到当前会话不清。目标还有 `/send` 在等回答时拒绝切换,前台也一样。
|
|
14
|
+
- `DirectBindingStore` 的状态变更统一走 `update` 队列(读改写):标题事件与 `/switch` 交错时,后执行的变更总能读到前一次的结果,不会用旧快照覆盖新标题;首次读盘 single-flight;临时文件名加随机 UUID,避免同毫秒 rename 互相踩。
|
|
15
|
+
|
|
16
|
+
## 后果
|
|
17
|
+
|
|
18
|
+
- 任何时候都能用 `/switch 0` 回到最初会话,不依赖 `/sessions` 快照是否还包含它。
|
|
19
|
+
- 前台不再出现在 `/sessions` 里,序号与切换目标一一对应;代价是不能用列表序号指前台,只能用 `0`/`front`。
|
|
20
|
+
- 前台会话被删掉后,`/switch 0` 与 `/send 0` 会明确提示,需要 `/new` 或先切到其它会话。
|
|
21
|
+
- 旧 `direct.json` 仍可读:未切换过的绑定自动补前台字段;已切换但没记前台的,升级后第一次 `/switch 0` 会提示没有前台,需要 `/new` 重新建一个;`/sessions` 只能换到其它会话,不会补前台。
|
|
22
|
+
|
|
23
|
+
## 备选
|
|
24
|
+
|
|
25
|
+
- 前台继续留在 `/sessions` 里,用 `*` 标出:切回前台后列表仍包含当前会话,序号和「当前」标记容易绕,未采用。
|
|
26
|
+
- 用 `/switch -1` 表示前台:负数不如 `0` 直观,也不方便和 `/send` 共用参数解析,未采用。
|
|
27
|
+
- 前台只放内存:重启后丢失,回到前台又得重新找,未采用。
|
package/docs/adr/README.md
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
| [0005](0005-独立模式问题与审批提醒.md) | 独立模式接管问题与审批提醒,与 Web 竞答 | 已接受 |
|
|
13
13
|
| [0006](0006-长程任务与失败任务提醒.md) | 独立模式发长程任务完成与失败提醒 | 已接受 |
|
|
14
14
|
| [0007](0007-发布流程与版本通道.md) | 发布走 CI,预发布进 npm 频道标签 | 已接受 |
|
|
15
|
+
| [0008](0008-独立模式send按会话序号投递.md) | 独立模式 `/send` 按会话序号投递 | 已接受 |
|
|
16
|
+
| [0009](0009-独立模式switch切换并标记回复来源.md) | 独立模式 `/switch` 切换会话并标记回复来源 | 已接受 |
|
|
17
|
+
| [0010](0010-独立模式前台会话与switch-0.md) | 独立模式的前台会话与 `/switch 0` | 已接受 |
|
|
15
18
|
|
|
16
19
|
新增决策时:编号连续、标题用「做了什么」而不是「为什么」、状态只有
|
|
17
20
|
`提议 / 已接受 / 已废弃 / 被 NNNN 取代`。改主意不要改旧 ADR 的结论,追加新的一条
|
package/lib/client.js
CHANGED
|
@@ -131,7 +131,7 @@ var en_default = {
|
|
|
131
131
|
"register.failed": "Failed to create the app. Please retry.",
|
|
132
132
|
"behavior.title": "Message behavior",
|
|
133
133
|
"behavior.typing": "Working / done reaction",
|
|
134
|
-
"behavior.typingHint": "Adds a Get (received) reaction on arrival, then appends DONE
|
|
134
|
+
"behavior.typingHint": "Adds a Get (received) reaction on arrival, then appends DONE to the original message only once the reply is actually delivered (queueing does not count); both stay on the message. Lark has no official typing API.",
|
|
135
135
|
"behavior.replyStatus": "Status line in replies",
|
|
136
136
|
"behavior.replyStatusHint": "Model, reasoning effort and duration.",
|
|
137
137
|
"common.save": "Save",
|
|
@@ -243,7 +243,7 @@ var zh_default = {
|
|
|
243
243
|
"register.failed": "\u521B\u5EFA\u5E94\u7528\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",
|
|
244
244
|
"behavior.title": "\u6D88\u606F\u884C\u4E3A",
|
|
245
245
|
"behavior.typing": "\u5904\u7406\u72B6\u6001\u8868\u60C5",
|
|
246
|
-
"behavior.typingHint": "\u6536\u5230\u6D88\u606F\u5148\u6253\u300C\u6536\u5230\u300D(Get)\uFF0C\
|
|
246
|
+
"behavior.typingHint": "\u6536\u5230\u6D88\u606F\u5148\u6253\u300C\u6536\u5230\u300D(Get)\uFF0C\u56DE\u7B54\u771F\u6B63\u9001\u8FBE\u540E\u624D\u5728\u539F\u6D88\u606F\u8FFD\u52A0 DONE\uFF08\u5165\u961F\u4E0D\u7B97\u5B8C\u6210\uFF09\uFF0C\u4E24\u4E2A\u90FD\u4FDD\u7559\u3002\u98DE\u4E66\u6CA1\u6709\u5B98\u65B9\u8F93\u5165\u72B6\u6001\u63A5\u53E3\u3002",
|
|
247
247
|
"behavior.replyStatus": "\u56DE\u590D\u672B\u5C3E\u663E\u793A\u72B6\u6001",
|
|
248
248
|
"behavior.replyStatusHint": "\u9644\u52A0\u6A21\u578B\u3001\u63A8\u7406\u7B49\u7EA7\u4E0E\u8017\u65F6\u3002",
|
|
249
249
|
"common.save": "\u4FDD\u5B58",
|
|
@@ -167,15 +167,15 @@ export class ApprovalBroker {
|
|
|
167
167
|
reply(text) {
|
|
168
168
|
const decision = parseDecision(text);
|
|
169
169
|
if (decision === null)
|
|
170
|
-
return
|
|
170
|
+
return undefined;
|
|
171
171
|
const pending = decision.no === undefined ? this.#pending.newest() : this.#byNo(decision.no);
|
|
172
172
|
if (pending === undefined)
|
|
173
|
-
return
|
|
173
|
+
return undefined;
|
|
174
174
|
pending.resolve(decision.outcome);
|
|
175
175
|
this.#pending.delete(pending.id);
|
|
176
176
|
// 回执尽力而为:不阻塞入站流水线,也不因为回执失败改变已经做出的决定。
|
|
177
177
|
void this.#options.send(receipt(pending, decision.outcome)).catch(() => { });
|
|
178
|
-
return
|
|
178
|
+
return 'settled';
|
|
179
179
|
}
|
|
180
180
|
/** 停机/停用:把等待中的审批交回 Web(不吞掉请求,也不把它变成拒绝)。 */
|
|
181
181
|
cancelAll(reason = '插件已停止') {
|
package/lib/src/host/bridge.js
CHANGED
|
@@ -93,12 +93,19 @@ export function createLarkBridge(deps) {
|
|
|
93
93
|
if (delivery.expiresAt !== undefined && delivery.expiresAt <= now()) {
|
|
94
94
|
return failure(deliveryId, 'window-closed', '交付已过期,未发送');
|
|
95
95
|
}
|
|
96
|
+
// 本次交付完成的原消息;只在平台确认发送/更新成功后打(判据见 completionTargets)。
|
|
97
|
+
const doneTargets = completionTargets(delivery);
|
|
98
|
+
const markDone = () => {
|
|
99
|
+
for (const target of doneTargets)
|
|
100
|
+
deps.markDone?.(target);
|
|
101
|
+
};
|
|
96
102
|
const stream = delivery.stream;
|
|
97
103
|
let streamOversized = false;
|
|
98
104
|
if (stream !== undefined) {
|
|
99
105
|
const detached = detachedStreams.get(stream.id);
|
|
100
|
-
if (detached !== undefined) {
|
|
101
|
-
//
|
|
106
|
+
if (detached !== undefined && stream.final !== true) {
|
|
107
|
+
// 这条流已经改用分条消息了:中间修订再发只会刷屏。
|
|
108
|
+
// 终稿不能在这里吞掉——它和中间修订内容不同,要往下走正常发送。
|
|
102
109
|
return { deliveryId, status: 'sent', bridgeMessageId: detached, messagesSent: 0 };
|
|
103
110
|
}
|
|
104
111
|
const current = streams.get(stream.id);
|
|
@@ -117,6 +124,7 @@ export function createLarkBridge(deps) {
|
|
|
117
124
|
try {
|
|
118
125
|
await deps.api.patchCard({ messageId: current.messageId, card });
|
|
119
126
|
remember(streams, stream.id, { revision: stream.revision, messageId: current.messageId }, MAX_DELIVERED);
|
|
127
|
+
markDone();
|
|
120
128
|
return { deliveryId, status: 'sent', bridgeMessageId: current.messageId, messagesSent: 0 };
|
|
121
129
|
}
|
|
122
130
|
catch (error) {
|
|
@@ -166,6 +174,8 @@ export function createLarkBridge(deps) {
|
|
|
166
174
|
...(receipt.error === undefined ? {} : { error: receipt.error }),
|
|
167
175
|
};
|
|
168
176
|
}
|
|
177
|
+
// 回答送达成功才补 DONE;发送失败只留「收到」,不给假信号。
|
|
178
|
+
markDone();
|
|
169
179
|
const messageId = receipt.messageIds[0];
|
|
170
180
|
if (messageId !== undefined) {
|
|
171
181
|
remember(delivered, deliveryId, { delivery, messageId }, MAX_DELIVERED);
|
|
@@ -209,6 +219,32 @@ export function createLarkBridge(deps) {
|
|
|
209
219
|
? { ...sent, error: '交互卡片超过平台上限,已降级为纯文本;请在 Web 端作答' }
|
|
210
220
|
: sent;
|
|
211
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* 这次交付完成了哪些原消息(平台侧消息 id)。
|
|
224
|
+
*
|
|
225
|
+
* 判据直接读核心的 `completes`(my-superagent#3):只有「该轮以 completed 结束 +
|
|
226
|
+
* 消息自己的 rpcId 在这轮里 + 这条交付送达」三条同时成立才会带,停滞提醒、重启孤儿、
|
|
227
|
+
* 派发回执、转投确认、命令回复都不带。**不再按 `refs`/标题猜**——那套启发式会误判:
|
|
228
|
+
* 派发恢复告知与转投确认带 refs 却任务未完(误打),前台会话收尾不带 refs 却是正常
|
|
229
|
+
* 回答(漏打)。
|
|
230
|
+
*
|
|
231
|
+
* 旧核心不发这个字段 → 空数组 → 不打完成标记(漏打优于误打)。一条交付可能完成多条
|
|
232
|
+
* 消息(宿主把连发的几条并成一轮),所以返回数组逐个打。
|
|
233
|
+
*/
|
|
234
|
+
function completionTargets(delivery) {
|
|
235
|
+
const targets = [];
|
|
236
|
+
for (const id of delivery.completes ?? []) {
|
|
237
|
+
// 核心给的是入站草稿的 messageId,要翻成平台消息 id;查不到就不打。
|
|
238
|
+
// 常见原因:插件重启后入站映射被淘汰(有界 FIFO)、核心契约漂移。留一条调试日志,
|
|
239
|
+
// 否则「少打了一个 DONE」在线上无从排查(不打对用户无害,但说不清为什么)。
|
|
240
|
+
const platformId = inbound.get(id);
|
|
241
|
+
if (platformId !== undefined)
|
|
242
|
+
targets.push(platformId);
|
|
243
|
+
else
|
|
244
|
+
logger.debug?.('完成标记找不到对应的平台消息,跳过', id);
|
|
245
|
+
}
|
|
246
|
+
return targets;
|
|
247
|
+
}
|
|
212
248
|
/** 核心传的是 sender/open_id;飞书发消息要 chat_id,用入站学到的映射翻译。 */
|
|
213
249
|
function chatOf(recipient) {
|
|
214
250
|
const learned = senderChats.get(recipient);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export class DoneAlign {
|
|
2
|
+
/** 已提交、尚无定论的消息,按提交顺序。 */
|
|
3
|
+
#pending = [];
|
|
4
|
+
/** 提交成功(已入会话)后登记。 */
|
|
5
|
+
push(messageId, mode) {
|
|
6
|
+
this.#pending.push({ messageId, mode });
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 一轮结束:出队本轮应答的消息(平台消息 id)。
|
|
10
|
+
* 交付失败时调用方仍要结算(这一轮已经消耗掉它们),只是不盖完成标记。
|
|
11
|
+
*/
|
|
12
|
+
settle() {
|
|
13
|
+
const head = this.#pending.shift();
|
|
14
|
+
if (head === undefined)
|
|
15
|
+
return [];
|
|
16
|
+
const settled = [head.messageId];
|
|
17
|
+
// 队头之后、连续提交的 steer 消息已被这一轮在步骤边界吸收。
|
|
18
|
+
while (this.#pending[0]?.mode === 'steer') {
|
|
19
|
+
const absorbed = this.#pending.shift();
|
|
20
|
+
if (absorbed !== undefined)
|
|
21
|
+
settled.push(absorbed.messageId);
|
|
22
|
+
}
|
|
23
|
+
return settled;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 绑定会话换了(`/new`、`/switch`):旧会话的 `turn/end` 会被会话校验
|
|
27
|
+
* 丢弃,残留条目永远等不到自己的回合,只会被下一轮错认。整队清掉。
|
|
28
|
+
*/
|
|
29
|
+
clear() {
|
|
30
|
+
this.#pending.length = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -10,19 +10,10 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { MAX_FILE_BYTES, MAX_FILES_BYTES, MAX_IMAGE_BYTES, OWNER_FILES_MAX, OWNER_IMAGES_MAX } from "../shared/limits.js";
|
|
12
12
|
import { parseCardAction, parseMessageEvent } from "./inbound.js";
|
|
13
|
+
import { addReaction, REACTION_ACK } from "./reactions.js";
|
|
13
14
|
import { SeenStore } from "./state/seen.js";
|
|
14
15
|
const TEXT_MAX = 20_000;
|
|
15
|
-
/**
|
|
16
|
-
* 消息上的处理状态标记,走官方「添加消息表情回复」接口的 `emoji_type`。
|
|
17
|
-
*
|
|
18
|
-
* - `Get`:收到消息就打上(官方表情表里「已收到/已受理」语义的那个);
|
|
19
|
-
* - `DONE`:处理完成后**追加**,`Get` 不撤,两个标记并排留在消息上。
|
|
20
|
-
*
|
|
21
|
-
* 第一个标记永不撤销——它只表示「收到过」,失败时也成立;只有成功处理完
|
|
22
|
-
* 才追加 `DONE`,失败不给「已完成」的假信号。
|
|
23
|
-
*/
|
|
24
|
-
const REACTION_ACK = 'Get';
|
|
25
|
-
const REACTION_DONE = 'DONE';
|
|
16
|
+
/** 图片类型白名单:只有这几种能当 `image` 交给核心。 */
|
|
26
17
|
const KNOWN_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
|
|
27
18
|
/** 卡片回调的重推窗口:没有 `event_id` 时用它兜住平台重推,窗口之外允许同一张卡再提交。 */
|
|
28
19
|
const CARD_RETRY_WINDOW_MS = 5_000;
|
|
@@ -39,6 +30,7 @@ export class InboundPipeline {
|
|
|
39
30
|
#onOwner;
|
|
40
31
|
#now;
|
|
41
32
|
#claim;
|
|
33
|
+
#markDone;
|
|
42
34
|
#claimCard;
|
|
43
35
|
#fallback;
|
|
44
36
|
#chain = Promise.resolve();
|
|
@@ -55,6 +47,7 @@ export class InboundPipeline {
|
|
|
55
47
|
this.#onOwner = options.onOwner;
|
|
56
48
|
this.#now = options.now ?? Date.now;
|
|
57
49
|
this.#claim = options.claim;
|
|
50
|
+
this.#markDone = options.markDone;
|
|
58
51
|
this.#claimCard = options.claimCard;
|
|
59
52
|
this.#fallback = options.fallback;
|
|
60
53
|
}
|
|
@@ -135,47 +128,34 @@ export class InboundPipeline {
|
|
|
135
128
|
this.#logger.warn?.('入站处理失败', error instanceof Error ? error.message : String(error));
|
|
136
129
|
});
|
|
137
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* 入站只负责「收到」标记(`Get`,取值与打点约定见 `reactions.ts`)。
|
|
133
|
+
* `DONE` 不在这里打:`receive` 返回 accepted 只代表消息入队,任务是之后异步跑的
|
|
134
|
+
* (核心 emit 事件即返回、独立模式提交即返回),入队就打会给「已完成」的假信号。
|
|
135
|
+
* 完成标记在回答真正送达时补(bridge 的交付路径、独立模式的回合结束),
|
|
136
|
+
* 唯一例外是提醒作答:只有**结算成功**时当场打,没答完(`unsettled`)不打。
|
|
137
|
+
*/
|
|
138
138
|
async #processMessage(message, body) {
|
|
139
139
|
if (this.#typing)
|
|
140
|
-
await this.#
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
settled = true;
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const result = await this.#bridge.receive(draft);
|
|
156
|
-
if (!result.accepted && result.reason === 'unknown' && this.#fallback !== undefined) {
|
|
157
|
-
await this.#fallback(message, draft);
|
|
158
|
-
}
|
|
159
|
-
else if (!result.accepted) {
|
|
160
|
-
this.#logger.debug?.('消息未被核心接受', `${result.reason} ${result.detail ?? ''}`);
|
|
161
|
-
}
|
|
162
|
-
settled = true;
|
|
163
|
-
}
|
|
164
|
-
finally {
|
|
165
|
-
// 「收到」标记不撤:它只表示消息已受理,成功与失败都留着。
|
|
166
|
-
if (settled && this.#typing)
|
|
167
|
-
await this.#addReaction(message.messageId, REACTION_DONE);
|
|
140
|
+
await addReaction(this.#api, message.messageId, REACTION_ACK);
|
|
141
|
+
const draft = await this.#toDraft(message, body);
|
|
142
|
+
if (draft === null)
|
|
143
|
+
return;
|
|
144
|
+
// 提醒的作答先于一切:主人回「批准」「2」时不该把它当聊天送进会话。
|
|
145
|
+
// 只有**已结算**的作答当场补完成标记;多题只答一半时提醒还在等(回了格式提示),
|
|
146
|
+
// 那条消息不算处理完,不能盖 DONE。普通消息的完成标记由回答送达时补。
|
|
147
|
+
const claim = this.#claim?.(draft);
|
|
148
|
+
if (claim !== undefined) {
|
|
149
|
+
if (claim === 'settled')
|
|
150
|
+
this.#markDone?.(message.messageId);
|
|
151
|
+
return;
|
|
168
152
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
const result = await this.#api.addReaction({ messageId, emojiType });
|
|
174
|
-
return result.reactionId;
|
|
153
|
+
const result = await this.#bridge.receive(draft);
|
|
154
|
+
if (!result.accepted && result.reason === 'unknown' && this.#fallback !== undefined) {
|
|
155
|
+
await this.#fallback(message, draft);
|
|
175
156
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return undefined;
|
|
157
|
+
else if (!result.accepted) {
|
|
158
|
+
this.#logger.debug?.('消息未被核心接受', `${result.reason} ${result.detail ?? ''}`);
|
|
179
159
|
}
|
|
180
160
|
}
|
|
181
161
|
/** 事件 → 协议草稿;媒体下载失败时降级成文字说明,不让整条消息丢掉。 */
|