fix(webui): recognize typed session handles as references (#6311)

* fix(webui): recognize typed session handles as references

Refs NAN-286

* refactor(webui): simplify session reference handling

* fix(webui): recognize mentions after punctuation

* docs(webui): focus topic references on usage
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-20 01:05:11 +08:00
1 parent 1f8e49c70a
commit 909b277e7a
7 files changed
+369 -144

No files matched your search

+9 -5
View File
@@ -10,7 +10,11 @@ import { logoFallbackUrls } from "@/lib/provider-brand";
import { sessionHandleColor } from "@/lib/session-handle";
import type { CliAppInfo, McpPresetInfo, SessionMention } from "@/lib/types";
import { cn } from "@/lib/utils";
import { composerMentionLabel, type CapabilityMentionSegment } from "@/lib/composer-mention-text";
import {
composerMentionLabel,
isCapabilityMentionStart,
type CapabilityMentionSegment,
} from "@/lib/composer-mention-text";
// Paint-only weight keeps the native textarea's regular-width caret and wrapping in sync.
const COMPOSER_BRAND_NAME_CLASS = "[-webkit-text-stroke:0.4px_currentColor]";
@@ -64,19 +68,19 @@ export function splitCapabilityMentionSegments(
}
const segments: CapabilityMentionSegment[] = [];
const mentionRe = /(^|[\s([{])@([\p{L}\p{N}_-]+)(?=$|[^\p{L}\p{N}_-])/giu;
const mentionRe = /@([\p{L}\p{N}_-]+)(?=$|[^\p{L}\p{N}_-])/giu;
let cursor = 0;
let match: RegExpExecArray | null;
while ((match = mentionRe.exec(value)) !== null) {
const prefix = match[1] ?? "";
const name = match[2] ?? "";
if (!isCapabilityMentionStart(value, match.index)) continue;
const name = match[1] ?? "";
const key = name.toLowerCase();
const session = sessionsByName.get(key);
const app = session ? null : cliAppsByName.get(key);
const preset = session || app ? null : mcpPresetsByName.get(key);
if (!app && !preset && !session) continue;
const mentionStart = match.index + prefix.length;
const mentionStart = match.index;
const mentionEnd = mentionStart + name.length + 1;
if (mentionStart > cursor) {
segments.push({ kind: "text", text: value.slice(cursor, mentionStart) });