@@ -206,12 +206,24 @@ export const TridentFileSystem: React.FC = () => {
206
206
prompt : inputText ,
207
207
} ) ;
208
208
console . log ( resJson . content ) ;
209
- const resContent = resJson . content ;
210
- const newFilePath = resContent . split ( "\n" ) [ 0 ] . replace ( "# path: " , "" ) ;
209
+ const resContent = resJson . content as string ;
210
+ const regex = / ` ` ` (?: y a m l ) ? \n ( [ \s \S ] + ) \n ` ` ` / ;
211
+ const resMatched = resContent . match ( regex ) ;
212
+ const resBody = resMatched ? resMatched [ 1 ] : null ;
213
+ if ( ! resBody ) {
214
+ throw new Error ( "AIによるファイルの編集に失敗しました" ) ;
215
+ }
216
+ const newFilePath = resBody . split ( "\n" ) [ 0 ] . replace ( "# path: " , "" ) ;
217
+ console . log ( newFilePath ) ;
211
218
const newDirPath = newFilePath . split ( "/" ) . slice ( 0 , - 1 ) . join ( "/" ) ;
219
+ console . log ( newDirPath ) ;
212
220
const newFileName = newFilePath . split ( "/" ) . pop ( ) ;
213
- const newContent = resContent . split ( "\n" ) . slice ( 1 ) . join ( "\n" ) ;
221
+ console . log ( newFileName ) ;
222
+ if ( ! newFileName || ! newDirPath ) {
223
+ throw new Error ( "AIによるファイルの編集に失敗しました" ) ;
224
+ }
214
225
const newDirHandle = await rootDirHandle . getDirectoryHandle ( newDirPath ) ;
226
+ const newContent = resBody . split ( "\n" ) . slice ( 1 ) . join ( "\n" ) ;
215
227
216
228
const newFileHandle = await newDirHandle . getFileHandle ( newFileName , {
217
229
create : true ,
@@ -366,7 +378,7 @@ export const TridentFileSystem: React.FC = () => {
366
378
zoom : 4 ,
367
379
} }
368
380
style = { { width : "100vw" , height : "80vh" } }
369
- mapStyle = { styleJsonOutput }
381
+ mapStyle = { styleJsonOutput ? styleJsonOutput : { } }
370
382
>
371
383
< GeolocateControl />
372
384
</ Map >
0 commit comments