@ -5,10 +5,15 @@ import { RemixAITab, ChatApi } from '@remix-ui/remix-ai'
import React , { useCallback } from 'react' ;
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 } from '@remix/remix-ai-core' ;
import { CustomRemixApi } from '@remix-api'
import { CustomRemixApi } from '@remix-api'
import { PluginViewWrapper } from '@remix-ui/helper'
type chatRequestBufferT < T > = {
type chatRequestBufferT < T > = {
[ key in keyof T ] : T [ key ]
[ key in keyof T ] : T [ key ]
}
}
enum AIChatViewState {
minimized = 0 ,
open = 1
}
const profile = {
const profile = {
name : 'remixAI' ,
name : 'remixAI' ,
@ -16,7 +21,8 @@ const profile = {
methods : [ 'code_generation' , 'code_completion' ,
methods : [ 'code_generation' , 'code_completion' ,
"solidity_answer" , "code_explaining" ,
"solidity_answer" , "code_explaining" ,
"code_insertion" , "error_explaining" ,
"code_insertion" , "error_explaining" ,
"initialize" , 'chatPipe' , 'ProcessChatRequestBuffer' , 'isChatRequestPending' ] ,
"initialize" , 'chatPipe' , 'ProcessChatRequestBuffer' ,
'isChatRequestPending' , 'toggle' ] ,
events : [ ] ,
events : [ ] ,
icon : 'assets/img/remix-logo-blue.png' ,
icon : 'assets/img/remix-logo-blue.png' ,
description : 'RemixAI provides AI services to Remix IDE.' ,
description : 'RemixAI provides AI services to Remix IDE.' ,
@ -37,6 +43,7 @@ export class RemixAIPlugin extends ViewPlugin {
chatRequestBuffer : chatRequestBufferT < any > = null
chatRequestBuffer : chatRequestBufferT < any > = null
agent : CodeExplainAgent
agent : CodeExplainAgent
useRemoteInferencer :boolean = false
useRemoteInferencer :boolean = false
dispatch : any
constructor ( inDesktop :boolean ) {
constructor ( inDesktop :boolean ) {
super ( profile )
super ( profile )
@ -46,6 +53,7 @@ export class RemixAIPlugin extends ViewPlugin {
}
}
onActivation ( ) : void {
onActivation ( ) : void {
//this.renderComponent(AIChatViewState.open)
if ( this . isOnDesktop ) {
if ( this . isOnDesktop ) {
console . log ( 'Activating RemixAIPlugin on desktop' )
console . log ( 'Activating RemixAIPlugin on desktop' )
// this.on(this.remixDesktopPluginName, 'activated', () => {
// this.on(this.remixDesktopPluginName, 'activated', () => {
@ -59,6 +67,10 @@ export class RemixAIPlugin extends ViewPlugin {
}
}
}
}
toggle ( open : AIChatViewState ) {
this . renderComponent ( open )
}
async initialize ( model1? :IModel , model2? :IModel , remoteModel? :IRemoteModel , useRemote? :boolean ) {
async initialize ( model1? :IModel , model2? :IModel , remoteModel? :IRemoteModel , useRemote? :boolean ) {
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
// on desktop use remote inferencer -> false
// on desktop use remote inferencer -> false
@ -201,13 +213,41 @@ export class RemixAIPlugin extends ViewPlugin {
return ""
return ""
}
}
}
}
isChatRequestPending ( ) {
isChatRequestPending ( ) {
return this . chatRequestBuffer != null
return this . chatRequestBuffer != null
}
}
setDispatch ( dispatch ) {
this . dispatch = dispatch
this . renderComponent ( AIChatViewState . open )
}
renderComponent ( open : AIChatViewState ) {
this . dispatch ( {
plugin : this ,
openState : open
} )
}
render() {
render() {
return < div
id = 'ai-view'
className = 'pb-2 mb-2 h-100 d-flex'
data - id = 'aichat-view'
style = { {
minHeight : 'max-content' ,
maxWidth : '25rem' ,
width : '24rem' ,
} }
>
< PluginViewWrapper plugin = { this } / >
< / div >
}
updateComponent ( state ) {
return (
return (
< RemixAITab plugin = { this } > < / RemixAITab >
< RemixAITab plugin = { state . plugin } openState = { state . openState } > < / RemixAITab >
)
)
}
}
}
}