@ -3,7 +3,7 @@ import { ViewPlugin } from '@remixproject/engine-web'
import { Plugin } from '@remixproject/engine' ;
import { RemixAITab , ChatApi } from '@remix-ui/remix-ai'
import React , { useCallback } from 'react' ;
import { ICompletions , IModel , RemoteInferencer , IRemoteModel , IParams , GenerationParams , CodeExplainAgent } from '@remix/remix-ai-core' ;
import { ICompletions , IModel , RemoteInferencer , IRemoteModel , IParams , GenerationParams , CodeExplainAgent , SecurityAgent } from '@remix/remix-ai-core' ;
import { CustomRemixApi } from '@remix-api'
type chatRequestBufferT < T > = {
@ -35,13 +35,14 @@ export class RemixAIPlugin extends ViewPlugin {
remoteInferencer :RemoteInferencer = null
isInferencing : boolean = false
chatRequestBuffer : chatRequestBufferT < any > = null
agent : CodeExplainAgent
codeExpAgent : CodeExplainAgent
securityAgent : SecurityAgent
useRemoteInferencer :boolean = false
constructor ( inDesktop :boolean ) {
super ( profile )
this . isOnDesktop = inDesktop
this . a gent = new CodeExplainAgent ( this )
this . codeExpA gent = new CodeExplainAgent ( this )
// user machine dont use ressource for remote inferencing
}
@ -57,6 +58,8 @@ export class RemixAIPlugin extends ViewPlugin {
this . useRemoteInferencer = true
this . initialize ( )
}
this . securityAgent = new SecurityAgent ( this )
}
async initialize ( model1? :IModel , model2? :IModel , remoteModel? :IRemoteModel , useRemote? :boolean ) {
@ -92,11 +95,6 @@ export class RemixAIPlugin extends ViewPlugin {
}
async code_generation ( prompt : string ) : Promise < any > {
if ( this . isInferencing ) {
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "RemixAI is already busy!" } )
return
}
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
return await this . call ( this . remixDesktopPluginName , 'code_generation' , prompt )
} else {
@ -113,12 +111,7 @@ export class RemixAIPlugin extends ViewPlugin {
}
async solidity_answer ( prompt : string , params : IParams = GenerationParams ) : Promise < any > {
if ( this . isInferencing ) {
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "RemixAI is already busy!" } )
return
}
const newPrompt = await this . agent . chatCommand ( prompt )
const newPrompt = await this . codeExpAgent . chatCommand ( prompt )
let result
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
result = await this . call ( this . remixDesktopPluginName , 'solidity_answer' , newPrompt )
@ -130,11 +123,6 @@ export class RemixAIPlugin extends ViewPlugin {
}
async code_explaining ( prompt : string , context : string , params : IParams = GenerationParams ) : Promise < any > {
if ( this . isInferencing ) {
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "RemixAI is already busy!" } )
return
}
let result
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
result = await this . call ( this . remixDesktopPluginName , 'code_explaining' , prompt , context , params )
@ -147,11 +135,6 @@ export class RemixAIPlugin extends ViewPlugin {
}
async error_explaining ( prompt : string , context : string = "" , params : IParams = GenerationParams ) : Promise < any > {
if ( this . isInferencing ) {
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "RemixAI is already busy!" } )
return
}
let result
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
result = await this . call ( this . remixDesktopPluginName , 'error_explaining' , prompt )
@ -163,22 +146,21 @@ export class RemixAIPlugin extends ViewPlugin {
}
async vulnerability_check ( prompt : string , params : IParams = GenerationParams ) : Promise < any > {
if ( this . isInferencing ) {
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "RemixAI is already busy!" } )
return
}
let result
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
result = await this . call ( this . remixDesktopPluginName , 'vulnerability_check' , prompt )
} else {
result = await this . remoteInferencer . vulnerability_check ( prompt )
result = await this . remoteInferencer . vulnerability_check ( prompt , params )
}
if ( result && params . terminal_output ) this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : result } )
return result
}
getVulnerabilityReport ( file : string ) : any {
return this . securityAgent . getReport ( file )
}
async code_insertion ( msg_pfx : string , msg_sfx : string ) : Promise < any > {
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
return await this . call ( this . remixDesktopPluginName , 'code_insertion' , msg_pfx , msg_sfx )