diff --git a/apps/circuit-compiler/src/app/components/container.tsx b/apps/circuit-compiler/src/app/components/container.tsx index 5045ff7f9b..a93b56b340 100644 --- a/apps/circuit-compiler/src/app/components/container.tsx +++ b/apps/circuit-compiler/src/app/components/container.tsx @@ -10,7 +10,7 @@ import { CircuitActions } from './actions' import { WitnessToggler } from './witnessToggler' import { WitnessSection } from './witness' import { CompilerFeedback } from './feedback' -import { PrimeValue } from '../types' +import { CompilerReport, PrimeValue } from '../types' export function Container () { const circuitApp = useContext(CircuitAppContext) @@ -58,26 +58,41 @@ 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 askGPT = async (report: CompilerReport) => { + circuitApp.appState.filePathToId[report.labels[0].file_id], circuitApp.appState.filePathToId[report.labels[0].message] + if (report.labels.length > 0) { + const location = circuitApp.appState.filePathToId[report.labels[0].file_id] + const error = report.labels[0].message + + 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} + context: ${JSON.stringify(report, null, 2)} + explain why the error occurred and how to fix it. + ` + // @ts-ignore + await circuitApp.plugin.call('openaigpt', 'message', message) + } else { + const message = ` + error message: ${error} + context: ${JSON.stringify(report, null, 2)} + explain why the error occurred and how to fix it. + ` + // @ts-ignore + await circuitApp.plugin.call('openaigpt', 'message', message) + } + } else { + const error = report.message const message = ` - error message: ${error} - explain why the error occurred and how to fix it. - ` + error message: ${error} + context: ${JSON.stringify(report, null, 2)} + 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') } } diff --git a/apps/circuit-compiler/src/app/components/feedback.tsx b/apps/circuit-compiler/src/app/components/feedback.tsx index da4e43af64..5b61794281 100644 --- a/apps/circuit-compiler/src/app/components/feedback.tsx +++ b/apps/circuit-compiler/src/app/components/feedback.tsx @@ -17,8 +17,8 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr } } - const handleAskGPT = (message: string, location?: string) => { - askGPT(message, location) + const handleAskGPT = (report: CompilerReport) => { + askGPT(report) } return ( @@ -47,7 +47,7 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr handleAskGPT(filePathToId[response.labels[0].file_id], filePathToId[response.labels[0].message]) } /> + askGPT={ () => handleAskGPT(response) } /> @@ -55,7 +55,7 @@ export function CompilerFeedback ({ feedback, filePathToId, hideWarnings, openEr { handleAskGPT(response.message) }} /> + askGPT={() => { handleAskGPT(response) }} /> diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts index 16548188b1..add4806427 100644 --- a/apps/circuit-compiler/src/app/types/index.ts +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -52,7 +52,7 @@ export type CompilerFeedbackProps = { filePathToId: Record, openErrorLocation: (location: string, startRange: string) => void, hideWarnings: boolean, - askGPT: (message: string, location?: string) => void + askGPT: (report: CompilerReport) => void } export type CompilerReport = {