@@ -107,7 +107,7 @@ import {
107107} from "../routing/session-key.js" ;
108108import { defaultRuntime , type RuntimeEnv } from "../runtime.js" ;
109109import { createLazyRuntimeModule } from "../shared/lazy-runtime.js" ;
110- import { escapeRegExp } from "../utils.js" ;
110+ import { escapeRegExp , truncateUtf16Safe } from "../utils.js" ;
111111import { MAX_SAFE_TIMEOUT_DELAY_MS , resolveSafeTimeoutDelayMs } from "../utils/timer-delay.js" ;
112112import { loadOrCreateDeviceIdentity } from "./device-identity.js" ;
113113import { formatErrorMessage , hasErrnoCode } from "./errors.js" ;
@@ -2007,7 +2007,7 @@ export async function runHeartbeatOnce(opts: {
20072007 emitHeartbeatEvent ( {
20082008 status : "ok-token" ,
20092009 reason : opts . reason ,
2010- preview : heartbeatToolResponse . summary . slice ( 0 , 200 ) ,
2010+ preview : truncateUtf16Safe ( heartbeatToolResponse . summary , 200 ) ,
20112011 durationMs : Date . now ( ) - startedAt ,
20122012 channel : delivery . channel !== "none" ? delivery . channel : undefined ,
20132013 accountId : delivery . accountId ,
@@ -2161,7 +2161,7 @@ export async function runHeartbeatOnce(opts: {
21612161 emitHeartbeatEvent ( {
21622162 status : "skipped" ,
21632163 reason : "duplicate" ,
2164- preview : normalized . text . slice ( 0 , 200 ) ,
2164+ preview : truncateUtf16Safe ( normalized . text , 200 ) ,
21652165 durationMs : Date . now ( ) - startedAt ,
21662166 hasMedia : false ,
21672167 channel : delivery . channel !== "none" ? delivery . channel : undefined ,
@@ -2190,7 +2190,7 @@ export async function runHeartbeatOnce(opts: {
21902190 emitHeartbeatEvent ( {
21912191 status : "skipped" ,
21922192 reason : delivery . reason ?? "no-target" ,
2193- preview : previewText ?. slice ( 0 , 200 ) ,
2193+ preview : previewText != null ? truncateUtf16Safe ( previewText , 200 ) : undefined ,
21942194 durationMs : Date . now ( ) - startedAt ,
21952195 hasMedia : mediaUrls . length > 0 ,
21962196 accountId : delivery . accountId ,
@@ -2210,7 +2210,7 @@ export async function runHeartbeatOnce(opts: {
22102210 emitHeartbeatEvent ( {
22112211 status : "skipped" ,
22122212 reason : "alerts-disabled" ,
2213- preview : previewText ?. slice ( 0 , 200 ) ,
2213+ preview : previewText != null ? truncateUtf16Safe ( previewText , 200 ) : undefined ,
22142214 durationMs : Date . now ( ) - startedAt ,
22152215 channel : delivery . channel ,
22162216 hasMedia : mediaUrls . length > 0 ,
@@ -2233,7 +2233,7 @@ export async function runHeartbeatOnce(opts: {
22332233 emitHeartbeatEvent ( {
22342234 status : "skipped" ,
22352235 reason : readiness . reason ,
2236- preview : previewText ?. slice ( 0 , 200 ) ,
2236+ preview : previewText != null ? truncateUtf16Safe ( previewText , 200 ) : undefined ,
22372237 durationMs : Date . now ( ) - startedAt ,
22382238 hasMedia : mediaUrls . length > 0 ,
22392239 channel : delivery . channel ,
@@ -2317,7 +2317,7 @@ export async function runHeartbeatOnce(opts: {
23172317 to : delivery . to ,
23182318 ...( deliveredAgentRunFailure ? { reason : "agent-runner-failure" } : { } ) ,
23192319 ...( ! deliveredAgentRunFailure && ! visibleSendSucceeded ? { reason : send . reason } : { } ) ,
2320- preview : previewText ?. slice ( 0 , 200 ) ,
2320+ preview : previewText != null ? truncateUtf16Safe ( previewText , 200 ) : undefined ,
23212321 durationMs : Date . now ( ) - startedAt ,
23222322 hasMedia : mediaUrls . length > 0 ,
23232323 channel : delivery . channel ,
0 commit comments