diff --git a/vibn-frontend/app/api/chat/route.ts b/vibn-frontend/app/api/chat/route.ts index 853ef8cf..f31f3725 100644 --- a/vibn-frontend/app/api/chat/route.ts +++ b/vibn-frontend/app/api/chat/route.ts @@ -964,9 +964,17 @@ export async function POST(request: Request) { extraSystem += `\n\n[WARNING] You only have ${maxToolRounds - round} tool calls left before you are forcefully terminated. Stop exploring, make your final edits, and write your final response to the user NOW.`; } + // Execute tool calls and add results. OpenAI-compatible APIs + const resp = await callVibnChat({ + systemPrompt: systemPrompt + extraSystem, + messages, + tools: toolDefs, + temperature: 0.7, + includeThoughts: true, + }); + // C-08: Force Checkpoint Before Mutation - // If the AI is trying to use mutating tools but hasn't emitted a checkpoint, - // intercept the tool calls, block them, and force it to state its plan. + // (Moved safely *after* callVibnChat so 'resp' is defined) const requestedMutations = resp.toolCalls.filter((tc) => [ "fs_write", @@ -1010,15 +1018,6 @@ export async function POST(request: Request) { }); } - // Execute tool calls and add results. OpenAI-compatible APIs - const resp = await callVibnChat({ - systemPrompt: systemPrompt + extraSystem, - messages, - tools: toolDefs, - temperature: 0.7, - includeThoughts: true, - }); - if (resp.error) { emit({ type: "error", error: resp.error }); safeClose();