@@ -303,7 +319,14 @@ export const EditorScreen = () => {
return;
}}
theme={monokai}
- extensions={[basicSetup, javascriptLanguage, indentUnit.of(' '), EditorView.lineWrapping, EditorView.editable.of(false)]}
+ extensions={[
+ basicSetup,
+ javascriptLanguage,
+ indentUnit.of(' '),
+ EditorView.lineWrapping,
+ EditorView.editable.of(false),
+ buttonPlugin(openDrawerWithMessage, extractContent, 'enforcementResult'),
+ ]}
basicSetup={{
lineNumbers: true,
highlightActiveLine: true,
@@ -365,9 +388,7 @@ export const EditorScreen = () => {
} else if (Array.isArray(v)) {
const formattedResults = v.map((res) => {
if (typeof res === 'object') {
- const reasonString = Array.isArray(res.reason) && res.reason.length > 0
- ? ` Reason: ${JSON.stringify(res.reason)}`
- : '';
+ const reasonString = Array.isArray(res.reason) && res.reason.length > 0 ? ` Reason: ${JSON.stringify(res.reason)}` : '';
return `${res.okEx}${reasonString}`;
}
return res;
diff --git a/app/utils/contentExtractor.ts b/app/utils/contentExtractor.ts
new file mode 100644
index 0000000..d74685a
--- /dev/null
+++ b/app/utils/contentExtractor.ts
@@ -0,0 +1,56 @@
+const cleanContent = (content: string) => {
+ return content.replace(/^\d+\s+/gm, '').trim();
+};
+
+export const extractPageContent = (boxType: string) => {
+ const mainContent = document.querySelector('main')?.innerText || 'No main content found';
+
+ const customConfigMatch = mainContent.match(/Custom config\s+([\s\S]*?)\s+Model/);
+ const modelMatch = mainContent.match(/Model\s+([\s\S]*?)\s+Policy/);
+ const policyMatch = mainContent.match(/Policy\s+([\s\S]*?)\s+Request/);
+ const requestMatch = mainContent.match(/Request\s+([\s\S]*?)\s+Enforcement Result/);
+ const enforcementResultMatch = mainContent.match(/Enforcement Result\s+([\s\S]*?)\s+SYNTAX VALIDATE/);
+
+ const customConfig = customConfigMatch ? cleanContent(customConfigMatch[1]) : 'No custom config found';
+ const model = modelMatch ? cleanContent(modelMatch[1].replace(/Select your model[\s\S]*?RESET/, '')) : 'No model found';
+ const policy = policyMatch ? cleanContent(policyMatch[1].replace(/Node-Casbin v[\d.]+/, '')) : 'No policy found';
+ const request = requestMatch ? cleanContent(requestMatch[1]) : 'No request found';
+ const enforcementResult = enforcementResultMatch
+ ? cleanContent(enforcementResultMatch[1].replace(/Why this result\?[\s\S]*?AI Assistant/, ''))
+ : 'No enforcement result found';
+
+ const extractedContent = `
+ Custom Config: ${customConfig}
+ Model: ${model}
+ Policy: ${policy}
+ Request: ${request}
+ Enforcement Result: ${enforcementResult}
+ `;
+
+ let message = '';
+ switch (boxType) {
+ case 'model':
+ message = `Briefly explain the Model content.
+ no need to repeat the content of the question.\n${extractedContent}`;
+ break;
+ case 'policy':
+ message = `Briefly explain the Policy content.
+ no need to repeat the content of the question.\n${extractedContent}`;
+ break;
+ case 'request':
+ message = `Briefly explain the Request content.
+ no need to repeat the content of the question.\n${extractedContent}`;
+ break;
+ case 'enforcementResult':
+ message = `Why this result? please provide a brief summary.
+ no need to repeat the content of the question.\n${extractedContent}`;
+ break;
+ default:
+ message = extractedContent;
+ }
+
+ return {
+ extractedContent,
+ message,
+ };
+};
diff --git a/public/openai.svg b/public/openai.svg
new file mode 100644
index 0000000..964273d
--- /dev/null
+++ b/public/openai.svg
@@ -0,0 +1 @@
+
\ No newline at end of file