The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(shared): long assistant quote chips no longer end in a broken character (#30367)
spoukyii committed
Nov 5, 2026 at 20:25 UTC
66a2f35711a37e084803189a6089758a2f860650
2 files changed
+15
-1
packages/shared/src/assistantCitations.test.ts
+7
@@ -9,6 +9,7 @@ import {
9
type AssistantCitation,
10
} from "@t3tools/contracts";
11
import {
12
+ assistantCitationLabel,
13
assistantCitationsToPlainText,
14
collectAssistantCitations,
15
expandAssistantCitationsForProvider,
@@ -229,6 +230,12 @@ describe("assistant citation references", () => {
230
);
231
});
232
233
+ it("shortens a long quote label without splitting an emoji", () => {
234
+ expect(assistantCitationLabel({ ...citation, text: `${"a".repeat(63)}😀 and more` })).toBe(
235
+ `${"a".repeat(63)}…`,
236
+ );
237
+ });
238
+
239
it("replaces each marker once, including adjacent and repeated citations", () => {
240
const second = { ...citation, text: "A second quote: $& $1 $$" };
241
const marker = serializeAssistantCitation(citation);
packages/shared/src/assistantCitations.ts
+8
-1
@@ -98,7 +98,14 @@ export function parseAssistantCitationHref(href: string): AssistantCitation | nu
98
99
export function assistantCitationLabel(citation: AssistantCitation): string {
100
const preview = (citation.comment?.trim() || citation.text).replace(/\s+/g, " ");
101
- return preview.length > 64 ? `${preview.slice(0, 64)}…` : preview;
101
+ if (preview.length <= 64) return preview;
102
+ let end = 64;
103
+ const previous = preview.charCodeAt(end - 1);
104
+ const next = preview.charCodeAt(end);
105
+ if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
106
+ end -= 1;
107
+ }
108
+ return `${preview.slice(0, end)}…`;
109
}
110
111
export function serializeAssistantCitation(citation: AssistantCitation): string {