Skip to content

Commit 448c089

Browse files
committed
diffの出力がない時エラーになるのを修正
1 parent 74268e3 commit 448c089

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/actions/chatActions.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff 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*SEARCH\n([\s\S]*?)\n={3,}\n([\s\S]*?)\n>{3,}\s*REPLACE/g
206-
)) {
216+
) ?? []) {
207217
const search = m[1];
208218
const replace = m[2];
209219
const targetSection = sectionContent.find((s) =>

0 commit comments

Comments
 (0)