koishi-plugin-aka-ai-generator 0.7.10 → 0.7.12
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/lib/index.js +42 -3
- package/package.json +5 -2
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -28,6 +38,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
38
|
var import_koishi2 = require("koishi");
|
|
29
39
|
|
|
30
40
|
// src/providers/utils.ts
|
|
41
|
+
var import_jimp = __toESM(require("jimp"));
|
|
31
42
|
function sanitizeError(error) {
|
|
32
43
|
if (!error) return error;
|
|
33
44
|
if (typeof error === "string") {
|
|
@@ -92,6 +103,23 @@ async function downloadImageAsBase64(ctx, url, timeout, logger, maxSize = 10 * 1
|
|
|
92
103
|
mimeType = "image/gif";
|
|
93
104
|
}
|
|
94
105
|
}
|
|
106
|
+
if (mimeType === "image/gif") {
|
|
107
|
+
try {
|
|
108
|
+
logger.debug("检测到 GIF 图片,正在转换为 PNG", { url });
|
|
109
|
+
const image = await import_jimp.default.read(buffer);
|
|
110
|
+
const pngBuffer = await image.getBufferAsync(import_jimp.default.MIME_PNG);
|
|
111
|
+
const pngBase64 = pngBuffer.toString("base64");
|
|
112
|
+
logger.info("GIF 已转换为 PNG", {
|
|
113
|
+
originalSize: buffer.length,
|
|
114
|
+
newSize: pngBuffer.length,
|
|
115
|
+
width: image.getWidth(),
|
|
116
|
+
height: image.getHeight()
|
|
117
|
+
});
|
|
118
|
+
return { data: pngBase64, mimeType: "image/png" };
|
|
119
|
+
} catch (conversionError) {
|
|
120
|
+
logger.warn("GIF 转换失败,尝试原样发送", { error: conversionError?.message });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
95
123
|
logger.debug("图片下载并转换为Base64", { url, mimeType, size: base64.length });
|
|
96
124
|
return { data: base64, mimeType };
|
|
97
125
|
} catch (error) {
|
|
@@ -600,10 +628,21 @@ function parseGeminiResponse(response, logger) {
|
|
|
600
628
|
safetyRatings: candidate.safetyRatings
|
|
601
629
|
});
|
|
602
630
|
if (candidate.finishReason === "SAFETY" || candidate.finishReason === "RECITATION") {
|
|
603
|
-
|
|
631
|
+
let msg = `内容被阻止: ${candidate.finishReason},可能包含不安全的内容`;
|
|
632
|
+
if (candidate.finishMessage) {
|
|
633
|
+
msg += ` (详细信息: ${candidate.finishMessage})`;
|
|
634
|
+
}
|
|
635
|
+
throw new Error(msg);
|
|
604
636
|
}
|
|
605
|
-
if (candidate.finishReason !== "MAX_TOKENS") {
|
|
606
|
-
|
|
637
|
+
if (candidate.finishReason === "IMAGE_OTHER" || candidate.finishReason !== "MAX_TOKENS" && candidate.finishReason !== "STOP") {
|
|
638
|
+
let msg = `生成失败: ${candidate.finishReason}`;
|
|
639
|
+
if (candidate.finishMessage) {
|
|
640
|
+
msg += `,原因: ${candidate.finishMessage}`;
|
|
641
|
+
}
|
|
642
|
+
logger?.warn("Gemini 生成未完成", { finishReason: candidate.finishReason, finishMessage: candidate.finishMessage });
|
|
643
|
+
if (!candidate.content || !candidate.content.parts || candidate.content.parts.length === 0) {
|
|
644
|
+
throw new Error(msg);
|
|
645
|
+
}
|
|
607
646
|
}
|
|
608
647
|
}
|
|
609
648
|
if (candidate.content && candidate.content.parts) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-aka-ai-generator",
|
|
3
3
|
"description": "自用AI生成插件(GPTGod & Yunwu)",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.12",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -24,5 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"koishi": "^4.18.9"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"jimp": "^0.22.10"
|
|
27
30
|
}
|
|
28
|
-
}
|
|
31
|
+
}
|