后端 /api/skills 返回 Path.resolve() 字符串(Windows 为反斜杠),而 USER_SKILL_LINK_RE(ChatArea 气泡渲染)与 SKILL_MARKDOWN_LINK_RE(shared.ts 发送兜底提取)硬编码正斜杠 /.astrion/skills/,导致 / 菜单插入的 skill 引用在消息发出后 fallback 为原始文本。两处正则路径分隔符改 [\\/],对存量反斜杠消息同样生效(渲染侧修复)。@ 文件引用不受影响(路径段 [^)\\n]+ 本就能匹配反斜杠,已 Playwright 实测确认)。
27 lines
843 B
TypeScript
27 lines
843 B
TypeScript
// @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;
|
||
}
|
||
|