palz-connector 1.4.2 → 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.
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/bot.ts +3 -0
- package/src/content.ts +26 -0
- package/src/outbound.ts +7 -6
- package/src/reply-dispatcher.ts +36 -20
- package/src/types.ts +2 -0
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -548,6 +548,9 @@ async function _dispatchPalzMessageInner(params: HandlePalzMessageParams): Promi
|
|
|
548
548
|
if (msg.lobster_name) {
|
|
549
549
|
untrustedContext.push(`lobster_name: ${msg.lobster_name}`);
|
|
550
550
|
}
|
|
551
|
+
if (msg.lobster_type) {
|
|
552
|
+
untrustedContext.push(`lobster_type: ${msg.lobster_type}`);
|
|
553
|
+
}
|
|
551
554
|
if (msg.sender_account_type) {
|
|
552
555
|
untrustedContext.push(`sender_account_type: ${msg.sender_account_type}`);
|
|
553
556
|
}
|
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
|
|
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
|
|
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
|
|
package/src/reply-dispatcher.ts
CHANGED
|
@@ -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"
|
|
219
|
-
const delta = content.slice(streamState.lastSentLength);
|
|
216
|
+
if (streamState && kind === "final") {
|
|
220
217
|
const seq = streamState.seq++;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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");
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface PalzMessageEvent {
|
|
|
45
45
|
resource_id?: string;
|
|
46
46
|
/** Lobster 名称,由 IM 下发 */
|
|
47
47
|
lobster_name?: string;
|
|
48
|
+
/** Lobster 类型,由 IM 下发 */
|
|
49
|
+
lobster_type?: string;
|
|
48
50
|
/** 发送者账号类型,由 IM 下发 */
|
|
49
51
|
sender_account_type?: string;
|
|
50
52
|
/** W3C Trace Context traceparent,由 IM 上游传递 */
|