koishi-plugin-aka-ai-generator 0.8.5 → 0.8.7

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 CHANGED
@@ -69,14 +69,35 @@ function sanitizeString(str) {
69
69
  __name(sanitizeString, "sanitizeString");
70
70
  async function downloadImageAsBase64(ctx, url, timeout, logger, maxSize = 10 * 1024 * 1024) {
71
71
  try {
72
- const response = await ctx.http.get(url, {
73
- responseType: "arraybuffer",
74
- timeout: timeout * 1e3,
75
- headers: {
76
- "Accept": "image/*"
72
+ let buffer;
73
+ if (url.startsWith("internal:")) {
74
+ logger.debug("检测到 Koishi 内部协议 URL,使用 ctx.http.file() 获取", { url: url.substring(0, 80) });
75
+ try {
76
+ const fileResult = await ctx.http.file(url, { timeout: timeout * 1e3 });
77
+ buffer = Buffer.from(fileResult.data);
78
+ logger.info("Koishi 内部协议资源获取成功", {
79
+ url: url.substring(0, 80),
80
+ size: buffer.length,
81
+ type: fileResult.type
82
+ });
83
+ } catch (internalError) {
84
+ logger.error("Koishi 内部协议资源获取失败", {
85
+ url: url.substring(0, 80),
86
+ error: sanitizeError(internalError),
87
+ message: internalError?.message
88
+ });
89
+ throw new Error(`无法获取飞书/Lark 图片资源: ${internalError?.message || "未知错误"}`);
77
90
  }
78
- });
79
- const buffer = Buffer.from(response);
91
+ } else {
92
+ const response = await ctx.http.get(url, {
93
+ responseType: "arraybuffer",
94
+ timeout: timeout * 1e3,
95
+ headers: {
96
+ "Accept": "image/*"
97
+ }
98
+ });
99
+ buffer = Buffer.from(response);
100
+ }
80
101
  if (buffer.length > maxSize) {
81
102
  throw new Error(`图片大小超过限制 (${(maxSize / 1024 / 1024).toFixed(1)}MB)`);
82
103
  }
@@ -2205,8 +2226,26 @@ function apply(ctx, config) {
2205
2226
  while (true) {
2206
2227
  const msg = await session.prompt(mode === "multiple" ? 6e4 : 3e4);
2207
2228
  if (!msg) return { error: "等待超时" };
2229
+ logger.info("getInputData 收到消息", {
2230
+ platform: session.platform,
2231
+ msgType: typeof msg,
2232
+ msgLength: msg?.length,
2233
+ msgPreview: typeof msg === "string" ? msg.substring(0, 200) : "non-string",
2234
+ rawMsg: msg
2235
+ });
2208
2236
  const elements = import_koishi2.h.parse(msg);
2237
+ logger.info("getInputData 解析元素", {
2238
+ platform: session.platform,
2239
+ elementsCount: elements?.length,
2240
+ elementTypes: elements?.map((e) => e.type),
2241
+ elementsDetail: JSON.stringify(elements?.slice(0, 5))
2242
+ });
2209
2243
  const images = import_koishi2.h.select(elements, "img");
2244
+ logger.info("getInputData 图片元素", {
2245
+ platform: session.platform,
2246
+ imagesCount: images?.length,
2247
+ imagesAttrs: images?.map((img) => ({ src: img.attrs?.src?.substring(0, 100), allAttrs: Object.keys(img.attrs || {}) }))
2248
+ });
2210
2249
  const textElements = import_koishi2.h.select(elements, "text");
2211
2250
  const text = textElements.map((el) => el.attrs.content).join(" ").trim();
2212
2251
  if (images.length > 0) {
@@ -10,6 +10,7 @@ export declare function sanitizeString(str: string): string;
10
10
  /**
11
11
  * 下载图片并转换为 Base64
12
12
  * 包含 MIME 类型检测和大小限制
13
+ * 支持 Koishi 内部协议 URL (如 internal:lark/... internal:onebot/... 等)
13
14
  */
14
15
  export declare function downloadImageAsBase64(ctx: Context, url: string, timeout: number, logger: any, maxSize?: number): Promise<{
15
16
  data: string;
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.8.5",
4
+ "version": "0.8.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [