diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index a59a1d119..0bd367587 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -1,4 +1,4 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; +import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { acceptToolCall, @@ -23,8 +23,7 @@ export const callTool = createAsyncThunk( } if (!state.config.defaultModelTitle) { - console.error("Cannot call tools, no model selected"); - return; + throw new Error("No model selected"); } dispatch(setCalling()); @@ -40,12 +39,17 @@ export const callTool = createAsyncThunk( dispatch(acceptToolCall()); // Send to the LLM to continue the conversation - dispatch( + const response = await dispatch( streamResponseAfterToolCall({ toolCallId: toolCallState.toolCall.id, toolOutput: contextItems, }), ); + unwrapResult(response); + } else { + throw new Error( + `Failed to call tool ${toolCallState.toolCall.function.name}: ${result.error}`, + ); } }, ); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 9a19a471c..f0f6c9baa 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -1,4 +1,4 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; +import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { ChatMessage, PromptLog } from "core"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { selectDefaultModel } from "../slices/configSlice"; @@ -70,7 +70,8 @@ export const streamNormalInput = createAsyncThunk< toolSettings[toolCallState.toolCall.function.name] === "allowedWithoutPermission" ) { - await dispatch(callTool()); + const response = await dispatch(callTool()); + unwrapResult(response); } } }); diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 396ab6075..2710d0f5e 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -31,8 +31,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< const defaultModel = selectDefaultModel(state); if (!defaultModel) { - console.error("No default model found"); - return; + throw new Error("No model selected"); } resetStateForNewMessage(); @@ -68,7 +67,8 @@ export const streamResponseAfterToolCall = createAsyncThunk< defaultModel.provider, useTools, ); - unwrapResult(await dispatch(streamNormalInput(messages))); + const output = await dispatch(streamNormalInput(messages)); + unwrapResult(output); }), ); },