dsh-im-lark 0.1.4 → 0.1.6
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 +7 -3
- package/README.md +7 -3
- 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 +33 -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/0011-/347/213/254/347/253/213/346/250/241/345/274/217send/351/201/265/345/276/252/346/217/222/350/257/235/350/256/276/347/275/256/344/270/216queue/345/221/275/344/273/244.md +29 -0
- package/docs/adr/README.md +4 -0
- package/lib/client.js +2 -2
- package/lib/src/host/config.js +1 -1
- package/lib/src/host/done-align.js +28 -11
- package/lib/src/host/index.js +3 -0
- package/lib/src/host/long-tasks.js +1 -1
- package/lib/src/host/prompt-content.js +21 -0
- package/lib/src/host/session-list.js +165 -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 +4 -0
- package/lib/src/host/standalone-command.js +42 -14
- package/lib/src/host/standalone-send.js +111 -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 +123 -99
- 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 +1 -1
package/README.en.md
CHANGED
|
@@ -93,7 +93,7 @@ Static config lives in the profile patch; restart to apply:
|
|
|
93
93
|
maxText: 2000 # max characters per message; longer text is split automatically
|
|
94
94
|
typingIndicator: true # Get on receipt; DONE on the original message after delivery (Get is never removed)
|
|
95
95
|
replyStatus: false # append model, elapsed time and tokens to the answer
|
|
96
|
-
directBusyMode: steer #
|
|
96
|
+
directBusyMode: steer # all standalone sends while the target turn is running: steer / queue (legacy interrupt migrates to steer; /queue always queues)
|
|
97
97
|
directWorkspaceId: '' # workspace id for standalone sessions; empty uses the auto-created default
|
|
98
98
|
questionReminders: true # standalone: send a Feishu reminder when a question or approval is waiting
|
|
99
99
|
questionDelayMinutes: 5 # how long to wait before reminding (0–120): answering in the Web UI within this window avoids it
|
|
@@ -110,11 +110,15 @@ Items editable in the panel are written to `$DSH_HOME/.dsh-im-lark/config.json`
|
|
|
110
110
|
| --- | --- |
|
|
111
111
|
| `/help` | List commands |
|
|
112
112
|
| `/new` | Start a new session |
|
|
113
|
-
| `/sessions` | List recent sessions and
|
|
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 |
|
|
114
115
|
| `/status` | Current session and runtime state |
|
|
115
116
|
| `/stop` | Abort the running turn |
|
|
116
117
|
| `/trace` | Model and elapsed time of the last answer |
|
|
117
|
-
| `/send <text>` | Send
|
|
118
|
+
| `/send <index, 0, or session id> <text>` | Send to that session; its answer comes back here. `0` is the front session. Images allowed; mid-turn behavior follows the steer setting |
|
|
119
|
+
| `/queue <index, 0, or session id> <text>` | Same as `/send`, but always queues until the target's current turn ends |
|
|
120
|
+
|
|
121
|
+
`/send` behaves like a normal message: while the target session is running a turn, the panel's steer setting decides whether it joins that turn or queues. `/queue` takes the same arguments but always queues until the current turn ends, regardless of the setting. 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 a delivery is still 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`.
|
|
118
122
|
|
|
119
123
|
## CLI and slash command
|
|
120
124
|
|
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
104
104
|
maxText: 2000 # 单条消息字符上限,超出自动切段
|
|
105
105
|
typingIndicator: true # 收到打 Get;回答送达后原消息追加 DONE(Get 不撤)
|
|
106
106
|
replyStatus: false # 回答末尾附加模型、耗时、token
|
|
107
|
-
directBusyMode: steer #
|
|
107
|
+
directBusyMode: steer # 独立模式所有发送在目标回合进行中:steer 插话 / queue 排队(旧值 interrupt 迁移成 steer;/queue 固定排队)
|
|
108
108
|
directWorkspaceId: '' # 独立会话的工作区 id;留空用自动创建的默认工作区
|
|
109
109
|
questionReminders: true # 独立模式下有问题/授权在等时发飞书提醒
|
|
110
110
|
questionDelayMinutes: 5 # 提醒前等多久(0–120):这段时间在 Web 端答完就不打扰
|
|
@@ -121,11 +121,15 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
121
121
|
| --- | --- |
|
|
122
122
|
| `/help` | 命令列表 |
|
|
123
123
|
| `/new` | 开新会话 |
|
|
124
|
-
| `/sessions` |
|
|
124
|
+
| `/sessions [页码]` | 列出最近会话与序号(不含前台会话),每页 10 个 |
|
|
125
|
+
| `/switch <序号、0、front 或会话 id>` | 切换当前会话;`0` 与 `front` 回到前台会话 |
|
|
125
126
|
| `/status` | 当前会话与运行状态 |
|
|
126
127
|
| `/stop` | 中止正在跑的回合 |
|
|
127
128
|
| `/trace` | 查看上一条回答的模型与耗时 |
|
|
128
|
-
| `/send
|
|
129
|
+
| `/send <序号、0 或会话 id> <内容>` | 发到指定会话,那一轮的回答回到这里;`0` 是前台会话;可附图;回合正在跑时按「回合内插话」设置处理 |
|
|
130
|
+
| `/queue <序号、0 或会话 id> <内容>` | 与 `/send` 相同,但始终排队到目标当前回合之后 |
|
|
131
|
+
|
|
132
|
+
`/send` 与普通消息一样,在目标会话正在跑回合时按面板的「回合内插话」设置决定插进当前回合还是排队;`/queue` 参数相同,但始终排队到当前回合之后,不受该设置影响。`/switch` 的换绑与前缀会跨重启保留,`/new` 会清掉;切到非前台会话后,回复前会加 `**会话名>**`,切回前台(序号 `0`)后前缀消失。前台会话固定为序号 `0`,不出现在 `/sessions` 里,避免回到前台后列表里又套一个自己。目标会话还有投递在等回答时不允许切换。旧版 `direct.json` 没有前台记录时,`/switch 0` 会提示用 `/new` 重新建会话。
|
|
129
133
|
|
|
130
134
|
## 命令行与斜杠命令
|
|
131
135
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 0008 独立模式 /send 按会话序号投递
|
|
2
|
+
|
|
3
|
+
> 提交模式部分已被 [0011](0011-独立模式send遵循插话设置与queue命令.md) 取代:`/send` 现在遵循「回合内插话」,固定排队用 `/queue`。序号快照、回答回收与超时等决定仍有效。
|
|
4
|
+
|
|
5
|
+
## 背景
|
|
6
|
+
|
|
7
|
+
独立模式最初的 `/send <文本>` 只是把文本回显到当前聊天,与核心模式的
|
|
8
|
+
`/send <序号或会话 id> <内容>` 同名不同义;`/sessions` 又用序号来切换绑定会话,
|
|
9
|
+
无法向其它会话发消息。主人要接着某个旧会话说话,只能先切换,回答也只会回到
|
|
10
|
+
切换后的绑定会话。
|
|
11
|
+
|
|
12
|
+
## 决策
|
|
13
|
+
|
|
14
|
+
- `/sessions [页码]` 只列会话(每页 10 个),每次列出一份新快照并落盘 `sessions.json`,
|
|
15
|
+
序号在下次 `/sessions` 之前不变;不再切换绑定。
|
|
16
|
+
- `/send <序号或会话 id> <内容>` 用 `queue` 提交到目标会话,登记观察者等它 `turn/end`,
|
|
17
|
+
把最后一条 assistant 文本发回发起命令的聊天;命令消息的 `DONE` 等回答真正送达后再补。
|
|
18
|
+
- 目标是当前绑定会话时走普通提交流程,不另开观察者,避免同一轮发两份回答。
|
|
19
|
+
- 目标会话正在跑时,先到的 `turn/end` 属于上一轮,跳过;30 分钟没结束就不再等并回一条提示。
|
|
20
|
+
- 序号快照按 `$DSH_HOME/.dsh-im-lark/` 下的私密文件保存(`sessions.json`)。
|
|
21
|
+
|
|
22
|
+
## 后果
|
|
23
|
+
|
|
24
|
+
- `/sessions <序号>` 不再切换会话;要接着某个旧会话说话用 `/send <序号> <内容>`。
|
|
25
|
+
- `/send` 从自测命令变成真正的跨会话投递;内容按原文提交,不再压平换行。
|
|
26
|
+
- `/stop` 仍只停当前绑定会话,不能停 `/send` 的目标会话;需要时再扩展。
|
|
27
|
+
- `/trace` 仍是「上一条回答的模型与耗时」,没有跟随核心的跟踪语义。
|
|
28
|
+
|
|
29
|
+
## 备选
|
|
30
|
+
|
|
31
|
+
- 保留回显、改名为 `/echo`:只能自测,不解决与核心同名不同义的问题。
|
|
32
|
+
- 只发不回收回答:与核心「结果回到这里」的语义不一致,主人还得去 Web 端看结果。
|
|
33
|
+
- 让 `/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
|
+
- 前台只放内存:重启后丢失,回到前台又得重新找,未采用。
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 0011 独立模式 /send 遵循插话设置与 /queue 固定排队
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
0008 让 `/send` 固定用 `queue` 提交,面板的「回合内插话」只影响普通消息和发到当前会话的 `/send`。主人希望同一个开关覆盖所有发送,同时保留一个明确不打断目标回合的投递方式。
|
|
6
|
+
|
|
7
|
+
## 决策
|
|
8
|
+
|
|
9
|
+
- 「回合内插话」作用于独立模式的所有发送:普通消息、`/send` 到当前会话、`/send` 到其它会话。目标回合正在跑时,`steer` 插进当前回合,`queue` 排到下一轮。
|
|
10
|
+
- 新增 `/queue <序号、0 或会话 id> <内容>`,参数与 `/send` 相同,固定用 `queue`,不受面板设置影响。
|
|
11
|
+
- `/send` 与 `/queue` 共用会话定位、图片、回答观察与 `DONE` 对齐,只有提交模式不同。排队且目标正在跑时跳过上一轮的 `turn/end`;插话时当前 `turn/end` 就是这一条的回答。
|
|
12
|
+
- 排队一律按「先跳过目标当前那一轮」对齐(不看列表快照是否说在跑):目标要么先发 `turn/start`,要么这一轮 `turn/end` 直接被跳过,快照过期也不会把别人的回答当成自己的。
|
|
13
|
+
- 当前绑定会话的「正在跑」以 `turn/start`/`turn/end` 维护的状态为准(比列表快照新):排队消息在提交时已知目标在跑,就不随那一轮打 `DONE`,等它自己那轮结束再补。
|
|
14
|
+
- 面板提示写明 `/queue` 始终排队;两个命令在等回答时都拒绝同目标的第二条投递与 `/switch`。
|
|
15
|
+
|
|
16
|
+
## 后果
|
|
17
|
+
|
|
18
|
+
- 已知限制一:`steer` 的判断依赖提交前一刻的运行状态;列表说空闲、提交时目标已在跑(Web 端刚发起)时,这一条仍可能被并进别人的回合,回答与 `DONE` 归属只能靠事件顺序推断。宿主事件没有可对账的 prompt id(`turn/start` 只有 `{turn}`),这一层无法消除。
|
|
19
|
+
- 已知限制二:排队消息的 `waiting` 是提交前读到「正在跑」时打的一次性标记。若那一轮恰好在提交等待期间结束,标记会留到它自己那轮结束时才被清掉,表现为这条漏打 `DONE`(漏打优于误打);根治可用事件里已有的 `turn` 号对账(`turn/start` 与 `turn/end` 的 data 都带 `turn`),当前实现未用。
|
|
20
|
+
|
|
21
|
+
- 默认 `steer` 下,`/send` 到正在跑的其它会话也会插话,可能改变目标当前回合;需要不打断时用 `/queue`。
|
|
22
|
+
- `/queue` 保留 0008 的固定排队语义;0008 关于序号快照、回答回收、超时的其余决定继续有效。
|
|
23
|
+
- 主人可以用命令显式选择是否排队,不必先改面板设置。
|
|
24
|
+
|
|
25
|
+
## 备选
|
|
26
|
+
|
|
27
|
+
- 保留 `/send` 固定 `queue`,只把设置扩到普通消息:不满足「所有发送」。
|
|
28
|
+
- 用 `/send --queue` 参数:与「第一个空白前是会话引用」的解析冲突,也不直观。
|
|
29
|
+
- 新增一个独立的 `/queue` 会话命令:参数与 `/send` 重复,未采用。
|
package/docs/adr/README.md
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
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` | 已接受 |
|
|
18
|
+
| [0011](0011-独立模式send遵循插话设置与queue命令.md) | 独立模式 `/send` 遵循插话设置,新增 `/queue` | 已接受 |
|
|
15
19
|
|
|
16
20
|
新增决策时:编号连续、标题用「做了什么」而不是「为什么」、状态只有
|
|
17
21
|
`提议 / 已接受 / 已废弃 / 被 NNNN 取代`。改主意不要改旧 ADR 的结论,追加新的一条
|
package/lib/client.js
CHANGED
|
@@ -147,7 +147,7 @@ var en_default = {
|
|
|
147
147
|
"direct.summaryCore": "Switched to the super agent; these settings no longer apply",
|
|
148
148
|
"direct.groupSession": "Session",
|
|
149
149
|
"direct.steer": "Steer the running turn",
|
|
150
|
-
"direct.steerHint": "
|
|
150
|
+
"direct.steerHint": "Regular messages and /send join a running turn; turn this off to queue until the turn ends. /queue always queues and ignores this switch.",
|
|
151
151
|
"direct.workspace": "Session workspace",
|
|
152
152
|
"direct.workspaceHint": "Where new sessions are created; send /new to apply.",
|
|
153
153
|
"direct.workspaceDefault": "Default (Lark session)",
|
|
@@ -259,7 +259,7 @@ var zh_default = {
|
|
|
259
259
|
"direct.summaryCore": "\u5DF2\u5207\u6362\u5230\u8D85\u7EA7\u52A9\u7406\uFF0C\u6B64\u5904\u914D\u7F6E\u4E0D\u518D\u751F\u6548",
|
|
260
260
|
"direct.groupSession": "\u4F1A\u8BDD",
|
|
261
261
|
"direct.steer": "\u56DE\u5408\u5185\u63D2\u8BDD",
|
|
262
|
-
"direct.steerHint": "\u56DE\u5408\u6B63\u5728\u8DD1\u65F6\
|
|
262
|
+
"direct.steerHint": "\u666E\u901A\u6D88\u606F\u4E0E /send \u5728\u76EE\u6807\u56DE\u5408\u6B63\u5728\u8DD1\u65F6\u76F4\u63A5\u63D2\u8FDB\u5F53\u524D\u56DE\u5408\uFF1B\u5173\u6389\u5219\u6392\u961F\u7B49\u8FD9\u4E00\u8F6E\u7ED3\u675F\u3002/queue \u59CB\u7EC8\u6392\u961F\uFF0C\u4E0D\u53D7\u6B64\u5F00\u5173\u5F71\u54CD\u3002",
|
|
263
263
|
"direct.workspace": "\u4F1A\u8BDD\u5DE5\u4F5C\u533A",
|
|
264
264
|
"direct.workspaceHint": "\u65B0\u4F1A\u8BDD\u5EFA\u5728\u54EA\u4E2A\u5DE5\u4F5C\u533A\uFF1B\u6539\u5B8C\u53D1 /new \u751F\u6548\u3002",
|
|
265
265
|
"direct.workspaceDefault": "\u9ED8\u8BA4\uFF08\u98DE\u4E66\u4F1A\u8BDD\uFF09",
|
package/lib/src/host/config.js
CHANGED
|
@@ -14,7 +14,7 @@ import { DEFAULT_MAX_TEXT_CHARS } from "../shared/limits.js";
|
|
|
14
14
|
import { readJsonIfPresent, writePrivateFile } from "./state/files.js";
|
|
15
15
|
import { resolveDataDir } from "./state/paths.js";
|
|
16
16
|
import { DEFAULT_LONG_TASK_MINUTES, normalizeLongTaskMinutes } from "./long-tasks.js";
|
|
17
|
-
/**
|
|
17
|
+
/** 默认插话:主人发消息通常是想马上纠正方向,排队会让这条消息过时;`/queue` 不受此设置影响。 */
|
|
18
18
|
export const DEFAULT_DIRECT_BUSY_MODE = 'steer';
|
|
19
19
|
/** 问题与审批提醒:默认开。 */
|
|
20
20
|
export const DEFAULT_QUESTION_REMINDERS = true;
|
|
@@ -1,32 +1,49 @@
|
|
|
1
1
|
export class DoneAlign {
|
|
2
2
|
/** 已提交、尚无定论的消息,按提交顺序。 */
|
|
3
3
|
#pending = [];
|
|
4
|
-
/**
|
|
5
|
-
push(messageId, mode) {
|
|
6
|
-
this.#pending.push({ messageId, mode });
|
|
4
|
+
/** 提交成功(已入会话)后登记。`waiting` 表示它排在别人正跑的那一轮之后。 */
|
|
5
|
+
push(messageId, mode, waiting = false) {
|
|
6
|
+
this.#pending.push({ messageId, mode, waiting: waiting && mode === 'queue' });
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* 一轮结束:出队本轮应答的消息(平台消息 id)。
|
|
10
10
|
* 交付失败时调用方仍要结算(这一轮已经消耗掉它们),只是不盖完成标记。
|
|
11
11
|
*/
|
|
12
12
|
settle() {
|
|
13
|
-
const head = this.#pending
|
|
13
|
+
const head = this.#pending[0];
|
|
14
14
|
if (head === undefined)
|
|
15
15
|
return [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (absorbed !== undefined)
|
|
21
|
-
settled.push(absorbed.messageId);
|
|
16
|
+
if (head.waiting) {
|
|
17
|
+
// 这一轮是队头排的那一轮,不是它自己:它现在才轮到,只结算被本轮吸收的 steer。
|
|
18
|
+
head.waiting = false;
|
|
19
|
+
return this.#takeAbsorbed(1);
|
|
22
20
|
}
|
|
21
|
+
this.#pending.shift();
|
|
22
|
+
const settled = [head.messageId, ...this.#takeAbsorbed()];
|
|
23
|
+
// 队头这一轮结束后,紧随的排队消息自己的一轮随即开始,不再等别人的 `turn/end`。
|
|
24
|
+
const next = this.#pending[0];
|
|
25
|
+
if (next?.mode === 'queue')
|
|
26
|
+
next.waiting = false;
|
|
23
27
|
return settled;
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
|
-
* 绑定会话换了(`/new`、`/
|
|
30
|
+
* 绑定会话换了(`/new`、`/switch`):旧会话的 `turn/end` 会被会话校验
|
|
27
31
|
* 丢弃,残留条目永远等不到自己的回合,只会被下一轮错认。整队清掉。
|
|
28
32
|
*/
|
|
29
33
|
clear() {
|
|
30
34
|
this.#pending.length = 0;
|
|
31
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 取走 `start` 起连续提交的 steer 条目:它们已被刚结束的这一轮在步骤边界吸收。
|
|
38
|
+
* 默认从队头扫;`waiting` 分支队头要留下,就从它的下一条开始。
|
|
39
|
+
*/
|
|
40
|
+
#takeAbsorbed(start = 0) {
|
|
41
|
+
const settled = [];
|
|
42
|
+
while (this.#pending[start]?.mode === 'steer') {
|
|
43
|
+
const absorbed = this.#pending.splice(start, 1)[0];
|
|
44
|
+
if (absorbed !== undefined)
|
|
45
|
+
settled.push(absorbed.messageId);
|
|
46
|
+
}
|
|
47
|
+
return settled;
|
|
48
|
+
}
|
|
32
49
|
}
|
package/lib/src/host/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { LarkRuntime } from "./runtime.js";
|
|
|
23
23
|
import { createLarkStack } from "./stack.js";
|
|
24
24
|
import { CredentialStore } from "./state/credentials.js";
|
|
25
25
|
import { DirectBindingStore, OwnerStore } from "./state/direct.js";
|
|
26
|
+
import { ListingStore } from "./state/listing.js";
|
|
26
27
|
import { ensurePrivateDir } from "./state/files.js";
|
|
27
28
|
import { resolveDefaultWorkspace } from "./state/paths.js";
|
|
28
29
|
import { LongTaskNotifier } from "./long-tasks.js";
|
|
@@ -47,6 +48,7 @@ export async function apply(ctx, config = {}) {
|
|
|
47
48
|
const settings = new LocalConfigStore({ dataDir: normalized.dataDir, config: normalized, logger });
|
|
48
49
|
const bindings = new DirectBindingStore({ dataDir: normalized.dataDir, logger });
|
|
49
50
|
const owners = new OwnerStore({ dataDir: normalized.dataDir, logger });
|
|
51
|
+
const listing = new ListingStore({ dataDir: normalized.dataDir, logger });
|
|
50
52
|
// 默认工作区目录与状态目录分开:会话的 cwd 不该能读到 App Secret。
|
|
51
53
|
const workspaces = new Workspaces({ dir: resolveDefaultWorkspace(), logger });
|
|
52
54
|
/** 当前连接的整套对象;凭据变化时整套重建。 */
|
|
@@ -154,6 +156,7 @@ export async function apply(ctx, config = {}) {
|
|
|
154
156
|
settings: () => settings.current,
|
|
155
157
|
bindings,
|
|
156
158
|
owners,
|
|
159
|
+
listing,
|
|
157
160
|
controller: () => controller,
|
|
158
161
|
workspaceId: () => workspaces.defaultId,
|
|
159
162
|
// 提醒的作答先于普通消息:主人回「批准」「2」时不该把它当聊天送进会话。
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* 主人自己按了停止(`reason.reason.kind === 'user'`)不算失败,静默丢弃。
|
|
19
19
|
*/
|
|
20
|
-
import { textFromAssistantMessage } from "./
|
|
20
|
+
import { textFromAssistantMessage } from "./session-text.js";
|
|
21
21
|
/** 长程任务阈值(分钟):默认半小时。 */
|
|
22
22
|
export const DEFAULT_LONG_TASK_MINUTES = 30;
|
|
23
23
|
export const MIN_LONG_TASK_MINUTES = 1;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把一条入站草稿变成会话输入:文字在前、图片在后,文件只给一句提示。
|
|
3
|
+
*
|
|
4
|
+
* 普通消息与 `/send` 共用:两处对「什么算一条输入」的口径必须一致。
|
|
5
|
+
*/
|
|
6
|
+
export function buildContent(text, draft) {
|
|
7
|
+
const parts = [];
|
|
8
|
+
const body = text.trim();
|
|
9
|
+
if (body === '' && (draft.images ?? []).length === 0)
|
|
10
|
+
parts.push({ type: 'text', text: '(空消息)' });
|
|
11
|
+
if (body !== '')
|
|
12
|
+
parts.push({ type: 'text', text: body });
|
|
13
|
+
for (const image of draft.images ?? []) {
|
|
14
|
+
parts.push({ type: 'image', mediaType: image.mediaType, data: image.data, ...(image.name === undefined ? {} : { name: image.name }) });
|
|
15
|
+
}
|
|
16
|
+
const fileCount = draft.files?.length ?? 0;
|
|
17
|
+
if (fileCount > 0) {
|
|
18
|
+
parts.push({ type: 'text', text: `(收到 ${fileCount} 个文件;独立模式暂不转发文件内容)` });
|
|
19
|
+
}
|
|
20
|
+
return parts;
|
|
21
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 独立模式的会话目录:`/sessions` 的表格、序号快照与命令行里的会话定位。
|
|
3
|
+
*
|
|
4
|
+
* 序号只按最近一次 `/sessions` 的快照解释(快照由 `state/listing.ts` 落盘),会话 id
|
|
5
|
+
* 支持完整或唯一前缀。子代理会话与从未用过的空会话不列:主人不该从飞书接管子任务,
|
|
6
|
+
* 也不该对着一个空会话发消息。
|
|
7
|
+
*/
|
|
8
|
+
/** 列表超时:宿主读盘慢时宁可报「读不到」,也不把命令卡住。 */
|
|
9
|
+
const LIST_TIMEOUT_MS = 10_000;
|
|
10
|
+
/** `/sessions` 每页几个会话。 */
|
|
11
|
+
export const SESSION_PAGE_SIZE = 10;
|
|
12
|
+
const TITLE_MAX = 32;
|
|
13
|
+
const ID_SHOWN = 8;
|
|
14
|
+
const SESSION_PREFIX = 'session-';
|
|
15
|
+
export const SEND_USAGE = '用法:`/send <序号、0 或会话 id> <内容>`。先发 `/sessions` 看序号(`0` 是前台会话);回合正在跑时按「回合内插话」设置决定插话或排队。';
|
|
16
|
+
export const QUEUE_USAGE = '用法:`/queue <序号、0 或会话 id> <内容>`。与 `/send` 相同,但始终排队到目标当前回合之后。';
|
|
17
|
+
export const SWITCH_USAGE = '用法:`/switch <序号、0、front 或会话 id>`;`0` 与 `front` 回到前台会话。';
|
|
18
|
+
/** 没有前台会话时的提示:有绑定说明是旧记录丢了,不能再让人发消息等新建。 */
|
|
19
|
+
export function frontMissingHint(hasBinding) {
|
|
20
|
+
return hasBinding
|
|
21
|
+
? '没有前台会话记录:发 /new 开新会话。'
|
|
22
|
+
: '还没有前台会话:先发一条消息建会话。';
|
|
23
|
+
}
|
|
24
|
+
/** 前台会话的固定引用:`0` 或 `front`(大小写不敏感)。 */
|
|
25
|
+
export function isFrontRef(ref) {
|
|
26
|
+
const token = ref.trim().toLowerCase();
|
|
27
|
+
return token === '0' || token === 'front';
|
|
28
|
+
}
|
|
29
|
+
function asText(value) {
|
|
30
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
31
|
+
}
|
|
32
|
+
function titleOf(row) {
|
|
33
|
+
const title = row.projections?.values?.title;
|
|
34
|
+
return typeof title === 'string' ? title.trim() : '';
|
|
35
|
+
}
|
|
36
|
+
/** 一行摘要 → 可列出的会话;不满足条件的返回 null。 */
|
|
37
|
+
function toSummary(row, keepId) {
|
|
38
|
+
const sessionId = asText(row.sessionId);
|
|
39
|
+
if (sessionId === '')
|
|
40
|
+
return null;
|
|
41
|
+
// 绑定会话即使还是空的也要列出来:主人得看得见它。
|
|
42
|
+
if (sessionId !== keepId) {
|
|
43
|
+
if (asText(row.origin) === 'subagent' || asText(row.parentSessionId) !== '')
|
|
44
|
+
return null;
|
|
45
|
+
if (row.blank === true)
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return { sessionId, title: titleOf(row), running: row.running === true };
|
|
49
|
+
}
|
|
50
|
+
export async function loadSessionCatalog(lister, options = {}) {
|
|
51
|
+
if (lister === null || typeof lister.list !== 'function') {
|
|
52
|
+
return { sessions: [], available: false, reason: '宿主不提供会话列表。' };
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const value = await lister.list({}, AbortSignal.timeout(options.timeoutMs ?? LIST_TIMEOUT_MS));
|
|
56
|
+
const items = Array.isArray(value?.items) ? value.items : [];
|
|
57
|
+
const keepId = options.keepId?.trim() ?? '';
|
|
58
|
+
const sessions = [];
|
|
59
|
+
for (const row of items) {
|
|
60
|
+
const summary = toSummary(row ?? {}, keepId);
|
|
61
|
+
if (summary !== null)
|
|
62
|
+
sessions.push(summary);
|
|
63
|
+
}
|
|
64
|
+
return { sessions, available: true };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
sessions: [],
|
|
69
|
+
available: false,
|
|
70
|
+
reason: `读取会话列表失败:${error instanceof Error ? error.message : String(error)}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function renderSessionList(view) {
|
|
75
|
+
const heading = view.pages > 1
|
|
76
|
+
? `**最近会话**(共 ${view.total} 个,第 ${view.page}/${view.pages} 页)`
|
|
77
|
+
: `**最近会话**(共 ${view.total} 个)`;
|
|
78
|
+
const rows = view.rows.map((row, index) => {
|
|
79
|
+
const title = tableCell(row.title, TITLE_MAX) || '未命名会话';
|
|
80
|
+
const mark = row.sessionId === view.currentId ? '(当前)' : '';
|
|
81
|
+
return `| ${view.offset + index + 1} | ${title}${mark} | \`${shortSessionId(row.sessionId)}\` | ${row.running ? '**运行中**' : '空闲'} |`;
|
|
82
|
+
});
|
|
83
|
+
const lines = [
|
|
84
|
+
heading,
|
|
85
|
+
'',
|
|
86
|
+
'| # | 会话 | id | 状态 |',
|
|
87
|
+
'| --- | --- | --- | --- |',
|
|
88
|
+
...rows,
|
|
89
|
+
'',
|
|
90
|
+
];
|
|
91
|
+
if (view.truncated === true)
|
|
92
|
+
lines.push('只列最近 100 个会话,更多请到 DSH 网页端查看。', '');
|
|
93
|
+
if (view.page < view.pages)
|
|
94
|
+
lines.push(`发 \`/sessions ${view.page + 1}\` 看下一页。`, '');
|
|
95
|
+
const frontTip = view.hasFront === true ? '`/switch 0` 回到前台会话,`/send 0` 发到前台;' : '';
|
|
96
|
+
lines.push(`发 \`/switch <序号>\` 切换会话,${frontTip}\`/send <序号>\` 发到某个会话(\`/queue\` 始终排队),那一轮的回答回到这里。序号在下次发 \`/sessions\` 之前不变。`);
|
|
97
|
+
return lines.join('\n');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 按序号或会话 id 定位。
|
|
101
|
+
*
|
|
102
|
+
* 序号只按快照解释,不拿实时列表兜底:没列过的序号是盲猜。会话 id(完整或唯一前缀)
|
|
103
|
+
* 按当前列表找;不足 4 位的纯数字只当序号。
|
|
104
|
+
*/
|
|
105
|
+
export function resolveSessionRef(ref, listing, catalog) {
|
|
106
|
+
const token = ref.trim();
|
|
107
|
+
if (token === '')
|
|
108
|
+
return { miss: SEND_USAGE };
|
|
109
|
+
if (/^\d+$/.test(token)) {
|
|
110
|
+
const index = Number.parseInt(token, 10);
|
|
111
|
+
if (listing.length > 0 && index >= 1 && index <= listing.length) {
|
|
112
|
+
const entry = listing[index - 1];
|
|
113
|
+
return { sessionId: entry.sessionId, title: entry.title };
|
|
114
|
+
}
|
|
115
|
+
if (token.length < 4) {
|
|
116
|
+
return {
|
|
117
|
+
miss: listing.length > 0
|
|
118
|
+
? `序号 ${token} 不在你上次 /sessions 的列表里(共 ${listing.length} 个),发 /sessions 重新列出。`
|
|
119
|
+
: '还没列过会话:先发 /sessions 看序号,或直接用会话 id 的前几位。',
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!catalog.available)
|
|
124
|
+
return { miss: catalog.reason ?? '读取会话列表失败。' };
|
|
125
|
+
const matches = catalog.sessions.filter((row) => sessionIdMatches(row.sessionId, token));
|
|
126
|
+
if (matches.length === 1)
|
|
127
|
+
return { sessionId: matches[0].sessionId, title: matches[0].title };
|
|
128
|
+
if (matches.length > 1)
|
|
129
|
+
return { miss: `有多条会话匹配「${token}」,请多写几位 id。` };
|
|
130
|
+
return { miss: `找不到「${token}」对应的会话,先发 /sessions 看一眼序号(也可以用会话 id 的前几位)。` };
|
|
131
|
+
}
|
|
132
|
+
/** 会话 id 是否匹配命令行里给的完整 id 或前缀;表格里的短 id 也认。 */
|
|
133
|
+
export function sessionIdMatches(sessionId, token) {
|
|
134
|
+
const id = sessionId.trim();
|
|
135
|
+
const value = token.trim();
|
|
136
|
+
if (id === '' || value === '')
|
|
137
|
+
return false;
|
|
138
|
+
if (id === value || id.startsWith(value))
|
|
139
|
+
return true;
|
|
140
|
+
return id.startsWith(SESSION_PREFIX) && id.slice(SESSION_PREFIX.length).startsWith(value);
|
|
141
|
+
}
|
|
142
|
+
/** 表格里显示的会话 id:去掉 `session-` 前缀,只留前 8 位。 */
|
|
143
|
+
export function shortSessionId(sessionId) {
|
|
144
|
+
const id = sessionId.startsWith(SESSION_PREFIX) ? sessionId.slice(SESSION_PREFIX.length) : sessionId;
|
|
145
|
+
return id.slice(0, ID_SHOWN);
|
|
146
|
+
}
|
|
147
|
+
const UNTITLED_SESSION = '未命名会话';
|
|
148
|
+
const SESSION_LABEL_MAX = 32;
|
|
149
|
+
/** 回复里的会话名:压平换行与连续空白,过长截断。 */
|
|
150
|
+
export function sessionLabel(title) {
|
|
151
|
+
const flat = (title ?? '').replace(/\s+/g, ' ').trim();
|
|
152
|
+
if (flat === '')
|
|
153
|
+
return UNTITLED_SESSION;
|
|
154
|
+
return flat.length > SESSION_LABEL_MAX ? `${flat.slice(0, SESSION_LABEL_MAX - 1)}…` : flat;
|
|
155
|
+
}
|
|
156
|
+
/** 放进 `**…**` 里的会话名:转义会打断强调的 Markdown 字符。 */
|
|
157
|
+
export function markLabel(label) {
|
|
158
|
+
return label.replace(/[\\`*_[\]<>|~]/g, '\\$&');
|
|
159
|
+
}
|
|
160
|
+
/** 表格单元格:换行压成空格、`|` 转义(否则会被当成列分隔),过长截断。 */
|
|
161
|
+
function tableCell(value, max = Infinity) {
|
|
162
|
+
const flat = value.replace(/\s*\r?\n\s*/g, ' ').trim();
|
|
163
|
+
const clipped = flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
164
|
+
return clipped.replace(/\|/g, '\\|');
|
|
165
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 宿主 `session/event` 的取字段小工具。
|
|
3
|
+
*
|
|
4
|
+
* 独立会话与 `/send` 观察者都要从事件里取 assistant 文本,放在这里避免两边各写一份;
|
|
5
|
+
* 只做形状收窄,不认识的结构一律按「没有」处理。
|
|
6
|
+
*/
|
|
7
|
+
export function asRecord(value) {
|
|
8
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
9
|
+
}
|
|
10
|
+
/** 从 `assistant/message` 的 content 块里取文字。 */
|
|
11
|
+
export function textFromAssistantMessage(message) {
|
|
12
|
+
const content = asRecord(message)?.content;
|
|
13
|
+
if (!Array.isArray(content))
|
|
14
|
+
return '';
|
|
15
|
+
let text = '';
|
|
16
|
+
for (const block of content) {
|
|
17
|
+
const item = asRecord(block);
|
|
18
|
+
if (item !== null && item.type === 'text' && typeof item.text === 'string')
|
|
19
|
+
text += item.text;
|
|
20
|
+
}
|
|
21
|
+
return text;
|
|
22
|
+
}
|