-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Extract page content and send to AI assistant
- Loading branch information
1 parent
660ba3a
commit f96535e
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const cleanContent = (content: string) => { | ||
return content.replace(/^\d+\s+/gm, '').trim(); | ||
}; | ||
|
||
export const extractPageContent = () => { | ||
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} | ||
`; | ||
|
||
return { | ||
extractedContent, | ||
message: `Why this result?\n${extractedContent}`, | ||
}; | ||
}; |