@@ -37,7 +37,20 @@ export class ContractAgent {
37
37
async writeContracts ( payload , userPrompt ) {
38
38
const currentWorkspace = await this . plugin . call ( 'filePanel' , 'getCurrentWorkspace' )
39
39
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 )
41
54
if ( ! this . overrideWorkspace ) await this . plugin . call ( 'filePanel' , 'switchToWorkspace' , { name : this . workspaceName , isLocalHost : false } )
42
55
const dirCreated = [ ]
43
56
for ( const file of parsedResults . files ) {
@@ -49,8 +62,8 @@ export class ContractAgent {
49
62
// check if file already exists
50
63
await this . plugin . call ( 'fileManager' , 'writeFile' , file . fileName , file . content )
51
64
await this . plugin . call ( 'codeFormatter' , 'format' , file . fileName )
65
+ return "New workspace created: **" + this . workspaceName + "**\nUse the Hamburger menu to select it!"
52
66
}
53
- return "New workspace created: **" + this . workspaceName + "**\nUse the Hamburger menu to select it!"
54
67
}
55
68
56
69
try {
@@ -95,6 +108,7 @@ export class ContractAgent {
95
108
} catch ( error ) {
96
109
this . deleteWorkspace ( this . workspaceName )
97
110
this . nAttempts = 0
111
+ console . error ( 'Error writing contracts:' , error )
98
112
await this . plugin . call ( 'filePanel' , 'switchToWorkspace' , currentWorkspace )
99
113
return "Failed to generate secure code on user prompt! Please try again with a different prompt."
100
114
} finally {
@@ -104,10 +118,14 @@ export class ContractAgent {
104
118
105
119
async createWorkspace ( workspaceName ) {
106
120
// 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
+ }
111
129
}
112
130
113
131
async deleteWorkspace ( workspaceName ) {
0 commit comments