fix(webui): unify skill and session link highlighting (#6454)
* fix(webui): refine skill reference highlighting * fix(webui): highlight composer skills and align session links
This commit is contained in:
1 parent
d14c54c31c
commit
424d2debc2
12 files changed
+305
-91
No files matched your search
@@ -1,70 +1,11 @@
|
||||
import { Fragment } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
CapabilityMentionToken,
|
||||
splitCapabilityMentionSegments,
|
||||
} from "@/components/CliAppMentionText";
|
||||
import {
|
||||
INLINE_TOKEN_HIGHLIGHT_COLOR,
|
||||
InlineTokenHighlight,
|
||||
} from "@/components/InlineTokenHighlight";
|
||||
import { SkillReferenceToken, withSkillReferences } from "@/components/SkillReferenceText";
|
||||
import type { CliAppInfo, McpPresetInfo, SessionMention } from "@/lib/types";
|
||||
import type { CapabilityMentionSegment } from "@/lib/composer-mention-text";
|
||||
|
||||
type SkillReferenceSegment =
|
||||
| { kind: "text"; text: string }
|
||||
| { kind: "skill"; text: string; name: string };
|
||||
|
||||
type UserMessageSegment =
|
||||
| CapabilityMentionSegment
|
||||
| { kind: "skill"; text: string; name: string };
|
||||
|
||||
function splitSkillReferenceSegments(value: string): SkillReferenceSegment[] {
|
||||
if (!value) return [];
|
||||
const segments: SkillReferenceSegment[] = [];
|
||||
const referenceRe = /\$([A-Za-z0-9_-]+)/g;
|
||||
let cursor = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = referenceRe.exec(value)) !== null) {
|
||||
const name = match[1] ?? "";
|
||||
if (match.index > cursor) {
|
||||
segments.push({ kind: "text", text: value.slice(cursor, match.index) });
|
||||
}
|
||||
segments.push({
|
||||
kind: "skill",
|
||||
text: value.slice(match.index, referenceRe.lastIndex),
|
||||
name,
|
||||
});
|
||||
cursor = referenceRe.lastIndex;
|
||||
}
|
||||
if (cursor < value.length) {
|
||||
segments.push({ kind: "text", text: value.slice(cursor) });
|
||||
}
|
||||
return segments.length ? segments : [{ kind: "text", text: value }];
|
||||
}
|
||||
|
||||
function splitUserMessageSegments(
|
||||
value: string,
|
||||
cliApps: CliAppInfo[],
|
||||
mcpPresets: McpPresetInfo[],
|
||||
sessionMentions: SessionMention[],
|
||||
): UserMessageSegment[] {
|
||||
const segments: UserMessageSegment[] = [];
|
||||
for (const segment of splitCapabilityMentionSegments(
|
||||
value,
|
||||
cliApps,
|
||||
mcpPresets,
|
||||
sessionMentions,
|
||||
)) {
|
||||
if (segment.kind === "text") {
|
||||
segments.push(...splitSkillReferenceSegments(segment.text));
|
||||
} else {
|
||||
segments.push(segment);
|
||||
}
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function UserMessageText({
|
||||
text,
|
||||
@@ -77,8 +18,9 @@ export function UserMessageText({
|
||||
mcpPresets: McpPresetInfo[];
|
||||
sessionMentions?: SessionMention[];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const segments = splitUserMessageSegments(text, cliApps, mcpPresets, sessionMentions);
|
||||
const segments = withSkillReferences(
|
||||
splitCapabilityMentionSegments(text, cliApps, mcpPresets, sessionMentions),
|
||||
);
|
||||
return (
|
||||
<>
|
||||
{segments.map((segment, index) => {
|
||||
@@ -86,14 +28,11 @@ export function UserMessageText({
|
||||
return <Fragment key={`text-${index}`}>{segment.text}</Fragment>;
|
||||
}
|
||||
if (segment.kind === "skill") return (
|
||||
<InlineTokenHighlight
|
||||
<SkillReferenceToken
|
||||
key={`skill-${segment.name}-${index}`}
|
||||
name={segment.name}
|
||||
testId={`message-skill-reference-${segment.name.toLowerCase()}`}
|
||||
title={t("message.skill", { name: segment.name })}
|
||||
color={INLINE_TOKEN_HIGHLIGHT_COLOR}
|
||||
>
|
||||
{segment.text}
|
||||
</InlineTokenHighlight>
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<CapabilityMentionToken
|
||||
|
||||
Reference in new issue
Block a user