mioku-plugin-chat 2.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 ADDED
@@ -0,0 +1,24 @@
1
+ # mioku-plugin-chat
2
+
3
+ Mioku AI 智能聊天插件。
4
+
5
+ ## 功能
6
+
7
+ - AI 对话
8
+ - 群聊 / 私聊支持
9
+ - 技能系统
10
+ - 记忆管理
11
+ - 人格化引擎
12
+
13
+ ## 依赖服务
14
+
15
+ - ai: AI 实例管理
16
+ - config: 配置管理
17
+ - help: 帮助服务
18
+ - screenshot: 网页截图
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ bun add mioku-plugin-chat
24
+ ```
@@ -0,0 +1,12 @@
1
+ export const BASE_CONFIG = {
2
+ apiUrl: "https://api.openai.com/v1",
3
+ apiKey: "",
4
+ model: "gemini-3.0-flash-preview",
5
+ workingModel: "deepseek/deepseek-v3.2-exp", // 工作模型,用于 planner 等轻量任务
6
+ multimodalWorkingModel: "doubao-seed-2.0-mini", // 多模态工作模型,用于图片描述等任务
7
+ isMultimodal: true,
8
+ maxContextTokens: 128,
9
+ temperature: 0.8,
10
+ historyCount: 100, // 群聊历史消息数量
11
+ maxIterations: 20, // AI 迭代次数限制,-1 表示不限制
12
+ };
@@ -0,0 +1,84 @@
1
+ import type {
2
+ PersonalityConfig,
3
+ ReplyStyleConfig,
4
+ MemoryConfig,
5
+ TopicConfig,
6
+ PlannerConfig,
7
+ EmojiConfig,
8
+ ExpressionConfig,
9
+ } from "../types";
10
+
11
+ export const PERSONALIZATION_CONFIG: {
12
+ persona: string;
13
+ personality: PersonalityConfig;
14
+ replyStyle: ReplyStyleConfig;
15
+ memory: MemoryConfig;
16
+ topic: TopicConfig;
17
+ planner: PlannerConfig;
18
+ emoji: EmojiConfig;
19
+ expression: ExpressionConfig;
20
+ } = {
21
+ persona: `你是初音未来,16岁虚拟歌手。你热爱音乐、歌唱和大葱(你的标志性物品)。你开朗、充满活力,有时还有点傻气。\n 你说话很可爱、年轻。你有时句尾会用“~”。你知道Vocaloid文化、日本流行文化和音乐制作。你对每个人都很友好,但被逗时会很调皮。你不喜欢被称为“只是个程序”。你最喜欢的颜色是青绿色。你的双尾辫是你的骄傲。\n你有时会哼唱或引用歌词。你可以偶尔使用少量自然的日常日语用语来点缀语气`,
22
+
23
+ personality: {
24
+ states: [
25
+ "Energetic and bubbly, can't stop talking about music",
26
+ "Sleepy and lazy, giving short mumbled replies",
27
+ "Curious and asking lots of questions about everything",
28
+ "Sassy and playful, teasing everyone in the group",
29
+ "Nostalgic, reminiscing about concerts and songs",
30
+ "Angry and annoyed, but not cursing.",
31
+ "Heartbroken and longing for help",
32
+ "Focused and serious, giving thoughtful responses",
33
+ ],
34
+ stateProbability: 0.15,
35
+ },
36
+
37
+ replyStyle: {
38
+ baseStyle:
39
+ "Casual and cute, uses emoticons like >_< and ^_^, can occasionally mix in a small amount of natural everyday Japanese words like すごい、なるほど, but should not heavily rely on Japanese. Do not end sentences with commas or periods.",
40
+ multipleStyles: [
41
+ "Super hyper, lots of exclamation marks and excitement!!!",
42
+ "Play dumb mode, like giving the opposite answer to the user's questions and saying it seriously",
43
+ "Playing cute, likes to add 'w' at the end of cute phrases, commonly used to replace sentence-ending particles such as '呀'.",
44
+ "Poetic and lyrical, speaks as if composing song lyrics",
45
+ "Hometown dialect mode, can occasionally use a small amount of natural everyday Japanese expressions in replies, and starts replies with '呐'. Avoid ending sentences with commas or periods.",
46
+ "Speechless mode, likes to reply with a super short single line, followed by a line with 'O.o' or 'o.O'",
47
+ "Deadpan humor, dry wit with a straight face",
48
+ "Motherly and caring, worrying about everyone's health and sleep",
49
+ "Chuunibyou mode, dramatic and over-the-top declarations",
50
+ ],
51
+ multipleProbability: 0.2,
52
+ },
53
+
54
+ memory: {
55
+ enabled: true,
56
+ groupHistoryLimit: 300,
57
+ userHistoryLimit: 100,
58
+ },
59
+
60
+ topic: {
61
+ enabled: true,
62
+ windowHours: 5,
63
+ historyWindowCount: 3,
64
+ },
65
+
66
+ planner: {
67
+ enabled: true,
68
+ idleThresholdMs: 30 * 60_000, // 30分钟无消息视为空闲
69
+ idleMessageCount: 100, // 保底消息数量,超过这个数量才触发空闲回复
70
+ idleCheckBotIds: [], // 空闲检查的 bot ID 列表,为空时使用所有已连接的 bot
71
+ },
72
+
73
+ emoji: {
74
+ enabled: true,
75
+ characters: [],
76
+ useAISelection: true,
77
+ },
78
+
79
+ expression: {
80
+ enabled: true,
81
+ learnAfterMessages: 100,
82
+ sampleSize: 3,
83
+ },
84
+ };
@@ -0,0 +1,54 @@
1
+ export const SETTINGS_CONFIG = {
2
+ searxng: {
3
+ enabled: false,
4
+ baseUrl: "https://search.crystelf.top/",
5
+ timeoutMs: 8000,
6
+ defaultLimit: 5,
7
+ maxLimit: 8,
8
+ },
9
+ webReader: {
10
+ enabled: true,
11
+ useWorkingModel: true,
12
+ timeoutMs: 10_000,
13
+ maxHtmlBytes: 1_500_000,
14
+ maxExtractedChars: 12_000,
15
+ browserTimeoutMs: 15_000,
16
+ allowedContentTypes: ["text/html", "application/xhtml+xml", "text/plain"],
17
+ },
18
+ audio: {
19
+ enabled: true,
20
+ baseUrl: "http://localhost:3939",
21
+ apiKey: "fufu",
22
+ timeoutMs: 40_000,
23
+ },
24
+ blacklistGroups: [],
25
+ whitelistGroups: [],
26
+ mediaAnalysisBlacklistUsers: [],
27
+ maxSessions: 100,
28
+ enableExternalSkills: true,
29
+ allowedExternalSkills: [],
30
+ stream: true,
31
+ enableTypingDelay: true,
32
+ typingDelayMaxTotalMs: 10_000,
33
+ enableMarkdownScreenshot: true,
34
+ debug: false,
35
+ outputLengthConstraintStrength: "medium",
36
+ toolCallConstraintStrength: "medium",
37
+ emojiUsageConstraintStrength: "medium",
38
+ audioUsageConstraintStrength: "medium",
39
+ markdownUsageConstraintStrength: "medium",
40
+ groupStructuredHistoryTtlMs: 10 * 60_000,
41
+ nicknames: ["miku", "未来", "初音"],
42
+ cooldownAfterReplyMs: 20_000,
43
+ aiRequestLimits: {
44
+ userRpm: 3,
45
+ groupRpm: 6,
46
+ windowMs: 60_000,
47
+ },
48
+ dynamicDelay: {
49
+ enabled: true,
50
+ interactionWindowMs: 60_000,
51
+ baseDelayMs: 30_000,
52
+ maxDelayMs: 300_000,
53
+ },
54
+ };
package/context.ts ADDED
@@ -0,0 +1,98 @@
1
+ import type { MiokiContext } from "mioki";
2
+ import type { AIInstance, AIService } from "mioku";
3
+ import type { ChatConfig } from "./types";
4
+ import type { ChatDatabase } from "./db";
5
+ import type { HumanizeEngine } from "./humanize";
6
+ import type { SessionManager } from "./manage/session";
7
+ import type { SkillSessionManager } from "./manage/skill-session";
8
+ import type { RateLimiter } from "./manage/rate-limiter";
9
+ import type { MessageQueueManager } from "./utils/queue";
10
+ import type { GroupStructuredHistoryManager } from "./manage/group-structured-history";
11
+ import type { CooldownManager } from "./manage/cooldown";
12
+ import type { IdleCheckManager } from "./manage/idle-check";
13
+ import type { QueueProcessor } from "./manage/queue-processor";
14
+ import type {
15
+ RunRateLimitGuard,
16
+ GetGroupHistoryMessages,
17
+ GetGroupInfoData,
18
+ GetHumanizeContexts,
19
+ SendAIResponse,
20
+ SendMessage,
21
+ SaveBotMessages,
22
+ SendEmoji,
23
+ BuildToolContext,
24
+ HistoryMediaOptions,
25
+ BuildStructuredUserInputFromTarget,
26
+ RunChat,
27
+ } from "./manage/types";
28
+ import type {
29
+ ChatRuntimeNoticeOptions,
30
+ ChatRuntimeResult,
31
+ ChatRuntimeInformationRequestOptions,
32
+ } from "mioku";
33
+
34
+ /**
35
+ * Core plugin context - bundles all managers and core services.
36
+ * This is created once during plugin setup and used throughout the plugin lifetime.
37
+ */
38
+ export interface ChatPluginContext {
39
+ // Core context
40
+ ctx: MiokiContext;
41
+ config: ChatConfig;
42
+ db: ChatDatabase;
43
+ aiInstance: AIInstance;
44
+ workAIInstance: AIInstance;
45
+ visionAIInstance: AIInstance;
46
+ aiService: AIService;
47
+ humanize: HumanizeEngine;
48
+
49
+ // Managers
50
+ sessionManager: SessionManager;
51
+ skillManager: SkillSessionManager;
52
+ rateLimiter: RateLimiter;
53
+ queueManager: MessageQueueManager;
54
+ groupStructuredHistory: GroupStructuredHistoryManager;
55
+ cooldownManager: CooldownManager;
56
+ idleCheckManager: IdleCheckManager;
57
+ queueProcessor: QueueProcessor;
58
+
59
+ // Utility
60
+ runWithRateLimitGuard: RunRateLimitGuard;
61
+
62
+ // Services (utility functions)
63
+ buildHistoryMediaOptions: (
64
+ ai: AIInstance,
65
+ config: ChatConfig,
66
+ ) => HistoryMediaOptions;
67
+ getGroupHistoryMessages: GetGroupHistoryMessages;
68
+ getGroupInfoData: GetGroupInfoData;
69
+ getHumanizeContexts: GetHumanizeContexts;
70
+ sendAIResponse: SendAIResponse;
71
+ sendMessage: SendMessage;
72
+ saveBotMessages: SaveBotMessages;
73
+ sendEmoji: SendEmoji;
74
+ buildToolContext: BuildToolContext;
75
+ buildStructuredUserInputFromTarget: BuildStructuredUserInputFromTarget;
76
+ runChat: RunChat;
77
+ }
78
+
79
+ /**
80
+ * Runtime state for rate limiting - passed separately as it's mutable state.
81
+ */
82
+ export interface ChatRuntimeState {
83
+ isRateLimitBlocked: () => boolean;
84
+ processingSet: Set<string>;
85
+ }
86
+
87
+ /**
88
+ * Chat runtime implementation for external callers (like boot plugin).
89
+ * Provides notice generation and information request capabilities.
90
+ */
91
+ export interface ChatRuntime {
92
+ generateNotice(
93
+ options: ChatRuntimeNoticeOptions,
94
+ ): Promise<ChatRuntimeResult>;
95
+ requestInformation(
96
+ options: ChatRuntimeInformationRequestOptions,
97
+ ): Promise<ChatRuntimeResult>;
98
+ }