palz-connector 1.4.4 → 1.4.5

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.4.4",
4
+ "version": "1.4.5",
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.4.4",
3
+ "version": "1.4.5",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "Palz IM 接入 OpenClaw — 模块化架构,基于 OpenClaw Runtime 消息管道",
package/src/outbound.ts CHANGED
@@ -9,8 +9,7 @@ import { resolvePalzAccount } from "./config.js";
9
9
  import { sendToPalzIM } from "./send.js";
10
10
  import { loadMediaAsOssUrl } from "./media.js";
11
11
  import { parsePalzTarget } from "./targets.js";
12
- import { contentPartsToOpenAIContent, textToOpenAIContent } from "./content.js";
13
- import type { ContentPart, OpenAIContent } from "./types.js";
12
+ import type { ContentPart } from "./types.js";
14
13
 
15
14
  export const palzOutbound = {
16
15
  deliveryMode: "direct" as const,
@@ -36,8 +35,8 @@ export const palzOutbound = {
36
35
  const { senderId, lobsterId, conversationId, conversationType } = parsePalzTarget(to);
37
36
  log(`palz-outbound: [sendText] 解析: senderId="${senderId}" lobsterId="${lobsterId}" conversationId="${conversationId}" conversationType="${conversationType}" botId=${account.config.botId}`);
38
37
 
39
- const content = textToOpenAIContent(text ?? "");
40
- log(`palz-outbound: [sendText] 发送内容: type=${typeof content === "string" ? "string" : "array"} parts=${Array.isArray(content) ? content.length : 1}`);
38
+ const content = text ?? "";
39
+ log(`palz-outbound: [sendText] 发送内容: textLen=${content.length}`);
41
40
 
42
41
  const result = await sendToPalzIM({
43
42
  config: account.config,
@@ -79,14 +78,12 @@ export const palzOutbound = {
79
78
  }
80
79
  }
81
80
 
82
- const content: OpenAIContent = contentPartsToOpenAIContent(contentParts);
83
-
84
- log(`palz-outbound: [sendMedia] 发送内容: type=${typeof content === "string" ? "string" : "array"} parts=${Array.isArray(content) ? content.length : 1}`);
81
+ log(`palz-outbound: [sendMedia] 发送内容: parts=${contentParts.length}`);
85
82
 
86
83
  const result = await sendToPalzIM({
87
84
  config: account.config,
88
85
  conversationId,
89
- content,
86
+ content: contentParts,
90
87
  senderId,
91
88
  conversationType,
92
89
  lobsterId,
@@ -11,7 +11,7 @@
11
11
  import { getPalzRuntime } from "./runtime.js";
12
12
  import { loadMediaAsOssUrl } from "./media.js";
13
13
  import { sendToPalzIM } from "./send.js";
14
- import { contentPartsToOpenAIContent } from "./content.js";
14
+
15
15
  import { resolveToolDisplay, formatToolStartText, formatToolResultText, formatResultSummary } from "./tool-display.js";
16
16
  import type { PalzConfig, StreamChunkOpts, ContentPart, OpenAIContent } from "./types.js";
17
17
 
@@ -211,7 +211,10 @@ export function createPalzReplyDispatcher(params: CreatePalzReplyDispatcherParam
211
211
  }
212
212
 
213
213
  // Determine final content format
214
- const content: OpenAIContent = contentPartsToOpenAIContent(contentParts);
214
+ const content: OpenAIContent =
215
+ contentParts.length === 1 && contentParts[0].type === "text"
216
+ ? contentParts[0].text
217
+ : contentParts;
215
218
 
216
219
  if (streamState && kind === "final") {
217
220
  const seq = streamState.seq++;
package/src/send.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  */
7
7
 
8
8
  import { tracer, trace, SpanStatusCode, buildTraceparentHeader } from "./tracing.js";
9
- import type { SendToIMParams, OpenAIContent } from "./types.js";
9
+ import { contentPartsToOpenAIContent } from "./content.js";
10
+ import type { SendToIMParams, OpenAIContent, TextContentPart } from "./types.js";
10
11
 
11
12
  let msgSeq = 0;
12
13
 
@@ -28,8 +29,19 @@ export async function sendToPalzIM(params: SendToIMParams): Promise<any> {
28
29
  });
29
30
  }
30
31
 
32
+ function normalizeContent(content: OpenAIContent): OpenAIContent {
33
+ if (typeof content === "string") {
34
+ return contentPartsToOpenAIContent([{ type: "text", text: content } as TextContentPart]);
35
+ }
36
+ if (Array.isArray(content) && content.length === 1 && content[0].type === "text") {
37
+ return contentPartsToOpenAIContent(content);
38
+ }
39
+ return content;
40
+ }
41
+
31
42
  async function _sendToPalzIMInner(params: SendToIMParams): Promise<any> {
32
- const { config, conversationId, content, conversationType, msgId, senderId, stream, msgType, groupId, lobsterId, palzMsgType, toolContent, passthrough } = params;
43
+ const { config, conversationId, content: rawContent, conversationType, msgId, senderId, stream, msgType, groupId, lobsterId, palzMsgType, toolContent, passthrough } = params;
44
+ const content = normalizeContent(rawContent);
33
45
  const url = `${config.apiBaseUrl}/bot/send`;
34
46
  const resolvedMsgId = msgId || nextMsgId();
35
47
  const span = trace.getActiveSpan();