@cmach_socket/opencode-qq-bot 0.6.3 → 0.6.4
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/package.json +1 -1
- package/src/index.ts +15 -2
- package/src/tools/qq.ts +22 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ import { registerAskGuard } from "./tools/ask-guard"
|
|
|
36
36
|
import { defaultToolProfilesPath, roleOf, ToolPolicy } from "./tools/policy"
|
|
37
37
|
import { registerToolPolicy } from "./tools/policy-guard"
|
|
38
38
|
import { registerSendGuard } from "./tools/send-guard"
|
|
39
|
-
import { createPlainSender, registerTools, sendPlainMessage } from "./tools/qq"
|
|
39
|
+
import { createPlainSender, registerTools, sendPlainMessage, TOOL_NAMESPACE } from "./tools/qq"
|
|
40
40
|
import { createEmojiRunner, emojiCommand } from "./emoji/command"
|
|
41
41
|
import { describeNotice, noticeMatches, noticeTarget } from "./events/notice"
|
|
42
42
|
import { NoticeStore } from "./events/store"
|
|
@@ -358,12 +358,25 @@ export default Plugin.define({
|
|
|
358
358
|
delete event.tools[name]
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
+
const profile = await policy.profileOf(role, targetKey(target))
|
|
362
|
+
// 模型这一轮实际能用的 QQ 工具:模型只认这些名字,缺一个就发不出消息。
|
|
363
|
+
const qqTools = Object.keys(event.tools).filter((name) =>
|
|
364
|
+
name.startsWith(`${TOOL_NAMESPACE}_`),
|
|
365
|
+
)
|
|
361
366
|
logger.debug(`上下文钩子:按角色收窄工具`, {
|
|
362
367
|
target: targetLabel(target),
|
|
363
368
|
role,
|
|
364
|
-
profile
|
|
369
|
+
profile,
|
|
365
370
|
removed,
|
|
371
|
+
qqTools,
|
|
366
372
|
})
|
|
373
|
+
if (!qqTools.includes("qq_send_message")) {
|
|
374
|
+
logger.warn(`${targetLabel(target)} 模型这一轮看不到 qq_send_message,发不出消息`, {
|
|
375
|
+
role,
|
|
376
|
+
profile,
|
|
377
|
+
removed,
|
|
378
|
+
})
|
|
379
|
+
}
|
|
367
380
|
}
|
|
368
381
|
})
|
|
369
382
|
|
package/src/tools/qq.ts
CHANGED
|
@@ -22,6 +22,26 @@ import type { Tracer } from "../trace"
|
|
|
22
22
|
/** 工具命名空间,最终工具名为 qq_send_message 等。 */
|
|
23
23
|
export const TOOL_NAMESPACE = "qq"
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* 暴露给模型的 QQ 工具名。
|
|
27
|
+
*
|
|
28
|
+
* 上游按 `namespace_工具名` 生成对外名字(点号换成下划线),模型只认这些名字;
|
|
29
|
+
* `qq_send_message` 是模型发消息的唯一入口。
|
|
30
|
+
*/
|
|
31
|
+
export const QQ_TOOL_NAMES = [
|
|
32
|
+
"qq_send_message",
|
|
33
|
+
"qq_send_image",
|
|
34
|
+
"qq_send_sticker",
|
|
35
|
+
"qq_send_record",
|
|
36
|
+
"qq_send_forward",
|
|
37
|
+
"qq_send_poke",
|
|
38
|
+
"qq_delete_message",
|
|
39
|
+
"qq_favorite_list",
|
|
40
|
+
"qq_get_group_member_info",
|
|
41
|
+
"qq_fetch_ptt_text",
|
|
42
|
+
"qq_get_login_info",
|
|
43
|
+
] as const
|
|
44
|
+
|
|
25
45
|
export interface ToolDeps {
|
|
26
46
|
ctx: Plugin.Context
|
|
27
47
|
config: QQBotConfig
|
|
@@ -352,6 +372,8 @@ export async function registerTools(deps: ToolDeps): Promise<{ dispose(): Promis
|
|
|
352
372
|
description:
|
|
353
373
|
"QQ 聊天工具:发送消息、图片、语音、合并转发,以及查询用户信息。仅在 QQ 群聊或私聊会话里可用,其他会话调用会返回错误。",
|
|
354
374
|
})
|
|
375
|
+
// 模型按这些名字调用工具;名字对不上时模型只会说「找不到工具」。
|
|
376
|
+
logger.info("已注册 QQ 工具", { tools: [...QQ_TOOL_NAMES] })
|
|
355
377
|
|
|
356
378
|
// QQ 工具必须作为独立工具暴露。Code Mode 只给模型一个 execute,
|
|
357
379
|
// 按聊天配置的 qq_* 规则永远命不中,普通成员会连发消息的能力都没有。
|