@ -5,10 +5,15 @@ 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 { CustomRemixApi } from '@remix-api'
import { PluginViewWrapper } from '@remix-ui/helper'
type chatRequestBufferT < T > = {
[ key in keyof T ] : T [ key ]
}
enum AIChatViewState {
minimized = 0 ,
open = 1
}
const profile = {
name : 'remixAI' ,
@ -16,7 +21,8 @@ const profile = {
methods : [ 'code_generation' , 'code_completion' ,
"solidity_answer" , "code_explaining" ,
"code_insertion" , "error_explaining" ,
"initialize" , 'chatPipe' , 'ProcessChatRequestBuffer' , 'isChatRequestPending' ] ,
"initialize" , 'chatPipe' , 'ProcessChatRequestBuffer' ,
'isChatRequestPending' , 'toggle' ] ,
events : [ ] ,
icon : 'assets/img/remix-logo-blue.png' ,
description : 'RemixAI provides AI services to Remix IDE.' ,
@ -37,6 +43,7 @@ export class RemixAIPlugin extends ViewPlugin {
chatRequestBuffer : chatRequestBufferT < any > = null
agent : CodeExplainAgent
useRemoteInferencer :boolean = false
dispatch : any
constructor ( inDesktop :boolean ) {
super ( profile )
@ -46,6 +53,7 @@ export class RemixAIPlugin extends ViewPlugin {
}
onActivation ( ) : void {
//this.renderComponent(AIChatViewState.open)
if ( this . isOnDesktop ) {
console . log ( 'Activating RemixAIPlugin on desktop' )
// 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 ) {
if ( this . isOnDesktop && ! this . useRemoteInferencer ) {
// on desktop use remote inferencer -> false
@ -201,13 +213,41 @@ export class RemixAIPlugin extends ViewPlugin {
return ""
}
}
isChatRequestPending ( ) {
return this . chatRequestBuffer != null
}
setDispatch ( dispatch ) {
this . dispatch = dispatch
this . renderComponent ( AIChatViewState . open )
}
renderComponent ( open : AIChatViewState ) {
this . dispatch ( {
plugin : this ,
openState : open
} )
}
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 (
< RemixAITab plugin = { this } > < / RemixAITab >
< RemixAITab plugin = { state . plugin } openState = { state . openState } > < / RemixAITab >
)
}
}