u
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
SUPPORTED_CATEGORIES,
|
||||
formatFileSize,
|
||||
} from './chatAttachments';
|
||||
import { stripUserEnv } from './userEnv';
|
||||
|
||||
const KNOWN_FILE_EXTENSIONS = new Set([
|
||||
'html', 'htm', 'csv', 'tsv', 'pdf', 'txt', 'text', 'md', 'markdown', 'log',
|
||||
@@ -199,20 +200,28 @@ export function parseAttachmentTag(attrString) {
|
||||
};
|
||||
}
|
||||
|
||||
export { stripUserEnv };
|
||||
|
||||
/**
|
||||
* Extract all `[ATTACHMENT ...]` markers and return clean text plus attachment metadata.
|
||||
* Also strips <USERENV> tags so route context is never rendered in chat views.
|
||||
* @param {string} rawText
|
||||
* @returns {{ attachments: Array<{ name: string, path: string, type: string, url: string }>, cleanText: string }}
|
||||
*/
|
||||
export function parseAttachmentsFromText(rawText) {
|
||||
if (typeof rawText !== 'string' || !rawText.includes('[ATTACHMENT')) {
|
||||
return { attachments: [], cleanText: rawText || '' };
|
||||
if (typeof rawText !== 'string') {
|
||||
return { attachments: [], cleanText: '' };
|
||||
}
|
||||
|
||||
const textWithoutUserEnv = stripUserEnv(rawText);
|
||||
if (!textWithoutUserEnv.includes('[ATTACHMENT')) {
|
||||
return { attachments: [], cleanText: textWithoutUserEnv };
|
||||
}
|
||||
|
||||
const attachments = [];
|
||||
const tagRegex = /\[ATTACHMENT\s+([^\]]+)\]/g;
|
||||
let match;
|
||||
while ((match = tagRegex.exec(rawText)) !== null) {
|
||||
while ((match = tagRegex.exec(textWithoutUserEnv)) !== null) {
|
||||
const parsed = parseAttachmentTag(match[1]);
|
||||
if (parsed.name || parsed.path) {
|
||||
attachments.push({
|
||||
@@ -222,7 +231,7 @@ export function parseAttachmentsFromText(rawText) {
|
||||
}
|
||||
}
|
||||
|
||||
const cleanText = rawText.replace(tagRegex, '').trim();
|
||||
const cleanText = textWithoutUserEnv.replace(tagRegex, '').trim();
|
||||
return { attachments, cleanText };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user