parent
4c843e9b5f
commit
ad70e5ed0a
@ -1,29 +1,45 @@ |
||||
// interactive code explaining and highlight security vunerabilities
|
||||
import * as fs from 'fs'; |
||||
|
||||
class CodeExplainAgent { |
||||
export class CodeExplainAgent { |
||||
private codebase: string[]; // list of code base file
|
||||
public currentFile: string; |
||||
plugin |
||||
|
||||
constructor(props) { |
||||
this.plugin = props |
||||
|
||||
constructor(codebasePath: string) { |
||||
// git or fs
|
||||
this.codebase = this.loadCodebase(codebasePath); |
||||
const codebase = this.loadCodebase("codebasePath"); |
||||
} |
||||
|
||||
private loadCodebase(path: string): string[] { |
||||
const files = fs.readdirSync(path); |
||||
return files |
||||
.filter(file => file.endsWith('.ts')) |
||||
.flatMap(file => fs.readFileSync(`${path}/${file}`, 'utf-8').split('\n')); |
||||
return [] |
||||
} |
||||
|
||||
public update(currentFile, lineNumber){ |
||||
|
||||
} |
||||
|
||||
async chatCommand(prompt:string){ |
||||
// change this function with indexer or related
|
||||
try{ |
||||
if (prompt.includes('Explain briefly the current file')){ |
||||
const file = await this.plugin.call('fileManager', 'getCurrentFile') |
||||
const content = `Explain this code:\n ${await this.plugin.call('fileManager', 'readFile', file)}` |
||||
return content |
||||
} else return prompt |
||||
} catch { |
||||
console.log('There is No file selected') |
||||
return 'There is No file selected' |
||||
} |
||||
} |
||||
|
||||
public getExplanations(currentLine: string, numSuggestions: number = 3): string[] { |
||||
// process the code base explaining the current file and highlight some details
|
||||
const suggestions: string[] = []; |
||||
return suggestions; |
||||
} |
||||
} |
||||
|
||||
// Handle file changed (significantly)
|
||||
|
@ -1,61 +1,61 @@ |
||||
import { ChatHistory } from '../prompts/chat'; |
||||
import { JsonStreamParser} from '../types/types' |
||||
import { JsonStreamParser } from '../types/types' |
||||
|
||||
export const HandleSimpleResponse = async (response, |
||||
cb?: (streamText: string) => void) => { |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
cb?: (streamText: string) => void) => { |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
|
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(response); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(response); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
} |
||||
} |
||||
|
||||
export const HandleStreamResponse = async (streamResponse, |
||||
cb?: (streamText: string) => void, |
||||
done_cb?: (result: string) => void) => { |
||||
try { |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
const reader = streamResponse.body!.getReader(); |
||||
const decoder = new TextDecoder(); |
||||
cb?: (streamText: string) => void, |
||||
done_cb?: (result: string) => void) => { |
||||
try { |
||||
let resultText = '' |
||||
const parser = new JsonStreamParser(); |
||||
const reader = streamResponse.body!.getReader(); |
||||
const decoder = new TextDecoder(); |
||||
|
||||
while (true) { |
||||
const { done, value } = await reader.read(); |
||||
if (done) break; |
||||
while (true) { |
||||
const { done, value } = await reader.read(); |
||||
if (done) break; |
||||
|
||||
try { |
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(decoder.decode(value, { stream: true })); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
} |
||||
} |
||||
catch (error) { |
||||
console.error('Error parsing JSON:', error); |
||||
} |
||||
} |
||||
if (done_cb) { |
||||
done_cb(resultText) |
||||
try { |
||||
const chunk = parser.safeJsonParse<{ generatedText: string; isGenerating: boolean }>(decoder.decode(value, { stream: true })); |
||||
for (const parsedData of chunk) { |
||||
if (parsedData.isGenerating) { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} else { |
||||
resultText += parsedData.generatedText |
||||
cb(parsedData.generatedText) |
||||
} |
||||
} |
||||
} |
||||
catch (error) { |
||||
} |
||||
catch (error) { |
||||
console.error('Error parsing JSON:', error); |
||||
} |
||||
} |
||||
if (done_cb) { |
||||
done_cb(resultText) |
||||
} |
||||
} |
||||
catch (error) { |
||||
console.error('Error parsing JSON:', error); |
||||
} |
||||
} |
||||
|
||||
export const UpdtateChatHistory = (userPromptprompt: string, AIAnswer: string) => { |
||||
ChatHistory.pushHistory(userPromptprompt, AIAnswer) |
||||
ChatHistory.pushHistory(userPromptprompt, AIAnswer) |
||||
} |
@ -0,0 +1,94 @@ |
||||
.nlux-theme-remix_ai_theme[data-color-scheme='light'] { |
||||
--nlux-ChatRoom--BackgroundColor: var(--text-background); |
||||
} |
||||
|
||||
.nlux-theme-remix_ai_theme[data-color-scheme='dark'] { |
||||
--nlux-ChatRoom--BackgroundColor: var(--text-background); |
||||
} |
||||
|
||||
.nlux-theme-remix_ai_theme { |
||||
|
||||
/* Override top-level chat room colors */ |
||||
--nlux-ChatRoom--BorderColor: #24233d; |
||||
--nlux-ChatRoom-Divider--Color: var(--light); |
||||
/* --nlux-ChatRoom-Divider--BorderWidth:2px; */ |
||||
--nlux-ChatRoom--TextColor: var(--text); |
||||
|
||||
/* Override message bubble colors */ |
||||
--nlux-AiMessage--BackgroundColor: var(--light); |
||||
--nlux-HumanMessage--BackgroundColor: var(--text-background); |
||||
|
||||
/* Override border width */ |
||||
--nlux-ChatRoom--BorderWidth: 0; |
||||
--nlux-SubmitButton--BorderWidth: 0; |
||||
--nlux-ChatItem-Avatar--BorderWidth: 0; |
||||
--nlux-ChatItem-Message-BubbleLayout--BorderWidth: 0; |
||||
--nlux-ConversationStarter--BorderWidth: 1; |
||||
|
||||
/* Override border radius */ |
||||
--nlux-ChatRoom--BorderRadius: 5px; |
||||
--nlux-SubmitButton--BorderRadius: 0 10px 10px 0; |
||||
--nlux-SubmitButton--Width: 73px; |
||||
--nlux-ChatItem-Avatar--BorderRadius: 5px; |
||||
--nlux-ChatItem-Message-BubbleLayout--BorderRadius: 5px; |
||||
--nlux-ConversationStarter--BorderRadius: 5px; |
||||
--nlux-PromptInput-Focus-Outline--Width: 10px; |
||||
--nlux-PromptInput-Max-Height: 50px; |
||||
--nlux-PromptInput--BorderWidth: 0; |
||||
.nlux-comp-composer > textarea {padding: 8px;} |
||||
--nlux-PromptInput--BorderRadius: 10px 0 0 10px; |
||||
--nlux-PromptInput-Height: 50px; |
||||
|
||||
|
||||
/* Override input colors */ |
||||
--nlux-PromptInput--BackgroundColor: var(--light); |
||||
--nlux-PromptInput-Active--BackgroundColor: var(--light); |
||||
--nlux-PromptInput-Disabled--BackgroundColor: var(--dark); |
||||
|
||||
/* Gap between submit button and input */ |
||||
--nlux-Composer--Gap: 0; |
||||
|
||||
/* Override submit button colors */ |
||||
--nlux-SubmitButton--BackgroundColor: var(--primary); |
||||
--nlux-SubmitButton-Active--BackgroundColor:var(--primary); |
||||
--nlux-SubmitButton-Disabled--BackgroundColor: var(--dark); |
||||
--nlux-SubmitButton-Active--TextColor: var(--text); |
||||
--nlux-SubmitButton-Disabled--TextColor: var(--text); |
||||
|
||||
/** Inline code in markdown */ |
||||
--nlux-InlineCode--BorderRadius: 6px; |
||||
--nlux-InlineCode--BorderWidth: 0.5px; |
||||
--nlux-InlineCode--Padding: 0 2px; |
||||
--nlux-InlineCode--FontSize: 14px; |
||||
|
||||
|
||||
/*code block */ |
||||
--nlux-CodeBlock-CopyButton--BackgroundColor: var(--bg-text); |
||||
--nlux-CodeBlock-CopyButton--TextColor: var(--text); |
||||
|
||||
/*codeblock*/ |
||||
/*--nlux-CodeBlock--BackgroundColor: var(--body-bg);*/ |
||||
--nlux-CodeBlock--BackgroundColor: var(--bg-text); |
||||
--nlux-CodeBlock--BorderColor: var(--secondary); |
||||
--nlux-CodeBlock--Padding: 20px; |
||||
--nlux-CodeBlock--TextColor: var(--text); |
||||
--nlux-CodeBlock--FontSize: 14px; |
||||
|
||||
/* Conversation starter colors */ |
||||
--nlux-ConversationStarter--BackgroundColor: var(--light); |
||||
--nlux-copy-icon: url('data:image/svg+xml,\ |
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">\ |
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 1.25H10.9436C9.10583 1.24998 7.65019 1.24997 6.51098 1.40314C5.33856 1.56076 4.38961 1.89288 3.64124 2.64124C2.89288 3.38961 2.56076 4.33856 2.40314 5.51098C2.24997 6.65019 2.24998 8.10582 2.25 9.94357V16C2.25 17.8722 3.62205 19.424 5.41551 19.7047C5.55348 20.4687 5.81753 21.1208 6.34835 21.6517C6.95027 22.2536 7.70814 22.5125 8.60825 22.6335C9.47522 22.75 10.5775 22.75 11.9451 22.75H15.0549C16.4225 22.75 17.5248 22.75 18.3918 22.6335C19.2919 22.5125 20.0497 22.2536 20.6517 21.6517C21.2536 21.0497 21.5125 20.2919 21.6335 19.3918C21.75 18.5248 21.75 17.4225 21.75 16.0549V10.9451C21.75 9.57754 21.75 8.47522 21.6335 7.60825C21.5125 6.70814 21.2536 5.95027 20.6517 5.34835C20.1208 4.81753 19.4687 4.55348 18.7047 4.41551C18.424 2.62205 16.8722 1.25 15 1.25ZM17.1293 4.27117C16.8265 3.38623 15.9876 2.75 15 2.75H11C9.09318 2.75 7.73851 2.75159 6.71085 2.88976C5.70476 3.02502 5.12511 3.27869 4.7019 3.7019C4.27869 4.12511 4.02502 4.70476 3.88976 5.71085C3.75159 6.73851 3.75 8.09318 3.75 10V16C3.75 16.9876 4.38624 17.8265 5.27117 18.1293C5.24998 17.5194 5.24999 16.8297 5.25 16.0549V10.9451C5.24998 9.57754 5.24996 8.47522 5.36652 7.60825C5.48754 6.70814 5.74643 5.95027 6.34835 5.34835C6.95027 4.74643 7.70814 4.48754 8.60825 4.36652C9.47522 4.24996 10.5775 4.24998 11.9451 4.25H15.0549C15.8297 4.24999 16.5194 4.24998 17.1293 4.27117ZM7.40901 6.40901C7.68577 6.13225 8.07435 5.9518 8.80812 5.85315C9.56347 5.75159 10.5646 5.75 12 5.75H15C16.4354 5.75 17.4365 5.75159 18.1919 5.85315C18.9257 5.9518 19.3142 6.13225 19.591 6.40901C19.8678 6.68577 20.0482 7.07435 20.1469 7.80812C20.2484 8.56347 20.25 9.56458 20.25 11V16C20.25 17.4354 20.2484 18.4365 20.1469 19.1919C20.0482 19.9257 19.8678 20.3142 19.591 20.591C19.3142 20.8678 18.9257 21.0482 18.1919 21.1469C17.4365 21.2484 16.4354 21.25 15 21.25H12C10.5646 21.25 9.56347 21.2484 8.80812 21.1469C8.07435 21.0482 7.68577 20.8678 7.40901 20.591C7.13225 20.3142 6.9518 19.9257 6.85315 19.1919C6.75159 18.4365 6.75 17.4354 6.75 16V11C6.75 9.56458 6.75159 8.56347 6.85315 7.80812C6.9518 7.07435 7.13225 6.68577 7.40901 6.40901Z" fill="currentColor"/>\ |
||||
</svg>\ |
||||
'); |
||||
|
||||
/* Override icon for the send button */ |
||||
--nlux-send-icon: url('data:image/svg+xml,\ |
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" \ |
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\ |
||||
<circle cx="12" cy="12" r="10"/>\ |
||||
<path d="M16 12l-4-4-4 4M12 16V9"/>\ |
||||
</svg>\ |
||||
'); |
||||
|
||||
} |
Loading…
Reference in new issue