Skip to content

Commit 3a7991c

Browse files
authored
Merge pull request #6125 from ethereum/generate_fix_desktop
Generate fix desktop
2 parents 6d7f927 + c926a21 commit 3a7991c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

libs/remix-ai-core/src/agents/contractAgent.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ export class ContractAgent {
3737
async writeContracts(payload, userPrompt) {
3838
const currentWorkspace = await this.plugin.call('filePanel', 'getCurrentWorkspace')
3939

40-
const writeAIResults = async (parsedResults) => {await this.createWorkspace(this.workspaceName)
40+
const writeAIResults = async (parsedResults) => {
41+
if (this.plugin.isOnDesktop) {
42+
console.log('Writing AI results to desktop workspace:', parsedResults.files)
43+
// Transform parsedResults.files into an object: { [fileName]: content }
44+
const files = parsedResults.files.reduce((acc, file) => {
45+
acc[file.fileName] = file.content
46+
return acc
47+
}, {})
48+
await this.plugin.call('electronTemplates', 'loadTemplateInNewWindow', files)
49+
//return "Feature not only available in the browser version of Remix IDE. Please use the browser version to generate secure code."
50+
return "## New workspace created! \nNavigate to the new window!"
51+
}
52+
53+
await this.createWorkspace(this.workspaceName)
4154
if (!this.overrideWorkspace) await this.plugin.call('filePanel', 'switchToWorkspace', { name: this.workspaceName, isLocalHost: false })
4255
const dirCreated = []
4356
for (const file of parsedResults.files) {
@@ -49,8 +62,8 @@ export class ContractAgent {
4962
// check if file already exists
5063
await this.plugin.call('fileManager', 'writeFile', file.fileName, file.content)
5164
await this.plugin.call('codeFormatter', 'format', file.fileName)
65+
return "New workspace created: **" + this.workspaceName + "**\nUse the Hamburger menu to select it!"
5266
}
53-
return "New workspace created: **" + this.workspaceName + "**\nUse the Hamburger menu to select it!"
5467
}
5568

5669
try {
@@ -104,10 +117,14 @@ export class ContractAgent {
104117

105118
async createWorkspace(workspaceName) {
106119
// create random workspace surfixed with timestamp
107-
const timestamp = new Date().getTime()
108-
const wsp_name = workspaceName + '-' + timestamp
109-
await this.plugin.call('filePanel', 'createWorkspace', wsp_name, true)
110-
this.workspaceName = wsp_name
120+
try {
121+
const timestamp = new Date().getTime()
122+
const wsp_name = workspaceName + '-' + timestamp
123+
await this.plugin.call('filePanel', 'createWorkspace', wsp_name, true)
124+
this.workspaceName = wsp_name
125+
} catch (error) {
126+
console.error('Error creating workspace:', error)
127+
}
111128
}
112129

113130
async deleteWorkspace(workspaceName) {

libs/remix-ai-core/src/agents/workspaceAgent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class workspaceAgent {
7676
break
7777
}
7878
default:
79-
console.log('Invalid context type', context)
8079
this.ctxFiles = ""
8180
break
8281
}

0 commit comments

Comments
 (0)