|
|
|
@ -4,12 +4,6 @@ import React, {useState, useRef, useReducer, useEffect, useCallback} from 'react |
|
|
|
|
import {AppModal, AlertModal, ModalTypes} from '@remix-ui/app' |
|
|
|
|
import {labels, textDark, textSecondary} from './constants' |
|
|
|
|
|
|
|
|
|
enum CONSENT { |
|
|
|
|
GIVEN = 0, |
|
|
|
|
NOT_GIVEN, |
|
|
|
|
NOT_ASKED |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
import './remix-ui-settings.css' |
|
|
|
|
import { |
|
|
|
|
generateContractMetadat, |
|
|
|
@ -62,7 +56,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { |
|
|
|
|
const [ipfsProjectSecret, setipfsProjectSecret] = useState('') |
|
|
|
|
const copilotDownload = useRef(null) |
|
|
|
|
|
|
|
|
|
let consentGivenForAI = CONSENT.NOT_ASKED |
|
|
|
|
const intl = useIntl() |
|
|
|
|
const initValue = () => { |
|
|
|
|
const metadataConfig = props.config.get('settings/generate-contract-metadata') |
|
|
|
@ -129,15 +122,6 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { |
|
|
|
|
if (props.useMatomoAnalytics !== null) useMatomoAnalytics(props.config, props.useMatomoAnalytics, dispatch) |
|
|
|
|
}, [props.useMatomoAnalytics])
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
console.log("useEffect on useCopilot") |
|
|
|
|
if (props.useCopilot !== null) copilotActivate(props.config, props.useCopilot, dispatch) |
|
|
|
|
if (props.useCopilot) { |
|
|
|
|
onchangeCopilotActivate() |
|
|
|
|
} |
|
|
|
|
console.log("useEffect on useCopilot finish") |
|
|
|
|
}, [props.useCopilot]) |
|
|
|
|
|
|
|
|
|
const onchangeGenerateContractMetadata = (event) => { |
|
|
|
|
generateContractMetadat(props.config, event.target.checked, dispatch) |
|
|
|
|
} |
|
|
|
@ -151,67 +135,30 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { |
|
|
|
|
if (!props.useCopilot) { |
|
|
|
|
copilotActivate(props.config, props.useCopilot, dispatch) |
|
|
|
|
props.plugin.call('copilot-suggestion', 'uninstall') |
|
|
|
|
props.plugin.call('terminal', 'log', {type: 'typewriterlog', value: `Solidity copilot deactivated` }) |
|
|
|
|
return |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const message = <div>Please wait while the copilot is downloaded. <span ref={copilotDownload}>0</span>/100 .</div> |
|
|
|
|
props.plugin.on('copilot-suggestion', 'loading', (data) => { |
|
|
|
|
if (!copilotDownload.current) return |
|
|
|
|
const loaded = ((data.loaded / data.total) * 100).toString() |
|
|
|
|
const dot = loaded.match(/(.*)\./g) |
|
|
|
|
copilotDownload.current.innerText = dot ? dot[0].replace('.', '') : loaded |
|
|
|
|
props.plugin.on('copilot-suggestion', 'ready', (data) => { |
|
|
|
|
props.plugin.call('terminal', 'log', {type: 'typewriterlog', value: `loading Solidity copilot: 100% done.` }) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const startCopilot = async () => { |
|
|
|
|
await props.plugin.call('copilot-suggestion', 'init') |
|
|
|
|
props.plugin.off('copilot-suggestion', 'loading') |
|
|
|
|
if (await props.plugin.call('copilot-suggestion', 'status')) { |
|
|
|
|
copilotActivate(props.config, true, dispatch)
|
|
|
|
|
} else { |
|
|
|
|
props.plugin.call('copilot-suggestion', 'uninstall') |
|
|
|
|
copilotActivate(props.config, false, dispatch) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const modalActivate: AppModal = { |
|
|
|
|
id: 'loadcopilotActivate', |
|
|
|
|
title: 'Download Solidity copilot', |
|
|
|
|
modalType: ModalTypes.default, |
|
|
|
|
okLabel: 'Hide', |
|
|
|
|
cancelLabel: 'Cancel', |
|
|
|
|
message, |
|
|
|
|
okFn: async() => { |
|
|
|
|
consentGivenForAI = CONSENT.GIVEN |
|
|
|
|
startCopilot() |
|
|
|
|
}, |
|
|
|
|
hideFn: async () => { |
|
|
|
|
consentGivenForAI = CONSENT.NOT_GIVEN |
|
|
|
|
props.plugin.off('copilot-suggestion', 'loading') |
|
|
|
|
// if (await props.plugin.call('copilot-suggestion', 'status')) {
|
|
|
|
|
// copilotActivate(props.config, true, dispatch)
|
|
|
|
|
// } else {
|
|
|
|
|
// props.plugin.call('copilot-suggestion', 'uninstall')
|
|
|
|
|
// copilotActivate(props.config, false, dispatch)
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (consentGivenForAI === CONSENT.NOT_ASKED) { |
|
|
|
|
console.log("CONSENT.NOT_ASKED modal") |
|
|
|
|
props.plugin.call('notification', 'modal', modalActivate) |
|
|
|
|
} else if (consentGivenForAI === CONSENT.GIVEN) { |
|
|
|
|
startCopilot() |
|
|
|
|
} else { |
|
|
|
|
// NOT_GIVEN
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
startCopilot() |
|
|
|
|
if (props.plugin.call('copilot-suggestion', 'status')) { |
|
|
|
|
copilotActivate(props.config, true, dispatch)
|
|
|
|
|
} else { |
|
|
|
|
props.plugin.call('copilot-suggestion', 'uninstall') |
|
|
|
|
copilotActivate(props.config, false, dispatch) |
|
|
|
|
}else { |
|
|
|
|
startCopilot() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
|
useEffect(() => { |
|
|
|
|
if (props.useCopilot !== null) copilotActivate(props.config, props.useCopilot, dispatch) |
|
|
|
|
onchangeCopilotActivate() |
|
|
|
|
}, [props.useCopilot]) |
|
|
|
@ -482,13 +429,13 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { |
|
|
|
|
const isCopilotActivated = props.config.get('settings/copilot/suggest/activate') || false |
|
|
|
|
let copilotMaxnewToken = props.config.get('settings/copilot/suggest/max_new_tokens') |
|
|
|
|
if (!copilotMaxnewToken) { |
|
|
|
|
props.config.set('settings/copilot/suggest/max_new_tokens', 5) |
|
|
|
|
copilotMaxnewToken = 5 |
|
|
|
|
props.config.set('settings/copilot/suggest/max_new_tokens', 10) |
|
|
|
|
copilotMaxnewToken = 10 |
|
|
|
|
} |
|
|
|
|
let copilotTemperatureValue = (props.config.get('settings/copilot/suggest/temperature')) * 100 |
|
|
|
|
if (!copilotTemperatureValue) { |
|
|
|
|
props.config.set('settings/copilot/suggest/temperature', 0.5) |
|
|
|
|
copilotTemperatureValue = 0.5 |
|
|
|
|
props.config.set('settings/copilot/suggest/temperature', 0.9) |
|
|
|
|
copilotTemperatureValue = 0.9 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//if (isCopilotActivated) props.plugin.call('copilot-suggestion', 'init')
|
|
|
|
|