palz-connector 1.4.3 → 1.4.4

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.3",
4
+ "version": "1.4.4",
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.3",
3
+ "version": "1.4.4",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "Palz IM 接入 OpenClaw — 模块化架构,基于 OpenClaw Runtime 消息管道",
package/src/content.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { ContentPart, OpenAIContent, TextContentPart } from "./types.js";
2
+
3
+ export function extractSingleHttpsUrl(text: string): string | null {
4
+ const trimmed = text.trim();
5
+ if (!trimmed || /\s/.test(trimmed)) return null;
6
+
7
+ try {
8
+ const url = new URL(trimmed);
9
+ return url.protocol === "https:" && url.hostname ? trimmed : null;
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+
15
+ export function textToOpenAIContent(text: string): OpenAIContent {
16
+ const url = extractSingleHttpsUrl(text);
17
+ return url ? [{ type: "file", file_url: { url } }] : text;
18
+ }
19
+
20
+ export function contentPartsToOpenAIContent(contentParts: ContentPart[]): OpenAIContent {
21
+ if (contentParts.length === 1 && contentParts[0].type === "text") {
22
+ return textToOpenAIContent((contentParts[0] as TextContentPart).text);
23
+ }
24
+
25
+ return contentParts;
26
+ }
package/src/outbound.ts CHANGED
@@ -9,7 +9,8 @@ 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 type { ContentPart, TextContentPart, OpenAIContent } from "./types.js";
12
+ import { contentPartsToOpenAIContent, textToOpenAIContent } from "./content.js";
13
+ import type { ContentPart, OpenAIContent } from "./types.js";
13
14
 
14
15
  export const palzOutbound = {
15
16
  deliveryMode: "direct" as const,
@@ -35,10 +36,13 @@ export const palzOutbound = {
35
36
  const { senderId, lobsterId, conversationId, conversationType } = parsePalzTarget(to);
36
37
  log(`palz-outbound: [sendText] 解析: senderId="${senderId}" lobsterId="${lobsterId}" conversationId="${conversationId}" conversationType="${conversationType}" botId=${account.config.botId}`);
37
38
 
39
+ const content = textToOpenAIContent(text ?? "");
40
+ log(`palz-outbound: [sendText] 发送内容: type=${typeof content === "string" ? "string" : "array"} parts=${Array.isArray(content) ? content.length : 1}`);
41
+
38
42
  const result = await sendToPalzIM({
39
43
  config: account.config,
40
44
  conversationId,
41
- content: text,
45
+ content,
42
46
  senderId,
43
47
  conversationType,
44
48
  lobsterId,
@@ -75,10 +79,7 @@ export const palzOutbound = {
75
79
  }
76
80
  }
77
81
 
78
- const content: OpenAIContent =
79
- contentParts.length === 1 && contentParts[0].type === "text"
80
- ? (contentParts[0] as TextContentPart).text
81
- : contentParts;
82
+ const content: OpenAIContent = contentPartsToOpenAIContent(contentParts);
82
83
 
83
84
  log(`palz-outbound: [sendMedia] 发送内容: type=${typeof content === "string" ? "string" : "array"} parts=${Array.isArray(content) ? content.length : 1}`);
84
85
 
@@ -11,6 +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
  import { resolveToolDisplay, formatToolStartText, formatToolResultText, formatResultSummary } from "./tool-display.js";
15
16
  import type { PalzConfig, StreamChunkOpts, ContentPart, OpenAIContent } from "./types.js";
16
17
 
@@ -210,28 +211,43 @@ export function createPalzReplyDispatcher(params: CreatePalzReplyDispatcherParam
210
211
  }
211
212
 
212
213
  // Determine final content format
213
- const content: OpenAIContent =
214
- contentParts.length === 1 && contentParts[0].type === "text"
215
- ? (contentParts[0] as { type: "text"; text: string }).text
216
- : contentParts;
214
+ const content: OpenAIContent = contentPartsToOpenAIContent(contentParts);
217
215
 
218
- if (streamState && kind === "final" && typeof content === "string") {
219
- const delta = content.slice(streamState.lastSentLength);
216
+ if (streamState && kind === "final") {
220
217
  const seq = streamState.seq++;
221
- log(
222
- `${tag}: [DELIVER 流式最终] seq=${seq} totalLen=${content.length} deltaLen=${delta.length} delta="${delta.slice(0, 120)}"`,
223
- );
224
- await enqueueIMSend(
225
- content,
226
- {
227
- streamId: streamState.streamId,
228
- seq,
229
- isFinal: true,
230
- delta,
231
- },
232
- undefined,
233
- `final seq=${seq}`,
234
- );
218
+ if (typeof content === "string") {
219
+ const delta = content.slice(streamState.lastSentLength);
220
+ log(
221
+ `${tag}: [DELIVER 流式最终] seq=${seq} totalLen=${content.length} deltaLen=${delta.length} delta="${delta.slice(0, 120)}"`,
222
+ );
223
+ await enqueueIMSend(
224
+ content,
225
+ {
226
+ streamId: streamState.streamId,
227
+ seq,
228
+ isFinal: true,
229
+ delta,
230
+ },
231
+ undefined,
232
+ `final seq=${seq}`,
233
+ );
234
+ } else if (streamState.lastSentLength > 0) {
235
+ log(`${tag}: [DELIVER 流式最终] seq=${seq} contentType=array parts=${content.length} replaceStream=true`);
236
+ await enqueueIMSend(
237
+ content,
238
+ {
239
+ streamId: streamState.streamId,
240
+ seq,
241
+ isFinal: true,
242
+ delta: "",
243
+ },
244
+ undefined,
245
+ `final seq=${seq}`,
246
+ );
247
+ } else {
248
+ log(`${tag}: [DELIVER 非流式] contentType=array parts=${content.length}`);
249
+ await enqueueIMSend(content, undefined, undefined, "deliver");
250
+ }
235
251
  } else {
236
252
  log(`${tag}: [DELIVER 非流式] contentType=${typeof content === "string" ? "string" : "array"}`);
237
253
  await enqueueIMSend(content, undefined, undefined, "deliver");