Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: resolve @mention overlap rendering in chat input

Guse91e9e284e9d
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index c149afce9..89d370dc3 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -951,18 +951,18 @@
.textarea-text-hidden {
-webkit-text-fill-color: transparent;
color: transparent;
+ -webkit-font-smoothing: antialiased;
}
.chat-input-line-height {
line-height: 24px;
}
-/* Mention highlight — underline + italic */
+/* Mention highlight — underline */
.mention-highlight {
text-decoration: underline;
text-decoration-color: var(--foreground);
text-underline-offset: 2px;
text-decoration-thickness: 1.5px;
- font-style: italic;
}
.markdown-user .mention-highlight {
text-decoration-color: var(--primary-foreground);
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index 3efdede09..db61ce7af 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -60,7 +60,8 @@ function MentionHighlight(props: Record<string, unknown> & { children?: React.Re
const agentId = (rest["data-agent-id"] ?? rest.dataAgentId) as string | undefined;
let agent = agentId ? agents.find((a) => a.id === agentId) : undefined;
if (!agent && typeof children === "string") {
- agent = agents.find((a) => a.name.toLowerCase() === children.toLowerCase());
+ const nameToMatch = children.startsWith("@") ? children.slice(1) : children;
+ agent = agents.find((a) => a.name.toLowerCase() === nameToMatch.toLowerCase());
}
if (agent) {
return (
diff --git a/src/web/src/lib/highlight-mentions.test.ts b/src/web/src/lib/highlight-mentions.test.ts
index 31659601c..db4fdee7a 100644
--- a/src/web/src/lib/highlight-mentions.test.ts
+++ b/src/web/src/lib/highlight-mentions.test.ts
@@ -24,12 +24,12 @@ const agent = (name: string, email_handle: string | null = null): Agent => ({
describe("highlightMentions", () => {
it("wraps basic @AgentName with data-agent-id", () => {
const result = highlightMentions("Hey @TestBot do this", [agent("TestBot", "testbot")])
- expect(result).toBe('Hey @<mention data-agent-id="ag_testbot">TestBot</mention> do this')
+ expect(result).toBe('Hey <mention data-agent-id="ag_testbot">@TestBot</mention> do this')
})
it("wraps only name portion of enriched form", () => {
const result = highlightMentions("Hey @TestBot ([email protected]) do this", [agent("TestBot", "testbot")])
- expect(result).toBe('Hey @<mention data-agent-id="ag_testbot">TestBot</mention> ([email protected]) do this')
+ expect(result).toBe('Hey <mention data-agent-id="ag_testbot">@TestBot</mention> ([email protected]) do this')
})
it("leaves non-matching @ as plain text", () => {
@@ -39,7 +39,7 @@ describe("highlightMentions", () => {
it("wraps multiple mentions with correct agent ids", () => {
const result = highlightMentions("@Alpha and @Beta", [agent("Alpha", "alpha"), agent("Beta", "beta")])
- expect(result).toBe('@<mention data-agent-id="ag_alpha">Alpha</mention> and @<mention data-agent-id="ag_beta">Beta</mention>')
+ expect(result).toBe('<mention data-agent-id="ag_alpha">@Alpha</mention> and <mention data-agent-id="ag_beta">@Beta</mention>')
})
it("does not wrap unknown agent names", () => {
@@ -67,6 +67,6 @@ describe("highlightMentions", () => {
const result = highlightMentions("@Alice talk to @Bob", agents)
expect(result).toContain('data-agent-id="ag_alice"')
expect(result).toContain('data-agent-id="ag_bob"')
- expect(result).toBe('@<mention data-agent-id="ag_alice">Alice</mention> talk to @<mention data-agent-id="ag_bob">Bob</mention>')
+ expect(result).toBe('<mention data-agent-id="ag_alice">@Alice</mention> talk to <mention data-agent-id="ag_bob">@Bob</mention>')
})
})
diff --git a/src/web/src/lib/highlight-mentions.ts b/src/web/src/lib/highlight-mentions.ts
index 504d02808..c39e28c48 100644
--- a/src/web/src/lib/highlight-mentions.ts
+++ b/src/web/src/lib/highlight-mentions.ts
@@ -62,8 +62,8 @@ export function highlightMentions(content: string, agents: Agent[]): string {
let result = content
for (let i = matches.length - 1; i >= 0; i--) {
const m = matches[i]
- const name = result.slice(m.start + 1, m.end)
- result = result.slice(0, m.start) + `@<mention data-agent-id="${m.agentId}">${name}</mention>` + result.slice(m.end)
+ const name = result.slice(m.start, m.end)
+ result = result.slice(0, m.start) + `<mention data-agent-id="${m.agentId}">${name}</mention>` + result.slice(m.end)
}
return result