|
4 | 4 | * blocks or plain prompt text. |
5 | 5 | */ |
6 | 6 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
7 | | -import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice"; |
| 7 | +import { truncateWithMarker } from "@openclaw/normalization-core/utf16-slice"; |
8 | 8 | import { |
9 | 9 | formatGeneratedAttachmentLines, |
10 | 10 | mediaUrlsFromGeneratedAttachments, |
@@ -109,16 +109,6 @@ function sanitizeSingleLineField(value: string, fallback: string): string { |
109 | 109 | return sanitized || fallback; |
110 | 110 | } |
111 | 111 |
|
112 | | -function truncateSingleLineField(value: string, maxChars: number, marker: string): string { |
113 | | - if (value.length <= maxChars) { |
114 | | - return value; |
115 | | - } |
116 | | - const keep = Math.max(0, maxChars - marker.length); |
117 | | - // truncateUtf16Safe never splits a surrogate pair, so astral characters in |
118 | | - // provider/lifecycle error text cannot leave a dangling half in the prompt. |
119 | | - return `${truncateUtf16Safe(value, keep).trimEnd()}${marker}`; |
120 | | -} |
121 | | - |
122 | 112 | function sanitizeMultilineField(value: string, fallback: string): string { |
123 | 113 | const sanitized = escapeInternalRuntimeContextDelimiters(value).replace(/\r\n/g, "\n").trim(); |
124 | 114 | return sanitized || fallback; |
@@ -169,10 +159,14 @@ function formatTaskCompletionEvent( |
169 | 159 | const sessionId = sanitizeSingleLineField(event.childSessionId ?? "unknown", "unknown"); |
170 | 160 | const announceType = sanitizeSingleLineField(event.announceType, "unknown"); |
171 | 161 | const taskLabel = sanitizeSingleLineField(event.taskLabel, "unnamed task"); |
172 | | - const statusLabel = truncateSingleLineField( |
| 162 | + const statusLabel = truncateWithMarker( |
173 | 163 | sanitizeSingleLineField(event.statusLabel, event.status), |
174 | 164 | MAX_TASK_COMPLETION_STATUS_LABEL_CHARS, |
175 | | - TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER, |
| 165 | + { |
| 166 | + marker: TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER, |
| 167 | + reserve: TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER.length, |
| 168 | + trimEnd: true, |
| 169 | + }, |
176 | 170 | ); |
177 | 171 | const result = formatChildResultDataBlock(event.result); |
178 | 172 | const attachmentLines = formatGeneratedAttachmentLines(event.attachments); |
|
0 commit comments