Skip to content
TypeScript

fix(client-runtime): subagent previews no longer end in a broken character (#30391)

spoukyii6f51361a279f
diff --git a/packages/client-runtime/src/state/subagentDisplay.test.ts b/packages/client-runtime/src/state/subagentDisplay.test.ts
index 5bdd434388e..9b1536a7aac 100644
--- a/packages/client-runtime/src/state/subagentDisplay.test.ts
+++ b/packages/client-runtime/src/state/subagentDisplay.test.ts
@@ -36,6 +36,6 @@ it("normalizes Unicode whitespace and ignores a large hidden suffix", () => {
subagentDetailPreview({ status: "running", progress: "\uFEFF\u2029", result: " Done " }),
).toBe("Done");
expect(subagentDetailPreview({ status: "failed", result: "x".repeat(279) + "😀" })).toBe(
- "x".repeat(279) + "\uD83D…",
+ "x".repeat(279) + "…",
);
});
diff --git a/packages/client-runtime/src/state/subagentDisplay.ts b/packages/client-runtime/src/state/subagentDisplay.ts
index c0763fa4c2f..1968f48b90a 100644
--- a/packages/client-runtime/src/state/subagentDisplay.ts
+++ b/packages/client-runtime/src/state/subagentDisplay.ts
@@ -134,7 +134,15 @@ export function subagentDetailPreview(input: {
if (compact.length > 0) compact += " ";
}
compact += detail[index];
- if (compact.length > 280) return `${compact.slice(0, 280).trimEnd()}…`;
+ if (compact.length > 280) {
+ let end = 280;
+ const previous = compact.charCodeAt(end - 1);
+ const next = compact.charCodeAt(end);
+ if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
+ end -= 1;
+ }
+ return `${compact.slice(0, end).trimEnd()}…`;
+ }
}
return compact || null;
}