Skip to content

Commit 9e7cb79

Browse files
committed
new window with user selected folder on AI generate
1 parent 1f8900d commit 9e7cb79

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

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

Lines changed: 24 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 {
@@ -95,6 +108,7 @@ export class ContractAgent {
95108
} catch (error) {
96109
this.deleteWorkspace(this.workspaceName )
97110
this.nAttempts = 0
111+
console.error('Error writing contracts:', error)
98112
await this.plugin.call('filePanel', 'switchToWorkspace', currentWorkspace)
99113
return "Failed to generate secure code on user prompt! Please try again with a different prompt."
100114
} finally {
@@ -104,10 +118,14 @@ export class ContractAgent {
104118

105119
async createWorkspace(workspaceName) {
106120
// 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
121+
try {
122+
const timestamp = new Date().getTime()
123+
const wsp_name = workspaceName + '-' + timestamp
124+
await this.plugin.call('filePanel', 'createWorkspace', wsp_name, true)
125+
this.workspaceName = wsp_name
126+
} catch (error) {
127+
console.error('Error creating workspace:', error)
128+
}
111129
}
112130

113131
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)