@michengai/dsh-im-connect 0.1.39 → 0.1.41
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 +18 -0
- package/CHANGELOG.zh-CN.md +18 -0
- package/README.en.md +27 -7
- package/README.md +29 -9
- package/client.js +168 -100
- package/lib/channels/dingtalk.d.ts.map +1 -1
- package/lib/channels/dingtalk.js +4 -2
- package/lib/channels/dingtalk.js.map +1 -1
- package/lib/client.js +168 -100
- package/lib/engine/chat-commands.d.ts +30 -0
- package/lib/engine/chat-commands.d.ts.map +1 -0
- package/lib/engine/chat-commands.js +451 -0
- package/lib/engine/chat-commands.js.map +1 -0
- package/lib/engine/command-locale.d.ts +6 -0
- package/lib/engine/command-locale.d.ts.map +1 -0
- package/lib/engine/command-locale.js +21 -0
- package/lib/engine/command-locale.js.map +1 -0
- package/lib/engine/command-messages.d.ts +214 -0
- package/lib/engine/command-messages.d.ts.map +1 -0
- package/lib/engine/command-messages.js +214 -0
- package/lib/engine/command-messages.js.map +1 -0
- package/lib/engine/command-permissions.d.ts +15 -0
- package/lib/engine/command-permissions.d.ts.map +1 -0
- package/lib/engine/command-permissions.js +39 -0
- package/lib/engine/command-permissions.js.map +1 -0
- package/lib/engine/command-replies.d.ts +12 -0
- package/lib/engine/command-replies.d.ts.map +1 -0
- package/lib/engine/command-replies.js +36 -0
- package/lib/engine/command-replies.js.map +1 -0
- package/lib/engine/gateway.d.ts +6 -1
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +70 -33
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/merge.d.ts +2 -0
- package/lib/engine/merge.d.ts.map +1 -1
- package/lib/engine/merge.js +2 -0
- package/lib/engine/merge.js.map +1 -1
- package/lib/engine/router.d.ts +19 -5
- package/lib/engine/router.d.ts.map +1 -1
- package/lib/engine/router.js +231 -61
- package/lib/engine/router.js.map +1 -1
- package/lib/engine/session-id.d.ts +7 -0
- package/lib/engine/session-id.d.ts.map +1 -1
- package/lib/engine/session-id.js.map +1 -1
- package/lib/engine/session-store.d.ts +6 -0
- package/lib/engine/session-store.d.ts.map +1 -1
- package/lib/engine/session-store.js +58 -1
- package/lib/engine/session-store.js.map +1 -1
- package/lib/engine/session-title.d.ts +8 -0
- package/lib/engine/session-title.d.ts.map +1 -0
- package/lib/engine/session-title.js +30 -0
- package/lib/engine/session-title.js.map +1 -0
- package/lib/manager.d.ts +7 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +57 -9
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/channels/dingtalk.ts +4 -2
- package/src/engine/chat-commands.ts +404 -0
- package/src/engine/command-locale.ts +20 -0
- package/src/engine/command-messages.ts +297 -0
- package/src/engine/command-permissions.ts +35 -0
- package/src/engine/command-replies.ts +37 -0
- package/src/engine/gateway.ts +59 -33
- package/src/engine/merge.ts +4 -0
- package/src/engine/router.ts +205 -60
- package/src/engine/session-id.ts +7 -0
- package/src/engine/session-store.ts +50 -1
- package/src/engine/session-title.ts +25 -0
- package/src/manager.ts +56 -10
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/** IM 命令文案字典。中文原文作为稳定键,插值与用户内容分开处理。 */
|
|
2
|
+
export const commandEnglish = {
|
|
3
|
+
"请在网页 Chat 中打开这条会话,再执行 /export 导出 ZIP 日志。IM 文件回传暂未支持。":
|
|
4
|
+
"Open this session in web Chat and run /export to download ZIP logs. File return is not yet supported in IM.",
|
|
5
|
+
"与 Chat 一致,此操作也会尝试保存后续 Chat 新会话的默认模型选择;已有其他会话不会主动修改。":
|
|
6
|
+
"As in Chat, this also attempts to save the default model selection for future Chat sessions; other existing sessions are not changed.",
|
|
7
|
+
会话与工作区: "Sessions and workspaces",
|
|
8
|
+
"/new — 新开会话(也可用 /clear);旧会话保留在频道列表":
|
|
9
|
+
"/new — Start a session (alias: /clear); previous sessions stay in the channel list",
|
|
10
|
+
"/sessions [页码] — 列出会话;/session 序号或ID — 切换会话":
|
|
11
|
+
"/sessions [page] — List sessions; /session number-or-ID — Switch session",
|
|
12
|
+
"/workspaces — 列出工作区;/workspace 序号或已有路径 — 切换并新建":
|
|
13
|
+
"/workspaces — List workspaces; /workspace number-or-existing-path — Start a session there",
|
|
14
|
+
"/history — 最近文字记录;/rename 新名称 — 改名;/fork — 分叉":
|
|
15
|
+
"/history — Recent text; /rename new-name — Rename; /fork — Fork",
|
|
16
|
+
模型与推理: "Models and reasoning",
|
|
17
|
+
"/model — 当前模型;/models — 可选模型":
|
|
18
|
+
"/model — Current model; /models — Available models",
|
|
19
|
+
"/reasoning — 当前推理等级和可选项":
|
|
20
|
+
"/reasoning — Current reasoning level and available options",
|
|
21
|
+
任务控制: "Task controls",
|
|
22
|
+
"/status — 当前状态;/stop — 请求停止,保留队列":
|
|
23
|
+
"/status — Current status; /stop — Request a stop, keeping queued messages",
|
|
24
|
+
"/steer 补充要求 — 提交补充指令;/queue — 查看队列与操作方法":
|
|
25
|
+
"/steer instructions — Submit additional instructions; /queue — View and manage queued messages",
|
|
26
|
+
"切换模型:先发 /models,再发 /model 序号。":
|
|
27
|
+
"Switch models: send /models, then /model number.",
|
|
28
|
+
"命令单独发送为文字;图片说明按普通消息处理。":
|
|
29
|
+
"Send commands as standalone text. Image captions are treated as ordinary messages.",
|
|
30
|
+
"当前 Host 未提供 {0},请升级 DSH。":
|
|
31
|
+
"Your DSH installation does not provide {0}. Update DSH on your computer.",
|
|
32
|
+
"当前 Host 不支持 {0}。": "Your DSH installation does not support {0}.",
|
|
33
|
+
"无法打开会话。": "Unable to open the session.",
|
|
34
|
+
"无法读取会话快照。": "Unable to read the session snapshot.",
|
|
35
|
+
"无法读取工作区。": "Unable to read workspaces.",
|
|
36
|
+
"序号无效或已过期,尚未切换。请发送 /{0} 获取新列表。":
|
|
37
|
+
"The number is invalid or expired. Nothing was switched. Send /{0} for a fresh list.",
|
|
38
|
+
"工作区:{0}": "Workspace: {0}",
|
|
39
|
+
默认推理: "Default reasoning",
|
|
40
|
+
"模型:{0}/{1} · {2}": "Model: {0}/{1} · {2}",
|
|
41
|
+
"命令格式无效,请发送 /help。": "Invalid command format. Send /help.",
|
|
42
|
+
"该控制命令不接受附件,请单独发送。":
|
|
43
|
+
"This control command does not accept attachments. Send it separately.",
|
|
44
|
+
"当前没有会话,请先发送消息或 /new。":
|
|
45
|
+
"No current session. Send a message or /new first.",
|
|
46
|
+
"/{0} 暂不支持参数。正确用法:/{1}":
|
|
47
|
+
"/{0} does not accept arguments. Usage: /{1}",
|
|
48
|
+
"查找当前会话:/status": "Find the current session: /status",
|
|
49
|
+
"最近文字:/history": "Recent text: /history",
|
|
50
|
+
"直接发送文字或 /new 创建会话": "Send text or /new to create a session",
|
|
51
|
+
"\n发送消息创建会话后,可查看该会话的 Chat 命令。":
|
|
52
|
+
"\nSend a message to create a session and discover its Chat commands.",
|
|
53
|
+
"\n扩展命令暂时无法读取,以上内置帮助仍可使用;稍后重试 /help。":
|
|
54
|
+
"\nExtension commands are temporarily unavailable. Built-in help above still applies; retry /help later.",
|
|
55
|
+
机器人: "Bot",
|
|
56
|
+
"\n\n扩展命令:\n": "\n\nExtension commands:\n",
|
|
57
|
+
"旧会话已保留,直接发送消息即可开始。":
|
|
58
|
+
"Previous sessions are preserved. Send a message to begin.",
|
|
59
|
+
"查看旧会话:/sessions": "Previous sessions: /sessions",
|
|
60
|
+
"查看当前配置:/status": "Current configuration: /status",
|
|
61
|
+
"用法:/sessions [页码]": "Usage: /sessions [page]",
|
|
62
|
+
"暂无可接续会话。": "No sessions available to resume.",
|
|
63
|
+
"直接发送消息,或 /new 开始聊天": "Send a message or /new to start chatting",
|
|
64
|
+
"没有第 {0} 页,共 {1} 页。": "Page {0} does not exist. There are {1} pages.",
|
|
65
|
+
"返回列表:/sessions {0}": "Back to list: /sessions {0}",
|
|
66
|
+
未命名会话: "Untitled session",
|
|
67
|
+
"〔当前〕": " [current]",
|
|
68
|
+
"切换:/session {0}": "Switch: /session {0}",
|
|
69
|
+
"下一页:/sessions {0}": "Next page: /sessions {0}",
|
|
70
|
+
"序号 15 分钟内有效,也可使用完整会话 ID。":
|
|
71
|
+
"Numbers expire after 15 minutes. Full session IDs also work.",
|
|
72
|
+
"当前没有会话。直接发送消息或 /new 开始。":
|
|
73
|
+
"No current session. Send a message or /new to begin.",
|
|
74
|
+
暂时无法读取: "Temporarily unavailable",
|
|
75
|
+
"当前会话:{0}\n工作区:{1}\n会话 ID:{2}":
|
|
76
|
+
"Current session: {0}\nWorkspace: {1}\nSession ID: {2}",
|
|
77
|
+
"切换会话:/sessions": "Switch session: /sessions",
|
|
78
|
+
"详细状态:/status": "Detailed status: /status",
|
|
79
|
+
"会话不存在或不是可接入的普通会话。":
|
|
80
|
+
"This session is unavailable. Send /sessions to choose another.",
|
|
81
|
+
"请先在 Chat 恢复该归档会话。":
|
|
82
|
+
"Restore this archived session in Chat first.",
|
|
83
|
+
"会话工作区归属无效。": "The session has an invalid workspace association.",
|
|
84
|
+
"目标会话正在运行,请在 Chat 停止后再切换。":
|
|
85
|
+
"The target session is running. Stop it in Chat before switching.",
|
|
86
|
+
"已切换会话:{0}\n工作区:{1}\n接下来的消息会发送到此会话。":
|
|
87
|
+
"Switched to: {0}\nWorkspace: {1}\nYour next messages will go to this session.",
|
|
88
|
+
"最近记录:/history": "Recent messages: /history",
|
|
89
|
+
"重新开始:/new": "Start over: /new",
|
|
90
|
+
"工作区列表 · 共 {0} 个\n\n": "Workspaces · {0} total\n\n",
|
|
91
|
+
"也可使用已列出的绝对路径;旧会话保留,账号默认目录不变。":
|
|
92
|
+
"You can also use a listed absolute path. Previous sessions and the account default directory are preserved.",
|
|
93
|
+
"别名:/workspacelist;序号 15 分钟内有效。":
|
|
94
|
+
"Alias: /workspacelist. Numbers expire after 15 minutes.",
|
|
95
|
+
"还没有可用工作区。请先在网页添加,再发送 /workspaces。":
|
|
96
|
+
"No workspaces available. Add one on the web, then send /workspaces.",
|
|
97
|
+
"没有找到这个已添加的工作区,尚未切换。发送 /workspaces 查看可选项;新目录请先在网页添加。":
|
|
98
|
+
"That workspace has not been added. Nothing was switched. Send /workspaces for options; add new directories on the web first.",
|
|
99
|
+
"查看配置:/status": "Configuration: /status",
|
|
100
|
+
"切回旧会话:/sessions": "Switch back: /sessions",
|
|
101
|
+
"可用模型 · 共 {0} 个\n\n": "Available models · {0} total\n\n",
|
|
102
|
+
"查看当前模型:/model;推理选项:/reasoning":
|
|
103
|
+
"Current model: /model; reasoning options: /reasoning",
|
|
104
|
+
"先发消息或 /new 创建会话,再切换模型。":
|
|
105
|
+
"Send a message or /new to create a session before switching models.",
|
|
106
|
+
"序号 15 分钟内有效。": "Numbers expire after 15 minutes.",
|
|
107
|
+
"暂无可用模型。请在网页配置模型服务,再发送 /models。":
|
|
108
|
+
"No models available. Configure a model provider on the web, then send /models.",
|
|
109
|
+
"当前没有排队消息。": "No queued messages.",
|
|
110
|
+
直接发消息继续: "Send a message to continue",
|
|
111
|
+
"查看状态:/status": "View status: /status",
|
|
112
|
+
"排队消息 · 共 {0} 条\n\n": "Queued messages · {0} total\n\n",
|
|
113
|
+
等待执行: "Waiting to run",
|
|
114
|
+
补充指令: "Additional instruction",
|
|
115
|
+
排队中: "Queued",
|
|
116
|
+
附件消息: "Attachment message",
|
|
117
|
+
"移除:/queue remove {0}": "Remove: /queue remove {0}",
|
|
118
|
+
"修改:/queue edit {0} 新内容": "Edit: /queue edit {0} new-content",
|
|
119
|
+
"改为补充指令:/queue steer {0}":
|
|
120
|
+
"Use as additional instruction: /queue steer {0}",
|
|
121
|
+
"无法读取队列。": "Unable to read the queue.",
|
|
122
|
+
"用法:/queue remove|steer|edit <消息ID> [新内容]":
|
|
123
|
+
"Usage: /queue remove|steer|edit <message-ID> [new-content]",
|
|
124
|
+
已移除排队消息: "Removed queued message",
|
|
125
|
+
已修改排队消息: "Updated queued message",
|
|
126
|
+
已将排队消息调整为补充指令:
|
|
127
|
+
"Changed queued message to an additional instruction",
|
|
128
|
+
"\n新内容:": "\nNew content: ",
|
|
129
|
+
"查看队列:/queue": "View queue: /queue",
|
|
130
|
+
"渠道:{0}({1})": "Channel: {0} ({1})",
|
|
131
|
+
"会话:{0}": "Session: {0}",
|
|
132
|
+
运行中: "Running",
|
|
133
|
+
空闲: "Idle",
|
|
134
|
+
"状态:{0}": "Status: {0}",
|
|
135
|
+
默认: "Default",
|
|
136
|
+
"模型:{0}/{1};推理:{2}": "Model: {0}/{1}; reasoning: {2}",
|
|
137
|
+
"模型:暂时无法读取": "Model: temporarily unavailable",
|
|
138
|
+
"补充要求:/steer 补充内容":
|
|
139
|
+
"Add instructions: /steer additional-instructions",
|
|
140
|
+
"请求停止:/stop": "Request a stop: /stop",
|
|
141
|
+
"模型设置:/model": "Model settings: /model",
|
|
142
|
+
"如已启用目标任务,请用 /goal pause 暂停目标。":
|
|
143
|
+
"If a goal is active, use /goal pause to pause it.",
|
|
144
|
+
"当前目标仍处于活跃状态,请用 /goal pause 暂停目标。":
|
|
145
|
+
"The current goal is still active. Use /goal pause to pause it.",
|
|
146
|
+
"已请求停止当前运行;排队消息保留,可用 /queue 查看。":
|
|
147
|
+
"Stop requested. Queued messages are preserved; view them with /queue.",
|
|
148
|
+
"确认运行状态:/status": "Check running status: /status",
|
|
149
|
+
"请填写补充要求。例如:/steer 只修改登录页面,保留现有配色\n查看状态:/status":
|
|
150
|
+
"Enter additional instructions. Example: /steer Only change the login page and keep the current colors\nView status: /status",
|
|
151
|
+
"补充指令已提交。\n{0}": "Additional instructions submitted.\n{0}",
|
|
152
|
+
"请填写新名称,例如:/rename 九月出行计划":
|
|
153
|
+
"Enter a new name. Example: /rename September travel plan",
|
|
154
|
+
"当前会话已改名:{0}": "Session renamed: {0}",
|
|
155
|
+
"查看会话列表:/sessions": "View sessions: /sessions",
|
|
156
|
+
"当前会话工作区不可用,无法分叉。":
|
|
157
|
+
"This session's workspace is unavailable. Unable to fork.",
|
|
158
|
+
"当前 Host 不支持 fork。": "This Host does not support fork.",
|
|
159
|
+
"已分叉并切换会话:{0}\n工作区:{1}\n新消息将继续这个分叉,原会话保留。":
|
|
160
|
+
"Forked and switched to session: {0}\nWorkspace: {1}\nNew messages will continue this fork. The original session is preserved.",
|
|
161
|
+
"查看继承记录:/history": "View inherited messages: /history",
|
|
162
|
+
"切回原会话:/sessions": "Return to the original session: /sessions",
|
|
163
|
+
"请先在网页检查并修复该分叉的工作区归属,然后":
|
|
164
|
+
"Check and repair this fork's workspace association on the web first, then ",
|
|
165
|
+
可稍后: "Later, ",
|
|
166
|
+
"分叉已创建:{0},但未能切换,当前绑定仍保留原会话。\n{1}发送 /session {2} 接续。":
|
|
167
|
+
"Fork created: {0}, but switching failed. The original session is still selected.\n{1}send /session {2} to resume it.",
|
|
168
|
+
"当前模型:{0}\n模型 ID:{1}/{2}\n推理等级:{3}":
|
|
169
|
+
"Current model: {0}\nModel ID: {1}/{2}\nReasoning level: {3}",
|
|
170
|
+
"选择其他模型:/models": "Choose another model: /models",
|
|
171
|
+
"查看推理选项:/reasoning": "Reasoning options: /reasoning",
|
|
172
|
+
"切换用法:/model {0}/{1} [推理等级ID]":
|
|
173
|
+
"Switch usage: /model {0}/{1} [reasoning-level-ID]",
|
|
174
|
+
"参数过多。用法:/model 序号或provider/model [推理等级ID];可用模型:/models":
|
|
175
|
+
"Too many arguments. Usage: /model number-or-provider/model [reasoning-level-ID]; available models: /models",
|
|
176
|
+
"用法:/model <序号或provider/model> [推理等级]":
|
|
177
|
+
"Usage: /model <number-or-provider/model> [reasoning-level]",
|
|
178
|
+
"调整推理:/reasoning": "Adjust reasoning: /reasoning",
|
|
179
|
+
"查看模型:/models": "View models: /models",
|
|
180
|
+
"可选等级:\n": "Available levels:\n",
|
|
181
|
+
"当前模型没有可选推理等级。":
|
|
182
|
+
"This model has no selectable reasoning levels.",
|
|
183
|
+
"模型:{0}\n当前推理:{1}\n{2}": "Model: {0}\nCurrent reasoning: {1}\n{2}",
|
|
184
|
+
"切换:/reasoning {0}": "Switch: /reasoning {0}",
|
|
185
|
+
"恢复默认:/reasoning --default": "Restore default: /reasoning --default",
|
|
186
|
+
"当前模型:/model": "Current model: /model",
|
|
187
|
+
"推理等级无效,请先 /reasoning 查看。":
|
|
188
|
+
"Invalid reasoning level. Send /reasoning for options.",
|
|
189
|
+
"推理等级已设为:{0}\n{1}": "Reasoning level set to: {0}\n{1}",
|
|
190
|
+
"查看当前模型:/model": "View current model: /model",
|
|
191
|
+
助手: "Assistant",
|
|
192
|
+
用户: "User",
|
|
193
|
+
"最近文字记录(不是完整历史)\n\n":
|
|
194
|
+
"Recent text messages (not the complete history)\n\n",
|
|
195
|
+
"最近记录中没有可展示的文字,图片或文件请在网页查看。":
|
|
196
|
+
"No displayable text in recent messages. View images or files on the web.",
|
|
197
|
+
"继续此会话:直接发消息": "Continue this session: send a message",
|
|
198
|
+
"换一个会话:/sessions": "Choose another session: /sessions",
|
|
199
|
+
"完整记录:在网页打开当前会话": "Full history: open this session on the web",
|
|
200
|
+
"Chat 命令只支持文字和图片附件。":
|
|
201
|
+
"Chat commands support only text and image attachments.",
|
|
202
|
+
"未知命令 /{0}。发送 /help 查看当前 Chat 支持的命令。":
|
|
203
|
+
"Unknown command /{0}. Send /help for available Chat commands.",
|
|
204
|
+
"压缩较早上下文:/compact": "Compress earlier context: /compact",
|
|
205
|
+
"管理长期目标:/goal;暂停:/goal pause;恢复:/goal resume":
|
|
206
|
+
"Manage a goal: /goal; pause: /goal pause; resume: /goal resume",
|
|
207
|
+
"进入计划模式:/plan;退出:/plan off":
|
|
208
|
+
"Enter plan mode: /plan; exit: /plan off",
|
|
209
|
+
"查看当前权限及可选项:/permission":
|
|
210
|
+
"Current permissions and options: /permission",
|
|
211
|
+
"记录会话反馈:/feedback 反馈内容":
|
|
212
|
+
"Record session feedback: /feedback feedback-text",
|
|
213
|
+
"提交代码简化审查:/simplify":
|
|
214
|
+
"Submit a code simplification review: /simplify",
|
|
215
|
+
"需在网页 Chat 中导出,IM 暂不回传文件":
|
|
216
|
+
"Export in web Chat; IM file return is not yet supported",
|
|
217
|
+
"命令已返回,但未提供结果说明。请在网页核对当前状态。":
|
|
218
|
+
"The command returned without a result description. Check the current state on the web.",
|
|
219
|
+
"命令执行失败,未提供具体原因。请在网页检查后重试。":
|
|
220
|
+
"The command failed without details. Check on the web before retrying.",
|
|
221
|
+
"查看运行状态:/status": "View running status: /status",
|
|
222
|
+
"查看可选权限:/permission": "Available permissions: /permission",
|
|
223
|
+
"切换方式:/permission 权限ID": "Switch usage: /permission permission-ID",
|
|
224
|
+
"进入计划模式:/plan": "Enter plan mode: /plan",
|
|
225
|
+
"退出计划模式:/plan off": "Exit plan mode: /plan off",
|
|
226
|
+
"查看任务状态:/status": "View task status: /status",
|
|
227
|
+
"补充反馈:/feedback 补充内容": "Add feedback: /feedback additional-feedback",
|
|
228
|
+
"查看最近对话:/history": "Recent conversation: /history",
|
|
229
|
+
"补充要求:/steer 保留现有接口":
|
|
230
|
+
"Add instructions: /steer Keep existing interfaces",
|
|
231
|
+
"暂停目标:/goal pause": "Pause goal: /goal pause",
|
|
232
|
+
"恢复推进:/goal resume": "Resume progress: /goal resume",
|
|
233
|
+
"修改目标:/goal edit 新目标": "Edit goal: /goal edit new-objective",
|
|
234
|
+
"查看进度:/goal": "View progress: /goal",
|
|
235
|
+
"恢复目标:/goal resume": "Resume goal: /goal resume",
|
|
236
|
+
"清除目标:/goal clear": "Clear goal: /goal clear",
|
|
237
|
+
"查看目标:/goal": "View goal: /goal",
|
|
238
|
+
"设置目标:/goal 目标内容": "Set a goal: /goal objective",
|
|
239
|
+
"Agent 预设:{0}": "Agent preset: {0}",
|
|
240
|
+
"权限:{0}": "Permissions: {0}",
|
|
241
|
+
活跃: "Active",
|
|
242
|
+
已暂停: "Paused",
|
|
243
|
+
受阻: "Needs attention",
|
|
244
|
+
已完成: "Complete",
|
|
245
|
+
"目标:{0}": "Goal: {0}",
|
|
246
|
+
无目标: "No goal",
|
|
247
|
+
"排队消息:{0} 条": "Queued messages: {0}",
|
|
248
|
+
"当前聊天未开启命令权限,可以继续正常对话。":
|
|
249
|
+
"Commands are disabled in this chat. You can still chat normally.",
|
|
250
|
+
"命令已取消。查看当前状态:/status":
|
|
251
|
+
"Command canceled. Check current status: /status",
|
|
252
|
+
"命令执行失败:{0}\n\n查看用法:/help;确认当前会话:/status":
|
|
253
|
+
"Command failed: {0}\n\nUsage: /help; check current session: /status",
|
|
254
|
+
"请查看本机日志。": "Open DSH on your computer to check the error details.",
|
|
255
|
+
"IM 助理已连接 DeepSeek Harness。直接发送文字即可开始任务。":
|
|
256
|
+
"IM assistant connected to DeepSeek Harness. Send a message to start a task.",
|
|
257
|
+
"请先完成当前问题或审批,再执行 /{0}。":
|
|
258
|
+
"Answer the pending question or approval, then run /{0} again.",
|
|
259
|
+
"当前任务正在运行,请先 /stop,等待停止后再执行 /{0}。":
|
|
260
|
+
"A task is running. Send /stop, wait for it to stop, then run /{0} again.",
|
|
261
|
+
"会话列表 · 第 {0}/{1} 页 · 共 {2} 个\n\n":
|
|
262
|
+
"Sessions · Page {0}/{1} · {2} total\n\n",
|
|
263
|
+
"〔已归档,需先在网页恢复〕": " [archived — restore on the web first]",
|
|
264
|
+
"归档状态暂时无法读取,切换时会重新校验。":
|
|
265
|
+
"Archive status is unavailable. It will be checked again when you switch.",
|
|
266
|
+
"{0}〔{1}〕\n{2}": "{0} [{1}]\n{2}",
|
|
267
|
+
"{0}:{1}{2}": "{0}: {1}{2}",
|
|
268
|
+
"{0}:{1}": "{0}: {1}",
|
|
269
|
+
"已切换模型:{0}/{1};推理:{2}\n{3}":
|
|
270
|
+
"Switched model to: {0}/{1}; reasoning: {2}\n{3}",
|
|
271
|
+
"当前会话还没有可分叉的完整回合。请完成一轮对话后再发送 /fork;也可用 /new 开始。":
|
|
272
|
+
"There is no completed turn to fork yet. Finish one exchange, then send /fork; or start fresh with /new.",
|
|
273
|
+
"已请求停止。当前没有正在执行的任务;排队消息保留,可用 /queue 查看。":
|
|
274
|
+
"Stop requested. No task is currently running. Queued messages are preserved; view them with /queue.",
|
|
275
|
+
"会话 ID:{0}": "Session ID: {0}",
|
|
276
|
+
"未授权:请管理员在设置 → IM助理 中批准你的访问。":
|
|
277
|
+
"Access is pending approval. Ask the administrator to approve you in Settings → IM assistant.",
|
|
278
|
+
"上一条消息正在合并,尚未执行本次命令。等待提交后再发 {0}。":
|
|
279
|
+
"Your previous messages are being combined. This command has not run. Send {0} again after they are submitted.",
|
|
280
|
+
"该会话已关联其他聊天,不能重复接续。请用 /sessions 选择其他会话,或 /new 新建。":
|
|
281
|
+
"This session is connected to another chat and cannot be connected again. Choose another with /sessions, or start one with /new.",
|
|
282
|
+
"/{0} 未能完成\n{1}": "/{0} couldn’t complete\n{1}",
|
|
283
|
+
"〔已关联其他聊天〕": " [connected to another chat]",
|
|
284
|
+
"〔运行中〕": " [running]",
|
|
285
|
+
"例如:帮我整理今天的待办。": "Try: Help me organize today's tasks.",
|
|
286
|
+
已开启新会话: "New session started",
|
|
287
|
+
"新建并切换:/workspace {0}":
|
|
288
|
+
"Start a session in another workspace: /workspace {0}",
|
|
289
|
+
"当前只有这个工作区。直接发消息继续,或 /new 开启新会话。":
|
|
290
|
+
"This is your only workspace. Send a message to continue, or /new to start fresh.",
|
|
291
|
+
"已在「{0}」开启新会话。\n工作区:{1}\n旧会话已保留,可以直接发送任务。":
|
|
292
|
+
"Started a new session in {0}.\nWorkspace: {1}\nPrevious sessions are preserved. Send a task to begin.",
|
|
293
|
+
"切换:/model {0}": "Switch: /model {0}",
|
|
294
|
+
"当前没有其他可切换模型,继续发送消息即可。":
|
|
295
|
+
"No other models are available. Send a message to continue.",
|
|
296
|
+
"当前名称已是:{0}": "The session is already named: {0}",
|
|
297
|
+
} as const;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** 命令权限独立于准入和工具审批;省略配置时兼容旧版行为。 */
|
|
2
|
+
export interface CommandScope { enabled: boolean; users: Array<{ userId: string; enabled: boolean }> }
|
|
3
|
+
export interface CommandPermissions { dm: CommandScope; group: CommandScope }
|
|
4
|
+
|
|
5
|
+
export function normalizeCommandPermissions(input: unknown): CommandPermissions {
|
|
6
|
+
if (input === undefined) return { dm: { enabled: true, users: [] }, group: { enabled: true, users: [] } }
|
|
7
|
+
const fail = (): never => { throw new Error('命令权限配置无效') }
|
|
8
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) return fail()
|
|
9
|
+
const source = input as Record<string, unknown>
|
|
10
|
+
if (Object.keys(source).some(key => key !== 'dm' && key !== 'group')) return fail()
|
|
11
|
+
const scope = (value: unknown): CommandScope => {
|
|
12
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return fail()
|
|
13
|
+
const item = value as Record<string, unknown>
|
|
14
|
+
if (typeof item.enabled !== 'boolean' || !Array.isArray(item.users) || item.users.length > 200
|
|
15
|
+
|| Object.keys(item).some(key => key !== 'enabled' && key !== 'users')) return fail()
|
|
16
|
+
const seen = new Set<string>()
|
|
17
|
+
const users = item.users.map((entry: unknown) => {
|
|
18
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return fail()
|
|
19
|
+
const user = entry as Record<string, unknown>
|
|
20
|
+
if (typeof user.userId !== 'string' || typeof user.enabled !== 'boolean'
|
|
21
|
+
|| Object.keys(user).some(key => key !== 'userId' && key !== 'enabled')) return fail()
|
|
22
|
+
const userId = user.userId.trim()
|
|
23
|
+
if (!userId || userId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(userId) || seen.has(userId)) return fail()
|
|
24
|
+
seen.add(userId)
|
|
25
|
+
return { userId, enabled: user.enabled }
|
|
26
|
+
})
|
|
27
|
+
return { enabled: item.enabled, users }
|
|
28
|
+
}
|
|
29
|
+
return { dm: scope(source.dm), group: scope(source.group) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function canExecuteCommand(policy: CommandPermissions, kind: 'dm' | 'group', userId?: string): boolean {
|
|
33
|
+
// 旧测试包的用户例外仅保留格式兼容,执行权限统一由聊天类型开关决定。
|
|
34
|
+
return policy[kind].enabled
|
|
35
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { replyText } from './command-locale.js'
|
|
2
|
+
/** 命令回复的文字排版与扩展命令指引;不推断宿主执行结果。 */
|
|
3
|
+
export function oneLine(value: string, limit = 160): string {
|
|
4
|
+
const text = value.replace(/\s+/g, ' ').trim()
|
|
5
|
+
return text.length > limit ? text.slice(0, limit) + '…' : text
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function related(...items: string[]): string { return items.some(Boolean) ? '\n\n' + items.filter(Boolean).join('\n') : '' }
|
|
9
|
+
|
|
10
|
+
export const extensionHelp = (): Record<string, string> => ({
|
|
11
|
+
compact: replyText('压缩较早上下文:/compact'),
|
|
12
|
+
goal: replyText('管理长期目标:/goal;暂停:/goal pause;恢复:/goal resume'),
|
|
13
|
+
plan: replyText('进入计划模式:/plan;退出:/plan off'),
|
|
14
|
+
permission: replyText('查看当前权限及可选项:/permission'),
|
|
15
|
+
feedback: replyText('记录会话反馈:/feedback 反馈内容'),
|
|
16
|
+
simplify: replyText('提交代码简化审查:/simplify'),
|
|
17
|
+
export: replyText('需在网页 Chat 中导出,IM 暂不回传文件'),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export function extensionReply(command: string, result: { kind: string; text?: string }, goal?: { phase?: string; activation?: string }): string {
|
|
21
|
+
// 宿主自然语言不是稳定协议,保留正文及反馈共享披露,不按英文子串猜测成功。
|
|
22
|
+
const body = result.text?.trim() ? result.text : result.kind === 'success' ? replyText('命令已返回,但未提供结果说明。请在网页核对当前状态。') : replyText('命令执行失败,未提供具体原因。请在网页检查后重试。')
|
|
23
|
+
const tips: Record<string, string[]> = {
|
|
24
|
+
compact: [replyText('最近记录:/history'), replyText('查看运行状态:/status')],
|
|
25
|
+
permission: [replyText('查看可选权限:/permission'), replyText('切换方式:/permission 权限ID')],
|
|
26
|
+
plan: [replyText('进入计划模式:/plan'), replyText('退出计划模式:/plan off'), replyText('查看任务状态:/status')],
|
|
27
|
+
feedback: [replyText('补充反馈:/feedback 补充内容'), replyText('查看最近对话:/history')],
|
|
28
|
+
simplify: [replyText('查看状态:/status'), replyText('补充要求:/steer 保留现有接口')],
|
|
29
|
+
goal: goal?.phase === 'active'
|
|
30
|
+
? [goal.activation === 'armed' ? replyText('暂停目标:/goal pause') : replyText('恢复推进:/goal resume'), replyText('修改目标:/goal edit 新目标'), replyText('查看进度:/goal')]
|
|
31
|
+
: goal?.phase === 'paused' || goal?.phase === 'blocked'
|
|
32
|
+
? [replyText('恢复目标:/goal resume'), replyText('修改目标:/goal edit 新目标'), replyText('清除目标:/goal clear')]
|
|
33
|
+
: [replyText('查看目标:/goal'), replyText('设置目标:/goal 目标内容')],
|
|
34
|
+
}
|
|
35
|
+
if (!Object.hasOwn(tips, command)) return body
|
|
36
|
+
return (result.kind === 'success' ? body : replyText('/{0} 未能完成\n{1}', command, body)) + related(...(tips[command] || []))
|
|
37
|
+
}
|
package/src/engine/gateway.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { replyText, withReplyLocale } from './command-locale.js'
|
|
2
|
+
import { ChatCommands } from './chat-commands.js'
|
|
3
|
+
import { canExecuteCommand, normalizeCommandPermissions, type CommandPermissions } from './command-permissions.js'
|
|
1
4
|
import type { Context } from '@deepseek-ai/cordis'
|
|
2
5
|
import { ImageInputError, imageInputFailure, imagePromptPart } from './image-input.js'
|
|
3
6
|
import { ApprovalBroker } from './approval.js'
|
|
4
7
|
import { SessionMerger } from './merge.js'
|
|
5
8
|
import { SessionRouter } from './router.js'
|
|
9
|
+
import { initialSessionTitle, readSessionTitle } from './session-title.js'
|
|
6
10
|
import { SeenStore } from './seen-store.js'
|
|
7
11
|
import { SessionMapStore } from './session-store.js'
|
|
8
|
-
import {
|
|
12
|
+
import { type ChatKind } from './session-id.js'
|
|
9
13
|
import { canAnswerToolApproval, decideAccess } from './access.js'
|
|
10
14
|
import { splitText } from './split.js'
|
|
11
15
|
import { ReplyStreamHub, isAssistantTextDelta } from './reply-stream.js'
|
|
@@ -50,16 +54,6 @@ interface InteractionDeliveryResult {
|
|
|
50
54
|
deliveredAny: boolean
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
const HELP = [
|
|
54
|
-
'IM 助理已连接本机 DeepSeek Harness。',
|
|
55
|
-
'',
|
|
56
|
-
'直接发文字即可继续当前频道会话。',
|
|
57
|
-
'结尾 .. 表示还有后续,!! 表示立即提交。',
|
|
58
|
-
'/new 开启全新会话(只影响当前 IM 聊天,不影响网页任务)',
|
|
59
|
-
'/status 查看当前频道会话',
|
|
60
|
-
'/help 显示本帮助',
|
|
61
|
-
].join('\n')
|
|
62
|
-
|
|
63
57
|
const DELEGATE_INTERACTION = Symbol('delegate-interaction')
|
|
64
58
|
const USER_QUESTION_WRAPPER = Symbol('dsh-im-connect.user-question-wrapper')
|
|
65
59
|
|
|
@@ -81,6 +75,8 @@ export class ImEngine {
|
|
|
81
75
|
private readonly wrappedUserQuestionServices = new WeakSet<object>()
|
|
82
76
|
private legacyServiceTimer?: NodeJS.Timeout
|
|
83
77
|
private disposed = false
|
|
78
|
+
private readonly chatCommands: ChatCommands
|
|
79
|
+
private readonly commandScopes = new Map<string, AbortController>()
|
|
84
80
|
private readonly inputScopes = new Map<string, AbortController>()
|
|
85
81
|
|
|
86
82
|
constructor(
|
|
@@ -92,9 +88,11 @@ export class ImEngine {
|
|
|
92
88
|
private readonly onUnauthorized?: (channelId: string, msg: ImMessage) => string,
|
|
93
89
|
private readonly resolveConfig: (channelId: string) => EngineConfig = () => config,
|
|
94
90
|
private readonly resolvePrivateAccess: (channelId: string) => 'approved' | 'all' = () => 'approved',
|
|
91
|
+
private readonly resolveCommandPermissions: (channelId: string) => CommandPermissions = () => normalizeCommandPermissions(undefined),
|
|
95
92
|
) {
|
|
96
93
|
// DSH 的真实 agents 类型比路由器所需的最小会话契约更严格,在此处完成边界适配。
|
|
97
94
|
this.router = new SessionRouter(ctx as unknown as ConstructorParameters<typeof SessionRouter>[0], store, config, log, resolveConfig)
|
|
95
|
+
this.chatCommands = new ChatCommands(ctx as unknown as { get(name: string): unknown }, this.router, id => this.questions.has(id) || this.broker.has(id), (id, msg) => { if (msg.userId) this.sessionActors.set(id, msg.userId) })
|
|
98
96
|
this.merger = new SessionMerger((config.mergeTimeoutSecs || 5) * 1000, (key, text) => {
|
|
99
97
|
const sep = key.indexOf(':')
|
|
100
98
|
const channelId = key.slice(0, sep)
|
|
@@ -148,6 +146,12 @@ export class ImEngine {
|
|
|
148
146
|
return this.router.remove(sessionId)
|
|
149
147
|
}
|
|
150
148
|
|
|
149
|
+
async cleanupMissingSession(sessionId: string): Promise<boolean> {
|
|
150
|
+
const removed = await this.router.cleanupMissing(sessionId)
|
|
151
|
+
if (removed) this.cancelSessionInteractions(sessionId)
|
|
152
|
+
return removed
|
|
153
|
+
}
|
|
154
|
+
|
|
151
155
|
async ensureSession(sessionId: string): Promise<boolean> {
|
|
152
156
|
return this.router.ensure(sessionId)
|
|
153
157
|
}
|
|
@@ -212,6 +216,9 @@ export class ImEngine {
|
|
|
212
216
|
|
|
213
217
|
dispose(): void {
|
|
214
218
|
this.disposed = true
|
|
219
|
+
this.chatCommands.clear()
|
|
220
|
+
for (const scope of this.commandScopes.values()) scope.abort()
|
|
221
|
+
this.commandScopes.clear()
|
|
215
222
|
for (const channelId of this.inputScopes.keys()) this.cancelInputs(channelId)
|
|
216
223
|
if (this.legacyServiceTimer) clearTimeout(this.legacyServiceTimer)
|
|
217
224
|
for (const off of this.disposeEvents) off()
|
|
@@ -223,6 +230,12 @@ export class ImEngine {
|
|
|
223
230
|
|
|
224
231
|
private enqueue(channelId: string, msg: ImMessage): void {
|
|
225
232
|
const key = `${channelId}:${msg.chatId}`
|
|
233
|
+
// 宿主命令可能等待交互;停止和审批回答不能排在该命令后面造成死锁。
|
|
234
|
+
const binding = this.router.lookup(channelId, msg.kind === 'group' ? 'group' : 'dm', msg.chatId)
|
|
235
|
+
if (this.commandScopes.has(key) && (/^\/stop(?:\s|$)/i.test(msg.text.trim()) || (binding && (this.questions.has(binding.sessionId) || this.broker.has(binding.sessionId)) && !msg.text.trim().startsWith('/')))) {
|
|
236
|
+
void this.handleInbound(channelId, msg)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
226
239
|
const prev = this.queues.get(key) ?? Promise.resolve()
|
|
227
240
|
const current = prev.catch(() => undefined).then(() => this.handleInbound(channelId, msg))
|
|
228
241
|
this.queues.set(key, current)
|
|
@@ -255,7 +268,7 @@ export class ImEngine {
|
|
|
255
268
|
|
|
256
269
|
private async rejectUnauthorized(channelId: string, channel: ChannelAdapter, msg: ImMessage): Promise<void> {
|
|
257
270
|
this.log(`[${channelId}] 拒绝未授权用户 ${msg.userId || '(无 userId)'}`)
|
|
258
|
-
const hint = this.onUnauthorized?.(channelId, msg) ?? '未授权:请管理员在设置 → IM助理 中批准你的访问。'
|
|
271
|
+
const hint = withReplyLocale(this.ctx, () => this.onUnauthorized?.(channelId, msg) ?? replyText('未授权:请管理员在设置 → IM助理 中批准你的访问。'))
|
|
259
272
|
if (msg.kind !== 'group') {
|
|
260
273
|
await channel.send(msg.chatId, hint).catch(() => undefined)
|
|
261
274
|
}
|
|
@@ -281,11 +294,21 @@ export class ImEngine {
|
|
|
281
294
|
const kind: ChatKind = msg.kind === 'group' ? 'group' : 'dm'
|
|
282
295
|
const binding = this.router.lookup(channelId, kind, msg.chatId)
|
|
283
296
|
if (text.startsWith('/') && !msg.media?.length) {
|
|
297
|
+
if (!canExecuteCommand(this.resolveCommandPermissions(channelId), kind, msg.userId)) {
|
|
298
|
+
await this.deliver(channel, msg.chatId, withReplyLocale(this.ctx, () => replyText('当前聊天未开启命令权限,可以继续正常对话。')))
|
|
299
|
+
return
|
|
300
|
+
}
|
|
284
301
|
const command = text.split(/\s+/, 1)[0]?.toLowerCase()
|
|
302
|
+
const mergeKey = `${channelId}:${kind}:${msg.chatId}`
|
|
303
|
+
if (command === '/stop') this.merger.cancel(mergeKey)
|
|
304
|
+
else if (this.merger.has(mergeKey)) {
|
|
305
|
+
await this.deliver(channel, msg.chatId, withReplyLocale(this.ctx, () => replyText('上一条消息正在合并,尚未执行本次命令。等待提交后再发 {0}。', command || '/help')))
|
|
306
|
+
return
|
|
307
|
+
}
|
|
285
308
|
if ((command === '/new' || command === '/clear')
|
|
286
309
|
&& binding
|
|
287
310
|
&& (this.questions.has(binding.sessionId) || this.broker.has(binding.sessionId))) {
|
|
288
|
-
await this.deliver(channel, msg.chatId, '
|
|
311
|
+
await this.deliver(channel, msg.chatId, withReplyLocale(this.ctx, () => replyText('请先完成当前问题或审批,再执行 /{0}。', command.slice(1))))
|
|
289
312
|
return
|
|
290
313
|
}
|
|
291
314
|
const reply = await this.handleCommand(channel, msg)
|
|
@@ -363,23 +386,18 @@ export class ImEngine {
|
|
|
363
386
|
}
|
|
364
387
|
|
|
365
388
|
private async handleCommand(channel: ChannelAdapter, msg: ImMessage): Promise<string | undefined> {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
if (cmd === '/new' || cmd === '/clear') {
|
|
379
|
-
const entry = await this.router.rotate(channel.id, kind, msg.chatId, msg.username ?? msg.chatId)
|
|
380
|
-
return `已开启新的频道会话:${entry.sessionId}`
|
|
389
|
+
const key = `${channel.id}:${msg.chatId}`
|
|
390
|
+
if (/^\/stop(?:\s|$)/i.test(msg.text.trim())) this.commandScopes.get(key)?.abort()
|
|
391
|
+
const scope = new AbortController()
|
|
392
|
+
this.commandScopes.set(key, scope)
|
|
393
|
+
try {
|
|
394
|
+
return await this.chatCommands.execute(channel, msg, scope.signal)
|
|
395
|
+
} catch (error) {
|
|
396
|
+
this.log(`[${channel.id}] 命令失败: ${error instanceof Error ? error.message : String(error)}`)
|
|
397
|
+
return withReplyLocale(this.ctx, () => scope.signal.aborted ? replyText('命令已取消。查看当前状态:/status') : replyText('命令执行失败:{0}\n\n查看用法:/help;确认当前会话:/status', error instanceof Error ? error.message : replyText('请查看本机日志。')))
|
|
398
|
+
} finally {
|
|
399
|
+
if (this.commandScopes.get(key) === scope) this.commandScopes.delete(key)
|
|
381
400
|
}
|
|
382
|
-
return `未知命令 ${cmd}。发送 /help 查看帮助。`
|
|
383
401
|
}
|
|
384
402
|
|
|
385
403
|
private async inject(channel: ChannelAdapter, msg: ImMessage): Promise<void> {
|
|
@@ -388,8 +406,10 @@ export class ImEngine {
|
|
|
388
406
|
if (!scope) this.inputScopes.set(channel.id, scope = new AbortController())
|
|
389
407
|
const { signal } = scope
|
|
390
408
|
const kind: ChatKind = msg.kind === 'group' ? 'group' : 'dm'
|
|
391
|
-
const
|
|
409
|
+
const initialTitle = initialSessionTitle(msg.text) || initialSessionTitle(msg.media?.find(item => item.name)?.name || '')
|
|
410
|
+
const title = initialTitle || msg.username || msg.chatId
|
|
392
411
|
const binding = await this.router.getOrCreate(channel.id, kind, msg.chatId, title)
|
|
412
|
+
if (initialTitle) this.router.setTitle(binding.sessionId, initialTitle, 'message')
|
|
393
413
|
const content: Array<Record<string, unknown>> = []
|
|
394
414
|
if (msg.text.trim()) content.push({ type: 'text', text: msg.text.trim() })
|
|
395
415
|
for (const media of msg.media ?? []) {
|
|
@@ -422,6 +442,7 @@ export class ImEngine {
|
|
|
422
442
|
}
|
|
423
443
|
|
|
424
444
|
private cancelInputs(channelId: string): void {
|
|
445
|
+
for (const [key, scope] of this.commandScopes) if (key.startsWith(channelId + ':')) scope.abort()
|
|
425
446
|
this.inputScopes.get(channelId)?.abort()
|
|
426
447
|
this.inputScopes.delete(channelId)
|
|
427
448
|
}
|
|
@@ -443,7 +464,7 @@ export class ImEngine {
|
|
|
443
464
|
const currentContract = req.agent !== undefined
|
|
444
465
|
const rawSessionId = req.agent?.session?.id ?? req.agent?.id ?? req.session?.id
|
|
445
466
|
const sessionId = rawSessionId ? String(rawSessionId) : ''
|
|
446
|
-
if (!sessionId || !
|
|
467
|
+
if (!sessionId || !this.router.bindingForSession(sessionId)) return next()
|
|
447
468
|
if (req.signal?.aborted) return currentContract ? 'cancelled' : next()
|
|
448
469
|
const result = await this.runInteraction(sessionId, async () => {
|
|
449
470
|
if (this.disposed || req.signal?.aborted) return currentContract ? 'cancelled' : DELEGATE_INTERACTION
|
|
@@ -495,7 +516,7 @@ export class ImEngine {
|
|
|
495
516
|
): Promise<UserQuestionAnswer> {
|
|
496
517
|
const rawSessionId = req.agent?.session?.id ?? req.agent?.id
|
|
497
518
|
const sessionId = rawSessionId ? String(rawSessionId) : ''
|
|
498
|
-
if (!sessionId || !
|
|
519
|
+
if (!sessionId || !this.router.bindingForSession(sessionId)) return next()
|
|
499
520
|
const questions = req.questions
|
|
500
521
|
if (!Array.isArray(questions)
|
|
501
522
|
|| questions.length === 0
|
|
@@ -705,7 +726,12 @@ export class ImEngine {
|
|
|
705
726
|
event: { type?: string; data?: { message?: { content?: Array<{ type?: string; text?: string }> }; chunk?: { type?: string; text?: string } } },
|
|
706
727
|
): Promise<void> {
|
|
707
728
|
const sessionId = session.id ? String(session.id) : ''
|
|
708
|
-
if (!
|
|
729
|
+
if (!this.router.bindingForSession(sessionId)) return
|
|
730
|
+
if (event.type === 'session/title') {
|
|
731
|
+
const title = readSessionTitle(event.data)
|
|
732
|
+
if (title) this.router.setTitle(sessionId, title.title, title.source)
|
|
733
|
+
return
|
|
734
|
+
}
|
|
709
735
|
const binding = this.router.bindingForSession(sessionId)
|
|
710
736
|
const channel = binding ? this.channels.get(binding.channelId) : undefined
|
|
711
737
|
if (!binding || !channel) return
|
package/src/engine/merge.ts
CHANGED
|
@@ -41,6 +41,10 @@ export class SessionMerger {
|
|
|
41
41
|
for (const key of [...this.buffers.keys()]) this.clear(key)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
has(key: string): boolean { return this.buffers.has(key) }
|
|
45
|
+
|
|
46
|
+
cancel(key: string): void { this.clear(key) }
|
|
47
|
+
|
|
44
48
|
private setBuffer(key: string, text: string): void {
|
|
45
49
|
this.clear(key)
|
|
46
50
|
const timer = setTimeout(() => {
|