diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts index 179f8865ac..c8cfc0a9be 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts @@ -6,27 +6,31 @@ const profile = { name: 'copilot-suggestion', displayName: 'copilot-suggestion', description: 'copilot-suggestion', - methods: ['suggest', 'init', 'uninstall'] + methods: ['suggest', 'init', 'uninstall', 'status'] } export class CopilotSuggestion extends Plugin { service: SuggestionService context: string + ready: boolean constructor() { super(profile) this.service = new SuggestionService() this.context = '' this.service.events.on('progress', (data) => { - this.call('terminal', 'log', {type: 'info', value: `loading Solidity copilot: ${(data.loaded / data.total) * 100}% done.` }) + this.emit('loading', data) }) this.service.events.on('done', (data) => { - this.call('terminal', 'log', { type: 'info', value: `Solidity copilot loaded.`}) }) this.service.events.on('ready', (data) => { - this.call('terminal', 'log', { type: 'info', value: `Solidity copilot ready to use.`}) + this.ready = true }) } + status () { + return this.ready + } + async suggest(content: string) { if (!await this.call('settings', 'get', 'settings/copilot/suggest/activate')) return { output: [{ generated_text: ''}]} @@ -59,5 +63,7 @@ export class CopilotSuggestion extends Plugin { return this.service.init() } - async uninstall() {} + async uninstall() { + this.service.terminate() + } } \ No newline at end of file diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts index bfe8b872ee..a6970144f1 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts @@ -17,6 +17,13 @@ export class SuggestionService { this.current } + terminate(): void { + this.worker.terminate() + this.worker = new Worker(new URL('./worker.js', import.meta.url), { + type: 'module' + }); + } + async init() { const onMessageReceived = (e) => { switch (e.data.status) { diff --git a/libs/remix-ui/app/src/lib/remix-app/interface/index.ts b/libs/remix-ui/app/src/lib/remix-app/interface/index.ts index 3ab21c7cc4..fcee9ef693 100644 --- a/libs/remix-ui/app/src/lib/remix-app/interface/index.ts +++ b/libs/remix-ui/app/src/lib/remix-app/interface/index.ts @@ -15,7 +15,7 @@ export interface AppModal { message: string | JSX.Element okLabel: string | JSX.Element okFn?: (value?:any) => void - cancelLabel: string | JSX.Element + cancelLabel?: string | JSX.Element cancelFn?: () => void, modalType?: ModalTypes, defaultValue?: string diff --git a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx index 83c6feacdb..99c38e82a2 100644 --- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx +++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx @@ -1,6 +1,7 @@ import {ViewPlugin} from '@remixproject/engine-web' -import React, {useState, useReducer, useEffect, useCallback} from 'react' // eslint-disable-line +import React, {useState, useRef, useReducer, useEffect, useCallback} from 'react' // eslint-disable-line +import {AppModal, AlertModal, ModalTypes} from '@remix-ui/app' import {labels, textDark, textSecondary} from './constants' import './remix-ui-settings.css' @@ -52,6 +53,8 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { const [ipfsProtocol, setipfsProtocol] = useState('') const [ipfsProjectId, setipfsProjectId] = useState('') const [ipfsProjectSecret, setipfsProjectSecret] = useState('') + const copilotDownload = useRef(null) + const intl = useIntl() const initValue = () => { const metadataConfig = props.config.get('settings/generate-contract-metadata') @@ -126,12 +129,45 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { textWrapEventAction(props.config, props.editor, event.target.checked, dispatch) } - const onchangeCopilotActivate = (event) => { + const onchangeCopilotActivate = (event) => { copilotActivate(props.config, event.target.checked, dispatch) - if (event.target.checked) props.plugin.call('copilot-suggestion', 'init') - else { + if (!event.target.checked) { + copilotActivate(props.config, event.target.checked, dispatch) props.plugin.call('copilot-suggestion', 'uninstall') + return + } + const message =