Skip to content

Commit 17ebd51

Browse files
zenglingbiaosteipete
authored andcommitted
fix(ui): preserve full graphemes in session owner initials
1 parent 3f9b242 commit 17ebd51

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎ui/src/components/session-owner-chip.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { html, nothing } from "lit";
22
import { property } from "lit/decorators.js";
33
import type { SessionCreatedActor as ProtocolSessionCreatedActor } from "../../../packages/gateway-protocol/src/schema/sessions.js";
44
import { t } from "../i18n/index.ts";
5+
import { takeGraphemes } from "../lib/graphemes.ts";
56
import { resolveAvatar } from "../lib/identity-avatar.ts";
67
import { OpenClawLightDomElement } from "../lit/openclaw-element.ts";
78
import "./viewer-facepile.ts";
@@ -66,8 +67,11 @@ function ownerInitials(createdActor: SessionCreatedActor): string {
6667
.replace(/@.*$/u, "")
6768
.split(/[\s._-]+/u)
6869
.filter(Boolean);
69-
const initials = ((parts[0]?.[0] ?? "") + (parts[1]?.[0] ?? "")).toUpperCase();
70-
return initials || source[0]!.toUpperCase();
70+
// Grapheme clusters, not UTF-16 units or bare code points: emoji display names
71+
// must render their complete visible initial (no lone surrogates or split ZWJ sequences).
72+
const firstChar = (value: string | undefined): string => (value ? takeGraphemes(value, 1) : "");
73+
const initials = (firstChar(parts[0]) + firstChar(parts[1])).toUpperCase();
74+
return initials || firstChar(source).toUpperCase();
7175
}
7276

7377
// Deterministic hue per identity so a person keeps one color everywhere.

‎ui/src/test-helpers/app-sidebar-cases/session-ownership.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,38 @@ describe("AppSidebar session ownership", () => {
130130
expect(carolChip?.textContent?.trim()).toBe("C");
131131
});
132132

133+
it("keeps emoji display-name initials as whole grapheme clusters", async () => {
134+
for (const { label, expected } of [
135+
{ label: "🦞小明", expected: "🦞" },
136+
{ label: "👨‍👩‍👧‍👦Family", expected: "👨‍👩‍👧‍👦" },
137+
]) {
138+
const gateway = createGateway({} as GatewayBrowserClient);
139+
const harness = createSessionsHarness("main", ["agent:main:main", "agent:main:lobster"]);
140+
const result = harness.sessions.state.result;
141+
if (!result) {
142+
throw new Error("expected session list");
143+
}
144+
const lobster = result.sessions.find((row) => row.key.endsWith(":lobster"));
145+
if (!lobster) {
146+
throw new Error("expected creator row");
147+
}
148+
lobster.createdActor = { type: "human", id: "profile-lobster", label };
149+
result.creators = [
150+
{ id: "profile-lobster", label },
151+
{ id: "profile-ada", label: "Ada" },
152+
];
153+
154+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
155+
harness.publishList({ result, agentId: "main" });
156+
await sidebar.updateComplete;
157+
158+
const chip = sidebar.querySelector(
159+
'[data-session-key="agent:main:lobster"] .session-owner-chip',
160+
);
161+
expect(chip?.textContent?.trim()).toBe(expected);
162+
}
163+
});
164+
133165
it("uses the complete facet and requests unloaded creators from the Gateway", async () => {
134166
const gateway = createGateway({} as GatewayBrowserClient);
135167
const harness = createSessionsHarness("main", ["agent:main:main", "agent:main:ada"]);

0 commit comments

Comments
 (0)