palz-connector 1.2.5 → 1.2.6

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "palz-connector",
3
3
  "name": "Palz Connector Channel",
4
- "version": "1.2.5",
4
+ "version": "1.2.6",
5
5
  "description": "Palz IM 接入 OpenClaw",
6
6
  "channels": [
7
7
  "palz-connector"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palz-connector",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "Palz IM 接入 OpenClaw — 模块化架构,基于 OpenClaw Runtime 消息管道",
package/src/bot.ts CHANGED
@@ -15,7 +15,7 @@ import { resolvePalzAccount } from "./config.js";
15
15
  import { tryClaimMessage } from "./dedup.js";
16
16
  import { createPalzReplyDispatcher } from "./reply-dispatcher.js";
17
17
  import { resolvePalzMediaList } from "./media.js";
18
- import type { PalzMessageEvent, OpenAIContent, ContentPart, TextContentPart } from "./types.js";
18
+ import type { PalzMessageEvent, OpenAIContent, ContentPart, TextContentPart, PalzMediaInfo } from "./types.js";
19
19
 
20
20
  // ============ 文本提取工具 ============
21
21
 
@@ -51,6 +51,7 @@ const enqueue = createChatQueue();
51
51
  interface HistoryEntry {
52
52
  sender: string;
53
53
  body: string;
54
+ mediaList?: PalzMediaInfo[];
54
55
  timestamp: number;
55
56
  messageId: string;
56
57
  }
@@ -194,22 +195,29 @@ export async function handlePalzMessage(params: HandlePalzMessageParams): Promis
194
195
  // 群聊 @提及检测
195
196
  const wasMentioned = isGroup ? (msg.mentioned_bot === true) : true;
196
197
  if (isGroup && !wasMentioned) {
197
- // 未@机器人:记录到群聊历史,下次被@时作为上下文
198
+ // 未@机器人:记录到群聊历史(含媒体),下次被@时作为上下文
198
199
  const historyKey = `${effectiveAgentId}:${msg.conversation_id}`;
199
200
  const senderName = msg.sender_name || msg.sender_id;
200
201
  log(`${tag}: [STEP 1 群聊历史] 未@机器人, 准备记录历史 historyKey=${historyKey} mentioned_bot=${msg.mentioned_bot} conversation_type=${msg.conversation_type}`);
202
+ // 解析媒体文件(图片/文档等),缓存到本地
203
+ const historyMediaList = await resolvePalzMediaList(msg.content, log);
204
+ log(`${tag}: [STEP 1 群聊历史] 媒体解析完成: mediaCount=${historyMediaList.length}`);
205
+ const bodyWithPlaceholder = historyMediaList.length > 0
206
+ ? `${senderName}: ${plainText} ${historyMediaList.map(m => m.placeholder).join(' ')}`
207
+ : `${senderName}: ${plainText}`;
201
208
  recordGroupHistoryEntry({
202
209
  historyKey,
203
210
  entry: {
204
211
  sender: msg.sender_id,
205
- body: `${senderName}: ${plainText}`,
212
+ body: bodyWithPlaceholder,
213
+ mediaList: historyMediaList.length > 0 ? historyMediaList : undefined,
206
214
  timestamp: Date.now(),
207
215
  messageId: msg.msg_id,
208
216
  },
209
217
  limit: DEFAULT_GROUP_HISTORY_LIMIT,
210
218
  log,
211
219
  });
212
- log(`${tag}: [STEP 1 跳过] 原因=群聊中未@机器人, 已记录到历史 historyKey=${historyKey}`);
220
+ log(`${tag}: [STEP 1 跳过] 原因=群聊中未@机器人, 已记录到历史 historyKey=${historyKey} mediaCount=${historyMediaList.length}`);
213
221
  return;
214
222
  }
215
223
 
@@ -258,7 +266,7 @@ async function dispatchPalzMessage(params: HandlePalzMessageParams): Promise<voi
258
266
  : 0;
259
267
  log(`${tag}: [STEP 4/6 媒体解析] 输入: contentType=${typeof msg.content === "string" ? "string" : "array"} mediaCount=${mediaCount}`);
260
268
  const mediaList = await resolvePalzMediaList(msg.content, log);
261
- const mediaPayload = buildMediaPayload(mediaList);
269
+ let mediaPayload = buildMediaPayload(mediaList);
262
270
  log(`${tag}: [STEP 4 输出] mediaList=${JSON.stringify(mediaList.map((m) => ({ path: m.path, contentType: m.contentType })))} mediaPayload=${JSON.stringify(mediaPayload)}`);
263
271
 
264
272
  // STEP 5: 解析路由
@@ -336,6 +344,15 @@ async function dispatchPalzMessage(params: HandlePalzMessageParams): Promise<voi
336
344
  });
337
345
  log(`${tag}: [STEP 6b 群聊历史] 构建完成, historyKey=${historyKey} bodyLen=${body.length} combinedBodyLen=${combinedBody.length} hasHistory=${combinedBody.length !== body.length}`);
338
346
  // log(`${tag}: [STEP 6b 群聊历史] combinedBody=\n${combinedBody}`);
347
+
348
+ // 将历史中缓存的媒体合并到当前 mediaPayload
349
+ const historyEntries = chatHistories.get(historyKey) ?? [];
350
+ const historyMediaList = historyEntries.flatMap(e => e.mediaList ?? []);
351
+ if (historyMediaList.length > 0) {
352
+ const allMedia = [...historyMediaList, ...mediaList];
353
+ mediaPayload = buildMediaPayload(allMedia);
354
+ log(`${tag}: [STEP 6b 历史媒体合并] historyMedia=${historyMediaList.length} currentMedia=${mediaList.length} totalMedia=${allMedia.length}`);
355
+ }
339
356
  }
340
357
 
341
358
  // 构建 InboundHistory(结构化历史数据,Runtime 会注入到系统提示中)
package/src/send.ts CHANGED
@@ -41,15 +41,16 @@ export async function sendToPalzIM(params: SendToIMParams): Promise<any> {
41
41
  reqBody.delta = stream.delta;
42
42
  }
43
43
 
44
+ const reqBodyStr = JSON.stringify(reqBody);
44
45
  console.log(
45
- `palz-send: [HTTP_REQ] POST ${url}\n request_body=${JSON.stringify(reqBody).slice(0, 800)}`,
46
+ `palz-send: [HTTP_REQ] POST ${url} body_length=${reqBodyStr.length}\n request_body=${reqBodyStr}`,
46
47
  );
47
48
 
48
49
  const startMs = Date.now();
49
50
  const response = await fetch(url, {
50
51
  method: "POST",
51
52
  headers: { "Content-Type": "application/json" },
52
- body: JSON.stringify(reqBody),
53
+ body: reqBodyStr,
53
54
  });
54
55
  const elapsedMs = Date.now() - startMs;
55
56