|
| 1 | +import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; |
1 | 2 | // Qa Matrix plugin module implements scenario runtime media behavior. |
2 | 3 | import type { MatrixQaObservedEvent } from "../../substrate/events.js"; |
3 | 4 | import { MATRIX_QA_MEDIA_ROOM_KEY, resolveMatrixQaScenarioRoomId } from "./scenario-catalog.js"; |
@@ -43,7 +44,7 @@ function buildMatrixQaAttachmentDetailLines(params: { |
43 | 44 | `${params.label} msgtype: ${params.attachmentEvent.msgtype ?? "<none>"}`, |
44 | 45 | `${params.label} attachment kind: ${params.attachmentEvent.attachment?.kind ?? "<none>"}`, |
45 | 46 | `${params.label} attachment filename: ${params.attachmentEvent.attachment?.filename ?? "<none>"}`, |
46 | | - `${params.label} body preview: ${params.attachmentEvent.body?.slice(0, 200) ?? "<none>"}`, |
| 47 | + `${params.label} body preview: ${params.attachmentEvent.body ? truncateUtf16Safe(params.attachmentEvent.body, 200) : "<none>"}`, |
47 | 48 | ]; |
48 | 49 | } |
49 | 50 |
|
@@ -124,7 +125,9 @@ export async function runImageUnderstandingAttachmentScenario(context: MatrixQaS |
124 | 125 | const reply = buildMatrixReplyArtifact(matched.event); |
125 | 126 | return { |
126 | 127 | artifacts: { |
127 | | - attachmentCaptionPreview: attachmentEvent.event.attachment?.caption?.slice(0, 200), |
| 128 | + attachmentCaptionPreview: attachmentEvent.event.attachment?.caption |
| 129 | + ? truncateUtf16Safe(attachmentEvent.event.attachment.caption, 200) |
| 130 | + : undefined, |
128 | 131 | attachmentFilename: MATRIX_QA_IMAGE_ATTACHMENT_FILENAME, |
129 | 132 | driverEventId, |
130 | 133 | reply, |
@@ -441,7 +444,9 @@ export async function runGeneratedImageDeliveryScenario(context: MatrixQaScenari |
441 | 444 | ); |
442 | 445 | return { |
443 | 446 | artifacts: { |
444 | | - attachmentBodyPreview: matchedEvent.body?.slice(0, 200), |
| 447 | + attachmentBodyPreview: matchedEvent.body |
| 448 | + ? truncateUtf16Safe(matchedEvent.body, 200) |
| 449 | + : undefined, |
445 | 450 | attachmentEventId: matchedEvent.eventId, |
446 | 451 | attachmentFilename: attachment.filename, |
447 | 452 | attachmentKind: attachment.kind, |
|
0 commit comments