mioku-plugin-chat 2.3.0 → 2.4.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/configs/base.ts +1 -0
- package/configs/settings.ts +1 -1
- package/context.ts +17 -0
- package/core/chat-engine.ts +6 -1
- package/core/chat-turn.ts +540 -0
- package/core/media/history-media.ts +215 -70
- package/core/media/image-analyzer.ts +28 -19
- package/core/media/image-compress.ts +75 -0
- package/core/media/segment.ts +91 -0
- package/core/multimodal.ts +24 -12
- package/core/prompt.ts +332 -445
- package/core/tools/info.ts +284 -0
- package/core/tools/load-skill.ts +149 -0
- package/core/tools/web.ts +306 -0
- package/core/tools.ts +11 -822
- package/db.ts +45 -142
- package/handlers/idle-debug.ts +135 -0
- package/handlers/message.ts +316 -0
- package/handlers/poke.ts +165 -0
- package/humanize/emotion-agent.ts +3 -4
- package/humanize/expression.ts +3 -4
- package/humanize/planner.ts +2 -2
- package/humanize/topic.ts +3 -4
- package/index.ts +73 -1705
- package/manage/cooldown.ts +52 -27
- package/manage/group-structured-history.ts +35 -0
- package/manage/idle-check.ts +40 -20
- package/manage/queue-processor.ts +51 -25
- package/manage/rate-limit-guard.ts +70 -0
- package/package.json +1 -1
- package/runtime/chat-runtime.ts +124 -0
- package/types.ts +1 -0
- package/utils/index.ts +2 -0
- package/utils/json.ts +8 -0
- package/utils/message.ts +185 -175
package/core/multimodal.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AIInstance } from "mioku";
|
|
2
2
|
import type { MiokiContext } from "mioki";
|
|
3
3
|
import { logger } from "mioki";
|
|
4
|
+
import { prepareImageUrlsForModel } from "./media/image-compress";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 多模态内容管理器
|
|
@@ -47,6 +48,8 @@ export async function describeImage(
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
imageUrls = await prepareImageUrlsForModel(imageUrls);
|
|
52
|
+
|
|
50
53
|
// 构建提示词
|
|
51
54
|
const systemPrompt = `You are an image analysis assistant. Your task is to provide a detailed, accurate description of the image.
|
|
52
55
|
|
|
@@ -110,36 +113,45 @@ ${context ? `\nUser context: ${context}` : ""}`;
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
export type MediaByMessageId =
|
|
117
|
+
| { kind: "image"; url: string }
|
|
118
|
+
| { kind: "video"; sources: string[] }
|
|
119
|
+
| null;
|
|
120
|
+
|
|
113
121
|
/**
|
|
114
|
-
* 获取指定消息 ID
|
|
122
|
+
* 获取指定消息 ID 中的首个媒体(图片或视频)
|
|
115
123
|
* @param ctx Mioki 上下文
|
|
116
124
|
* @param messageId 消息 ID
|
|
117
125
|
* @param e
|
|
118
|
-
* @returns
|
|
126
|
+
* @returns 媒体信息或 null
|
|
119
127
|
*/
|
|
120
|
-
export async function
|
|
128
|
+
export async function getMediaByMessageId(
|
|
121
129
|
ctx: MiokiContext,
|
|
122
130
|
messageId: number,
|
|
123
131
|
e: any,
|
|
124
|
-
): Promise<
|
|
132
|
+
): Promise<MediaByMessageId> {
|
|
125
133
|
try {
|
|
126
|
-
// 通过 message_id 获取消息详情
|
|
127
134
|
const msg = await ctx.pickBot(e.self_id).getMsg(messageId);
|
|
128
135
|
if (!msg || !msg.message) {
|
|
129
136
|
return null;
|
|
130
137
|
}
|
|
131
138
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
for (const seg of msg.message as any[]) {
|
|
140
|
+
if (seg.type === "image") {
|
|
141
|
+
const url = seg.url || seg.data?.url;
|
|
142
|
+
if (url) return { kind: "image", url };
|
|
143
|
+
}
|
|
144
|
+
if (seg.type === "video") {
|
|
145
|
+
const { getSegmentSourceCandidates } = await import("./media/history-media");
|
|
146
|
+
const sources = getSegmentSourceCandidates(seg);
|
|
147
|
+
if (sources.length > 0) return { kind: "video", sources };
|
|
148
|
+
}
|
|
136
149
|
}
|
|
137
150
|
|
|
138
|
-
|
|
139
|
-
return (imageSeg as any).url || (imageSeg as any).data?.url || null;
|
|
151
|
+
return null;
|
|
140
152
|
} catch (err) {
|
|
141
153
|
logger.error(
|
|
142
|
-
`[multimodal] Failed to get
|
|
154
|
+
`[multimodal] Failed to get media from message ${messageId}: ${err}`,
|
|
143
155
|
);
|
|
144
156
|
return null;
|
|
145
157
|
}
|