@cmach_socket/opencode-qq-bot 0.10.1 → 1.0.0
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.md +35 -32
- package/package.json +1 -1
- package/src/bot-lock.ts +47 -0
- package/src/config/store.ts +1 -1
- package/src/diary/summary.ts +84 -28
- package/src/emoji/collection.ts +2 -0
- package/src/index.ts +47 -15
- package/src/media-path.ts +5 -7
- package/src/model-view.ts +20 -1
- package/src/naplink/client.ts +2 -1
- package/src/naplink/history.ts +3 -3
- package/src/naplink/media.ts +178 -43
- package/src/naplink/render.ts +205 -55
- package/src/panel/documents.ts +21 -6
- package/src/restartable.ts +14 -0
- package/src/session/manager.ts +158 -30
- package/src/session/prompt.ts +2 -0
- package/src/session/soul-guard.ts +36 -5
- package/src/session/soul.ts +24 -11
- package/src/tools/policy.ts +5 -4
- package/src/tools/qq.ts +380 -161
- package/src/tools/send-guard.ts +11 -1
package/src/tools/send-guard.ts
CHANGED
|
@@ -6,6 +6,9 @@ import type { SessionManager, Turn } from "../session/manager"
|
|
|
6
6
|
export const DUPLICATE_SEND_REFUSAL =
|
|
7
7
|
"禁止连续调用发送工具:上一步已经发送过消息,再发可能重复。请先调用其它工具(例如查看消息或整理内容),或直接结束本轮。"
|
|
8
8
|
|
|
9
|
+
/** `/stop` 之后仍要发送时回给模型的说明。 */
|
|
10
|
+
export const STOPPED_SEND_REFUSAL = "这一轮已被用户停止,不要再发送消息。等用户发来新消息再继续。"
|
|
11
|
+
|
|
9
12
|
/** 匹配 qq_send_message 与 qq_delete_message 等出站动作;钩子里可能带或不带命名空间。 */
|
|
10
13
|
const SEND_TOOL = /^(?:qq_)?(?:send[_-]|delete_message$)/
|
|
11
14
|
|
|
@@ -35,7 +38,14 @@ export async function registerSendGuard(
|
|
|
35
38
|
|
|
36
39
|
const before = await ctx.tool.hook("execute.before", async (event) => {
|
|
37
40
|
const active = manager.activeTurn(event.sessionID)
|
|
38
|
-
if (!active)
|
|
41
|
+
if (!active) {
|
|
42
|
+
// `/stop` 之后上游那一轮可能还在跑:这时不让它再往聊天里发消息。
|
|
43
|
+
if (SEND_TOOL.test(event.tool) && manager.isStopped(event.sessionID)) {
|
|
44
|
+
logger.warn(`会话已被停止,拒绝调用 ${event.tool}`)
|
|
45
|
+
throw new Error(STOPPED_SEND_REFUSAL)
|
|
46
|
+
}
|
|
47
|
+
return
|
|
48
|
+
}
|
|
39
49
|
const turn = active.turn
|
|
40
50
|
const previous = last.get(event.sessionID)
|
|
41
51
|
const send = SEND_TOOL.test(event.tool)
|