mioku-plugin-chat 3.0.3 → 3.0.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/core/chat-engine.ts +3 -3
- package/core/chat-turn.ts +9 -0
- package/core/media/gif-extractor.ts +3 -3
- package/core/tools/load-skill.ts +2 -2
- package/handlers/idle-debug.ts +1 -1
- package/handlers/message.ts +0 -20
- package/handlers/tts-command.ts +1 -1
- package/index.ts +54 -2
- package/manage/skill-session.ts +1 -1
- package/package.json +2 -30
- package/runtime/chat-runtime.ts +5 -3
- package/types.ts +1 -2
package/core/chat-engine.ts
CHANGED
|
@@ -580,8 +580,8 @@ function prependDynamicContextToFirstUserMessage(
|
|
|
580
580
|
|
|
581
581
|
const RATE_LIMITED_TOOL_NAMES = new Set(["web_search", "web_read_page"]);
|
|
582
582
|
const RATE_LIMITED_BUILTIN_NAMES = new Set([
|
|
583
|
-
"web_search
|
|
584
|
-
"web_search
|
|
583
|
+
"web_search-web_search",
|
|
584
|
+
"web_search-web_read_page",
|
|
585
585
|
]);
|
|
586
586
|
|
|
587
587
|
function buildSessionTools(
|
|
@@ -634,7 +634,7 @@ function buildSessionTools(
|
|
|
634
634
|
}
|
|
635
635
|
|
|
636
636
|
for (const [name, tool] of skillTools) {
|
|
637
|
-
const skillName = name.split("
|
|
637
|
+
const skillName = name.split("-")[0] || "";
|
|
638
638
|
const skill = toolCtx.aiService.getSkill(skillName);
|
|
639
639
|
if (
|
|
640
640
|
!toolCtx.config.enableExternalSkills ||
|
package/core/chat-turn.ts
CHANGED
|
@@ -609,6 +609,15 @@ async function executeChatRuntimeRequestNow(
|
|
|
609
609
|
{ extraTools: options.extraTools },
|
|
610
610
|
);
|
|
611
611
|
|
|
612
|
+
if (!result) {
|
|
613
|
+
pluginCtx.sessionManager.touch(sessionId);
|
|
614
|
+
return {
|
|
615
|
+
messages: [],
|
|
616
|
+
toolCalls: [],
|
|
617
|
+
collectedInfo: null,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
612
621
|
await finalizeChatTurn(pluginCtx, {
|
|
613
622
|
event,
|
|
614
623
|
cfg,
|
|
@@ -57,7 +57,7 @@ export async function extractGifFrames(
|
|
|
57
57
|
})
|
|
58
58
|
.png()
|
|
59
59
|
.toBuffer();
|
|
60
|
-
frames.push(`data:image/png
|
|
60
|
+
frames.push(`data:image/png;base64,${firstFrame.toString("base64")}`);
|
|
61
61
|
|
|
62
62
|
// 提取中间帧
|
|
63
63
|
if (middleIndex !== firstIndex && middleIndex !== lastIndex) {
|
|
@@ -67,7 +67,7 @@ export async function extractGifFrames(
|
|
|
67
67
|
})
|
|
68
68
|
.png()
|
|
69
69
|
.toBuffer();
|
|
70
|
-
frames.push(`data:image/png
|
|
70
|
+
frames.push(`data:image/png;base64,${middleFrame.toString("base64")}`);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// 提取末尾帧
|
|
@@ -78,7 +78,7 @@ export async function extractGifFrames(
|
|
|
78
78
|
})
|
|
79
79
|
.png()
|
|
80
80
|
.toBuffer();
|
|
81
|
-
frames.push(`data:image/png
|
|
81
|
+
frames.push(`data:image/png;base64,${lastFrame.toString("base64")}`);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
logger.info(
|
package/core/tools/load-skill.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function createLoadSkillTool(
|
|
|
97
97
|
feature: true,
|
|
98
98
|
expires_in: "1 hour",
|
|
99
99
|
tools: featureTools.map((t) => ({
|
|
100
|
-
name: `${skillName}
|
|
100
|
+
name: `${skillName}-${t.name}`,
|
|
101
101
|
description: t.description,
|
|
102
102
|
parameters: t.parameters,
|
|
103
103
|
})),
|
|
@@ -139,7 +139,7 @@ export function createLoadSkillTool(
|
|
|
139
139
|
skill_name: skill.name,
|
|
140
140
|
expires_in: "1 hour",
|
|
141
141
|
tools: skill.tools.map((t) => ({
|
|
142
|
-
name: `${skill.name}
|
|
142
|
+
name: `${skill.name}-${t.name}`,
|
|
143
143
|
description: t.description,
|
|
144
144
|
parameters: t.parameters,
|
|
145
145
|
})),
|
package/handlers/idle-debug.ts
CHANGED
|
@@ -11,7 +11,7 @@ export async function handleIdleCheckDebug(
|
|
|
11
11
|
cfg: ChatConfig,
|
|
12
12
|
): Promise<void> {
|
|
13
13
|
const ctx: MiokuContext = pluginCtx.ctx;
|
|
14
|
-
const isOwner = ctx.
|
|
14
|
+
const isOwner = ctx.isMaster?.(e) ?? false;
|
|
15
15
|
if (!isOwner) {
|
|
16
16
|
await e.reply("只有主人才能使用这个指令~");
|
|
17
17
|
return;
|
package/handlers/message.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
summarizeHistoryVideo,
|
|
23
23
|
} from "../core/media/history-media";
|
|
24
24
|
import { handleIdleCheckDebug } from "./idle-debug";
|
|
25
|
-
import { handleTtsCommand } from "./tts-command";
|
|
26
25
|
import { processChat } from "../core/chat-turn";
|
|
27
26
|
|
|
28
27
|
const POKE_COOLDOWN_MS = 10 * 60_000;
|
|
@@ -55,25 +54,6 @@ export function createMessageHandler(
|
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
if (text.startsWith("/tts")) {
|
|
59
|
-
const payload = text.replace(/^\/tts\s*/, "");
|
|
60
|
-
await handleTtsCommand(pluginCtx, e, payload);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (text === "/重置会话") {
|
|
65
|
-
if (groupId) {
|
|
66
|
-
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
67
|
-
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
68
|
-
await e.reply("已清除本群会话中 AI 发送的消息~");
|
|
69
|
-
} else {
|
|
70
|
-
pluginCtx.sessionManager.resetBotMessages(`personal:${userId}`);
|
|
71
|
-
pluginCtx.groupStructuredHistory.clear(`personal:${userId}`);
|
|
72
|
-
await e.reply("已清除你的个人会话中 AI 发送的消息~");
|
|
73
|
-
}
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
57
|
if (groupId && !isGroupAllowed(groupId, cfg)) return;
|
|
78
58
|
|
|
79
59
|
// 媒体分析
|
package/handlers/tts-command.ts
CHANGED
|
@@ -15,7 +15,7 @@ export async function handleTtsCommand(
|
|
|
15
15
|
payload: string,
|
|
16
16
|
): Promise<void> {
|
|
17
17
|
const { ctx } = pluginCtx;
|
|
18
|
-
const isOwner = ctx.
|
|
18
|
+
const isOwner = ctx.isMaster?.(e) ?? false;
|
|
19
19
|
// if (!isOwner) {
|
|
20
20
|
// await e.reply("只有主人才能使用 /tts 指令~");
|
|
21
21
|
// return;
|
package/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { RateLimitGuard } from "./manage/rate-limit-guard";
|
|
|
43
43
|
import { createChatRuntime } from "./runtime/chat-runtime";
|
|
44
44
|
import { createMessageHandler } from "./handlers/message";
|
|
45
45
|
import { createPokeHandler } from "./handlers/poke";
|
|
46
|
+
import { handleTtsCommand } from "./handlers/tts-command";
|
|
46
47
|
import { buildHistoryMediaOptions } from "./core/media/segment";
|
|
47
48
|
import type { ChatConfigProvider } from "./humanize";
|
|
48
49
|
import type { ChatPluginContext, ChatHandlerState } from "./context";
|
|
@@ -115,8 +116,6 @@ function resolveRoleInstances(aiService: AIService): {
|
|
|
115
116
|
|
|
116
117
|
export default definePlugin({
|
|
117
118
|
name: "chat",
|
|
118
|
-
version: "1.1.0",
|
|
119
|
-
description: "AI 智能聊天插件",
|
|
120
119
|
async setup(ctx: MiokuContext) {
|
|
121
120
|
ctx.logger.info("聊天插件正在初始化...");
|
|
122
121
|
|
|
@@ -511,6 +510,59 @@ roleModels = resolved.models;
|
|
|
511
510
|
const runtime = createChatRuntime(pluginCtx, getConfig);
|
|
512
511
|
aiService.registerChatRuntime(runtime);
|
|
513
512
|
|
|
513
|
+
ctx.command({
|
|
514
|
+
name: "/重置会话",
|
|
515
|
+
match: /^\/重置会话$/,
|
|
516
|
+
prefixes: false,
|
|
517
|
+
description: "重置自己的AI聊天记录",
|
|
518
|
+
handler: async ({ event }) => {
|
|
519
|
+
if (event.user_id === event.self_id) return;
|
|
520
|
+
const groupId =
|
|
521
|
+
event.message_type === "group" ? Number(event.group_id) : undefined;
|
|
522
|
+
if (groupId) {
|
|
523
|
+
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
524
|
+
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
525
|
+
await event.reply("已清除本群会话中 AI 发送的消息~");
|
|
526
|
+
} else {
|
|
527
|
+
const userId = Number(event.user_id || event.sender?.user_id || 0);
|
|
528
|
+
pluginCtx.sessionManager.resetBotMessages(`personal:${userId}`);
|
|
529
|
+
pluginCtx.groupStructuredHistory.clear(`personal:${userId}`);
|
|
530
|
+
await event.reply("已清除你的个人会话中 AI 发送的消息~");
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
});
|
|
534
|
+
ctx.command({
|
|
535
|
+
name: "/重置群会话",
|
|
536
|
+
match: /^\/重置群会话$/,
|
|
537
|
+
prefixes: false,
|
|
538
|
+
permission: "admin",
|
|
539
|
+
description: "重置当前群的AI聊天记录",
|
|
540
|
+
handler: async ({ event }) => {
|
|
541
|
+
if (event.user_id === event.self_id) return;
|
|
542
|
+
const groupId =
|
|
543
|
+
event.message_type === "group" ? Number(event.group_id) : undefined;
|
|
544
|
+
if (!groupId) {
|
|
545
|
+
await event.reply("在群里使用试试看吧~", true);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
pluginCtx.sessionManager.resetBotMessages(`group:${groupId}`);
|
|
549
|
+
pluginCtx.groupStructuredHistory.clear(`group:${groupId}`);
|
|
550
|
+
await event.reply("已清除本群会话中 AI 发送的消息~");
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
ctx.command({
|
|
554
|
+
name: "/tts",
|
|
555
|
+
match: /^\/tts\s*(.*)$/,
|
|
556
|
+
prefixes: false,
|
|
557
|
+
permission: "owner",
|
|
558
|
+
description: "TTS 推理",
|
|
559
|
+
usage: "/tts <文本>",
|
|
560
|
+
handler: async ({ event, match }) => {
|
|
561
|
+
if (event.user_id === event.self_id) return;
|
|
562
|
+
await handleTtsCommand(pluginCtx, event, String(match?.[1] ?? "").trim());
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
|
|
514
566
|
ctx.handle("message", createMessageHandler(pluginCtx, handlerState));
|
|
515
567
|
ctx.handle("notice.group.poke", createPokeHandler(pluginCtx, handlerState));
|
|
516
568
|
|
package/manage/skill-session.ts
CHANGED
|
@@ -43,7 +43,7 @@ export class SkillSessionManager {
|
|
|
43
43
|
const now = Date.now();
|
|
44
44
|
const toolMap = new Map<string, AITool>();
|
|
45
45
|
for (const tool of tools) {
|
|
46
|
-
toolMap.set(`${skillName}
|
|
46
|
+
toolMap.set(`${skillName}-${tool.name}`, tool);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const session: SkillSession = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-chat",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "AI 智能聊天插件",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -17,35 +17,7 @@
|
|
|
17
17
|
"config",
|
|
18
18
|
"help",
|
|
19
19
|
"screenshot"
|
|
20
|
-
]
|
|
21
|
-
"accessHooks": [
|
|
22
|
-
{
|
|
23
|
-
"id": "戳一戳触发对话",
|
|
24
|
-
"event": "notice.group.poke",
|
|
25
|
-
"description": "群内戳一戳 bot"
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
"help": {
|
|
29
|
-
"title": "AI 聊天",
|
|
30
|
-
"description": "智能 AI 聊天插件",
|
|
31
|
-
"commands": [
|
|
32
|
-
{
|
|
33
|
-
"cmd": "/重置会话",
|
|
34
|
-
"desc": "重置自己的AI聊天记录",
|
|
35
|
-
"role": "member"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"cmd": "/重置群会话",
|
|
39
|
-
"desc": "重置当前群的AI聊天记录",
|
|
40
|
-
"role": "admin"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"cmd": "/tts <文本>",
|
|
44
|
-
"desc": "TTS 推理",
|
|
45
|
-
"role": "owner"
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
20
|
+
]
|
|
49
21
|
},
|
|
50
22
|
"dependencies": {
|
|
51
23
|
"openai": "^4.0.0",
|
package/runtime/chat-runtime.ts
CHANGED
|
@@ -15,9 +15,11 @@ function resolveRuntimeGroupId(
|
|
|
15
15
|
): number | undefined {
|
|
16
16
|
if ("event" in options) {
|
|
17
17
|
const event = options.event;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (event?.kind !== "message" || event.message_type !== "group") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const groupId: unknown = event.group_id;
|
|
22
|
+
return typeof groupId === "number" ? groupId : undefined;
|
|
21
23
|
}
|
|
22
24
|
return "groupId" in options ? options.groupId : undefined;
|
|
23
25
|
}
|
package/types.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
|
2
1
|
import type { MiokuContext } from "mioku";
|
|
3
2
|
import type { AITool, AIService, SkillPermissionRole } from "mioku";
|
|
4
3
|
import type { ChatDatabase } from "./db";
|
|
@@ -339,7 +338,7 @@ export interface ChatResult {
|
|
|
339
338
|
pendingQuote?: string;
|
|
340
339
|
toolCalls: { name: string; args: any; result: any }[];
|
|
341
340
|
emojiPath?: string | null;
|
|
342
|
-
protocolMessages?:
|
|
341
|
+
protocolMessages?: unknown[];
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
/**
|