Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/build/ai-agent.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/ckeditor5_plugins/aiagent/src/aiagentservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ export default class AiAgentService {
engine: this.aiEngine,
editor: this.editor
};
// Add providers if engine is dxai and providers is set
if (this.aiEngine === 'dxai' && this.providers) {
// Add providers if engine is dxai and model is kavya-m1 (default model)
if (this.aiEngine === 'dxai' && this.aiModel === 'kavya-m1' && this.providers) {
config.providers = this.providers;
}
const llmCustom = new AIApi(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Filters:
* - Images: <img> tags and Markdown ![alt](url) syntax including reference-style (enabled by default)
* - Links: <a> tags and Markdown [text](url) syntax including reference-style (enabled by default)
* - Plain text URLs: Bare http(s):// URLs in text content (replaced with EXTERNAL_URL_REDACTED)
* - Iframes: All <iframe> tags are unconditionally removed (always enabled)
* - Dangerous elements: <object>, <embed>, <applet>, SVG <image> (always enabled)
*
Expand Down
41 changes: 40 additions & 1 deletion js/ckeditor5_plugins/aiagent/src/util/ai-output-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Filters:
* - Images: <img> tags and Markdown ![alt](url) syntax including reference-style (enabled by default)
* - Links: <a> tags and Markdown [text](url) syntax including reference-style (enabled by default)
* - Plain text URLs: Bare http(s):// URLs in text content (replaced with EXTERNAL_URL_REDACTED)
* - Iframes: All <iframe> tags are unconditionally removed (always enabled)
* - Dangerous elements: <object>, <embed>, <applet>, SVG <image> (always enabled)
*
Expand Down Expand Up @@ -51,6 +52,8 @@ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
const MAX_FILENAME_LENGTH = 50;
/** Default filename when extraction fails */
const DEFAULT_FILENAME = 'image';
/** Replacement text for blocked plain text URLs */
const REDACTED_URL_TEXT = 'EXTERNAL_URL_REDACTED';
// Regex patterns
const PATTERNS = {
/** Matches [refname]: url or [refname]: url "title" */
Expand All @@ -68,7 +71,12 @@ const PATTERNS = {
/** Detects HTML content */
htmlDetection: /<[^>]+>/,
/** Escapes regex special characters */
regexEscape: /[.*+?^${}()|[\]\\]/g
regexEscape: /[.*+?^${}()|[\]\\]/g,
/**
* Matches plain text URLs (http:// or https://)
* Captures URLs that are not already inside HTML attributes or markdown syntax.
*/
plainTextUrl: /https?:\/\/[^\s<>"')\]]+/gi
};
// ============================================================================
// Helper Functions
Expand Down Expand Up @@ -181,6 +189,21 @@ const getReplacementImageSrc = (originalUrl, config) => {
}
return PLACEHOLDER_IMAGE_URL + encodeURIComponent(extractFilename(originalUrl));
};
/**
* Filters plain text URLs in content.
* Replaces blocked URLs with EXTERNAL_URL_REDACTED.
* This handles URLs that aren't wrapped in <a> tags or markdown link syntax.
*/
const filterPlainTextUrls = (content, config, blockedUrls) => {
const regex = new RegExp(PATTERNS.plainTextUrl.source, 'gi');
return content.replace(regex, (url) => {
if (shouldBlockLinkUrl(url, config)) {
recordBlockedUrl(blockedUrls, url, 'link');
return REDACTED_URL_TEXT;
}
return url;
});
};
/**
* Parses reference-style definitions from Markdown content.
*/
Expand Down Expand Up @@ -246,6 +269,20 @@ const filterHtmlContent = (html, config, blockedUrls) => {
anchor.setAttribute('href', '#');
}
});
// Filter plain text URLs in text nodes
const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT, null);
const textNodes = [];
let node;
while ((node = walker.nextNode())) {
textNodes.push(node);
}
textNodes.forEach(textNode => {
const text = textNode.textContent || '';
const filtered = filterPlainTextUrls(text, config, blockedUrls);
if (filtered !== text) {
textNode.textContent = filtered;
}
});
return doc.body.innerHTML;
};
// ============================================================================
Expand Down Expand Up @@ -318,6 +355,8 @@ const filterMarkdownContent = (markdown, config, blockedUrls) => {
filtered = filterMarkdownReference(filtered, PATTERNS.markdownRefLink, references, config, false, blockedUrls);
// Clean up orphaned reference definitions
filtered = cleanupMarkdownReferences(filtered, markdown, config);
// Filter plain text URLs (not in markdown syntax)
filtered = filterPlainTextUrls(filtered, config, blockedUrls);
return filtered;
};
// ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@ckeditor/ckeditor5-utils": "^45.0.0",
"@dxpr/ckeditor5-ai-agent": "^1.1.1",
"@dxpr/ckeditor5-ai-agent": "^1.1.2",
"sbd": "^1.0.19"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,10 @@
resolved "https://registry.npmjs.org/@dual-bundle/import-meta-resolve/-/import-meta-resolve-4.1.0.tgz"
integrity sha512-+nxncfwHM5SgAtrVzgpzJOI1ol0PkumhVo469KCf9lUi21IGcY90G98VuHm9VRrUypmAzawAHO9bs6hqeADaVg==

"@dxpr/ckeditor5-ai-agent@^1.1.1":
version "1.1.1"
resolved "https://registry.npmjs.org/@dxpr/ckeditor5-ai-agent/-/ckeditor5-ai-agent-1.1.1.tgz"
integrity sha512-YIoNcsimwPqmw80iCve1pbLnkpWbVaGDnbhx+6Z5IXpEnyGyeeUyq1QlAHk1M2LjA+DxfkoIOWXKrjWdfiTdXg==
"@dxpr/ckeditor5-ai-agent@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@dxpr/ckeditor5-ai-agent/-/ckeditor5-ai-agent-1.1.2.tgz"
integrity sha512-hL2JS+uQ1CCRrZRAZBA3JE28aE6r0h7aEQ6uLr53tmJs8dY7eINwCIuZQ1mLHqtr+fUFnB43mt9IxdLDOWQ+4Q==
dependencies:
"@ckeditor/ckeditor5-core" "^46.0.0"
"@ckeditor/ckeditor5-utils" "^46.0.0"
Expand Down