Merge branch 'main' into FEAT_BoltDYI_NEW_SETTINGS_UI_V2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { Message } from 'ai';
|
||||
import { generateId } from './fileUtils';
|
||||
import { detectProjectCommands, createCommandsMessage } from './projectCommands';
|
||||
import { detectProjectCommands, createCommandsMessage, escapeBoltTags } from './projectCommands';
|
||||
|
||||
export const createChatFromFolder = async (
|
||||
files: File[],
|
||||
@@ -42,7 +42,7 @@ export const createChatFromFolder = async (
|
||||
${fileArtifacts
|
||||
.map(
|
||||
(file) => `<boltAction type="file" filePath="${file.path}">
|
||||
${file.content}
|
||||
${escapeBoltTags(file.content)}
|
||||
</boltAction>`,
|
||||
)
|
||||
.join('\n\n')}
|
||||
|
||||
@@ -61,7 +61,13 @@ const rehypeSanitizeOptions: RehypeSanitizeOptions = {
|
||||
tagNames: allowedHTMLElements,
|
||||
attributes: {
|
||||
...defaultSchema.attributes,
|
||||
div: [...(defaultSchema.attributes?.div ?? []), 'data*', ['className', '__boltArtifact__']],
|
||||
div: [
|
||||
...(defaultSchema.attributes?.div ?? []),
|
||||
'data*',
|
||||
['className', '__boltArtifact__', '__boltThought__'],
|
||||
|
||||
// ['className', '__boltThought__']
|
||||
],
|
||||
},
|
||||
strip: [],
|
||||
};
|
||||
|
||||
@@ -78,3 +78,39 @@ ${commands.setupCommand}
|
||||
createdAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
export function escapeBoltArtifactTags(input: string) {
|
||||
// Regular expression to match boltArtifact tags and their content
|
||||
const regex = /(<boltArtifact[^>]*>)([\s\S]*?)(<\/boltArtifact>)/g;
|
||||
|
||||
return input.replace(regex, (match, openTag, content, closeTag) => {
|
||||
// Escape the opening tag
|
||||
const escapedOpenTag = openTag.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
// Escape the closing tag
|
||||
const escapedCloseTag = closeTag.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
// Return the escaped version
|
||||
return `${escapedOpenTag}${content}${escapedCloseTag}`;
|
||||
});
|
||||
}
|
||||
|
||||
export function escapeBoltAActionTags(input: string) {
|
||||
// Regular expression to match boltArtifact tags and their content
|
||||
const regex = /(<boltAction[^>]*>)([\s\S]*?)(<\/boltAction>)/g;
|
||||
|
||||
return input.replace(regex, (match, openTag, content, closeTag) => {
|
||||
// Escape the opening tag
|
||||
const escapedOpenTag = openTag.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
// Escape the closing tag
|
||||
const escapedCloseTag = closeTag.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
// Return the escaped version
|
||||
return `${escapedOpenTag}${content}${escapedCloseTag}`;
|
||||
});
|
||||
}
|
||||
|
||||
export function escapeBoltTags(input: string) {
|
||||
return escapeBoltArtifactTags(escapeBoltAActionTags(input));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user