Fix structured IPC envelope leakage

Normalize EJClaw structured send_message envelopes, preserve attachments, unwrap stored room payloads, and add regression tests.
This commit is contained in:
Eyejoker
2026-04-28 01:35:26 +09:00
committed by GitHub
parent 20e1a1e5e1
commit 8bb77ffaa3
11 changed files with 291 additions and 14 deletions

View File

@@ -1,3 +1,8 @@
import {
normalizeEjclawStructuredOutput,
type RunnerOutputAttachment,
} from 'ejclaw-runners-shared';
export interface SendMessageIpcPayloadInput {
chatJid: string;
text: string;
@@ -8,17 +13,36 @@ export interface SendMessageIpcPayloadInput {
timestamp?: string;
}
export interface SendMessageIpcPayload {
type: 'message';
chatJid: string;
text: string;
sender?: string;
senderRole?: string;
runId?: string;
groupFolder: string;
timestamp: string;
attachments?: RunnerOutputAttachment[];
}
export function buildSendMessageIpcPayload(
input: SendMessageIpcPayloadInput,
): Record<string, string | undefined> {
): SendMessageIpcPayload {
const normalized = normalizeEjclawStructuredOutput(input.text);
const output =
normalized.output?.visibility === 'public' ? normalized.output : null;
const text = output?.text ?? normalized.result ?? '';
const attachments = output?.attachments ?? [];
return {
type: 'message',
chatJid: input.chatJid,
text: input.text,
text,
sender: input.sender || undefined,
senderRole: input.senderRole || undefined,
runId: input.runId || undefined,
groupFolder: input.groupFolder,
timestamp: input.timestamp || new Date().toISOString(),
...(attachments.length > 0 ? { attachments } : {}),
};
}