agent-Specialization/static/src/app/methods/message/shared.ts
JOJO ca0d87d9b9 fix(frontend): skill 引用渲染与提取兼容 Windows 反斜杠路径
后端 /api/skills 返回 Path.resolve() 字符串(Windows 为反斜杠),而 USER_SKILL_LINK_RE(ChatArea 气泡渲染)与 SKILL_MARKDOWN_LINK_RE(shared.ts 发送兜底提取)硬编码正斜杠 /.astrion/skills/,导致 / 菜单插入的 skill 引用在消息发出后 fallback 为原始文本。两处正则路径分隔符改 [\\/],对存量反斜杠消息同样生效(渲染侧修复)。@ 文件引用不受影响(路径段 [^)\\n]+ 本就能匹配反斜杠,已 Playwright 实测确认)。
2026-08-02 00:00:16 +08:00

27 lines
843 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// @ts-nocheck
// @ts-nocheck
import { debugLog } from '../common';
import { useModelStore } from '../../../stores/model';
// 兼容 Windows 反斜杠路径skills 目录与 SKILL.md 前的分隔符同时接受 / 和 \
export const SKILL_MARKDOWN_LINK_RE = /\[\$([^\]\n]+)\]\(([^)\n]*[\\/]\.astrion[\\/]skills[\\/][^)\n]+[\\/]SKILL\.md)\)/g;
export function extractSkillRefsFromMessage(message = '') {
const refs = [];
const seen = new Set();
const text = String(message || '');
let match;
SKILL_MARKDOWN_LINK_RE.lastIndex = 0;
while ((match = SKILL_MARKDOWN_LINK_RE.exec(text))) {
const name = String(match[1] || '').trim().replace(/^\$/, '');
const path = String(match[2] || '').trim();
if (!path || seen.has(path)) {
continue;
}
seen.add(path);
refs.push({ name, path });
}
return refs;
}