diff --git a/apps/circuit-compiler/src/app/components/container.tsx b/apps/circuit-compiler/src/app/components/container.tsx index fa7467f69c..5045ff7f9b 100644 --- a/apps/circuit-compiler/src/app/components/container.tsx +++ b/apps/circuit-compiler/src/app/components/container.tsx @@ -58,6 +58,29 @@ export function Container () { circuitApp.dispatch({ type: 'SET_HIDE_WARNINGS', payload: value }) } + const askGPT = async (error: string, location?: string) => { + if (location) { + const fullPathLocation = await circuitApp.plugin.resolveReportPath(location) + const content = await circuitApp.plugin.call('fileManager', 'readFile', fullPathLocation) + const message = ` + solidity code: ${content} + error message: ${error} + explain why the error occurred and how to fix it. + ` + // @ts-ignore + await circuitApp.plugin.call('openaigpt', 'message', message) + } else if(error) { + const message = ` + error message: ${error} + explain why the error occurred and how to fix it. + ` + // @ts-ignore + await circuitApp.plugin.call('openaigpt', 'message', message) + } else { + console.error('unable to askGtp, no message provided') + } + } + return (
@@ -86,7 +109,7 @@ export function Container () { - + diff --git a/apps/circuit-compiler/src/app/components/feedback.tsx b/apps/circuit-compiler/src/app/components/feedback.tsx index 164c39e1ac..da4e43af64 100644 --- a/apps/circuit-compiler/src/app/components/feedback.tsx +++ b/apps/circuit-compiler/src/app/components/feedback.tsx @@ -4,7 +4,7 @@ import { RenderIf } from '@remix-ui/helper' import {CopyToClipboard} from '@remix-ui/clipboard' import { FeedbackAlert } from './feedbackAlert' -export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openErrorLocation }: CompilerFeedbackProps) { +export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openErrorLocation, askGPT }: CompilerFeedbackProps) { const [ showException, setShowException ] = useState(true) const handleCloseException = () => { @@ -17,6 +17,10 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr } } + const handleAskGPT = (message: string, location?: string) => { + askGPT(message, location) + } + return (
@@ -40,12 +44,18 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr
handleOpenError(response)}>
- + handleAskGPT(filePathToId[response.labels[0].file_id], filePathToId[response.labels[0].message]) } />
- + { handleAskGPT(response.message) }} />
diff --git a/apps/circuit-compiler/src/app/components/feedbackAlert.tsx b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx index 5c9e092ab4..48e57fab31 100644 --- a/apps/circuit-compiler/src/app/components/feedbackAlert.tsx +++ b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx @@ -3,7 +3,7 @@ import { FeedbackAlertProps } from '../types' import { RenderIf } from '@remix-ui/helper' import {CopyToClipboard} from '@remix-ui/clipboard' -export function FeedbackAlert ({ message, location }: FeedbackAlertProps) { +export function FeedbackAlert ({ message, location, askGPT }: FeedbackAlertProps) { const [ showAlert, setShowAlert] = useState(true) const handleCloseAlert = () => { @@ -24,6 +24,7 @@ export function FeedbackAlert ({ message, location }: FeedbackAlertProps) { + ASK GPT
diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index e54f12e507..312e489efd 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -124,7 +124,7 @@ export class CircomPluginClient extends PluginClient { async compile(path: string, compilationConfig?: CompilationConfig): Promise { this.internalEvents.emit('circuit_compiling_start') // @ts-ignore - this.call('terminal', 'log', { type: 'info', value: 'Compiling ' + path }) + this.call('terminal', 'log', { type: 'log', value: 'Compiling ' + path }) const [parseErrors, filePathToId] = await this.parse(path) if (parseErrors && (parseErrors.length > 0)) { @@ -172,7 +172,6 @@ export class CircomPluginClient extends PluginClient { } else { this.internalEvents.emit('circuit_compiling_done', []) } - // @ts-ignore circuitApi.log().map(log => { log && this.call('terminal', 'log', { type: 'log', value: log }) }) @@ -184,7 +183,7 @@ export class CircomPluginClient extends PluginClient { async generateR1cs (path: string, compilationConfig?: CompilationConfig): Promise { this.internalEvents.emit('circuit_generating_r1cs_start') // @ts-ignore - this.call('terminal', 'log', { type: 'info', value: 'Generating R1CS for ' + path }) + this.call('terminal', 'log', { type: 'log', value: 'Generating R1CS for ' + path }) const [parseErrors, filePathToId] = await this.parse(path) if (parseErrors && (parseErrors.length > 0)) { @@ -221,7 +220,6 @@ export class CircomPluginClient extends PluginClient { // @ts-ignore await this.call('fileManager', 'writeFile', writePath, r1csProgram, true) - // @ts-ignore r1csApi.log().map(log => { log && this.call('terminal', 'log', { type: 'log', value: log }) }) diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts index 3b6f7a57b4..16548188b1 100644 --- a/apps/circuit-compiler/src/app/types/index.ts +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -1,6 +1,6 @@ import { compiler_list } from 'circom_wasm' import {Dispatch} from 'react' -import { CircomPluginClient } from '../services/circomPluginClient' +import type { CircomPluginClient } from '../services/circomPluginClient' export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored" | "warning" export interface ICircuitAppContext { @@ -51,7 +51,8 @@ export type CompilerFeedbackProps = { feedback: string | CompilerReport[], filePathToId: Record, openErrorLocation: (location: string, startRange: string) => void, - hideWarnings: boolean + hideWarnings: boolean, + askGPT: (message: string, location?: string) => void } export type CompilerReport = { @@ -71,7 +72,8 @@ export type CompilerReport = { export type FeedbackAlertProps = { message: string, - location: string + location: string, + askGPT: () => void } export type ConfigurationsProps = { diff --git a/yarn.lock b/yarn.lock index 9e2f4c801c..3d4421f1bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10539,7 +10539,7 @@ circom_runtime@0.1.22: "circom_wasm@https://github.com/ioedeveloper/circom_wasm.git": version "0.2.0" - resolved "https://github.com/ioedeveloper/circom_wasm.git#68473f2c1166d96e73513b0a2aac1afcd30b0111" + resolved "https://github.com/ioedeveloper/circom_wasm.git#e558f8a449ac12151e735c6923c65f33b9b953ff" circular-json@^0.3.0: version "0.3.3"