File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -193,17 +193,27 @@ export async function askAI(params: ChatParams): Promise<ChatResult> {
193193 if ( ! text ) {
194194 throw new Error ( "AIからの応答が空でした" ) ;
195195 }
196- let targetSectionId = text . split ( / \n - { 3 , } \n / ) [ 0 ] . trim ( ) as SectionId ;
196+ let targetSectionId = text
197+ . split ( / \n - { 3 , } \n / )
198+ . at ( 0 )
199+ ?. trim ( ) as SectionId | undefined ;
197200 if ( ! targetSectionId ) {
198201 targetSectionId = introSectionId ( path ) ;
199202 }
200- const responseMessage = text . split ( / \n - { 3 , } \n / ) [ 1 ] . trim ( ) ;
203+ const responseMessage = text
204+ . split ( / \n - { 3 , } \n / )
205+ . at ( 1 )
206+ ?. trim ( ) ;
207+ if ( ! responseMessage ) {
208+ throw new Error ( "AIからの応答が空でした" ) ;
209+ }
201210 const diffRaw : CreateChatDiff [ ] = [ ] ;
202211 for ( const m of text
203- . split ( / \n - { 3 , } \n / ) [ 2 ]
204- . matchAll (
212+ . split ( / \n - { 3 , } \n / )
213+ . at ( 2 )
214+ ?. matchAll (
205215 / < { 3 , } \s * S E A R C H \n ( [ \s \S ] * ?) \n = { 3 , } \n ( [ \s \S ] * ?) \n > { 3 , } \s * R E P L A C E / g
206- ) ) {
216+ ) ?? [ ] ) {
207217 const search = m [ 1 ] ;
208218 const replace = m [ 2 ] ;
209219 const targetSection = sectionContent . find ( ( s ) =>
You can’t perform that action at this time.
0 commit comments