Visitar URL original
refac · open-webui/computer@af25ee4 · GitHub
Skip to content

Commit af25ee4

Browse files
committed
refac
1 parent 2514e96 commit af25ee4

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

‎cptr/frontend/src/lib/apis/chat.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ export const answerAskUser = (
200200
timedOut = false
201201
) =>
202202
fetchJSON(
203-
`/api/chats/${chatId}/messages/${messageId}/answer`,
204-
jsonBody({ call_id: callId, answers, timed_out: timedOut })
203+
`/api/chats/${chatId}/messages/${messageId}/approve`,
204+
jsonBody({ call_id: callId, approved: true, answers, timed_out: timedOut })
205205
);
206206

207207
export const cancelTask = (chatId: string, messageId: string) =>

‎cptr/routers/chat.py‎

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,7 @@ async def compact_chat(request: Request, chat_id: str, body: CompactRequest):
12101210
class ApproveRequest(BaseModel):
12111211
call_id: str
12121212
approved: bool = True
1213-
1214-
1215-
class AskUserAnswerRequest(BaseModel):
1216-
call_id: str
1217-
answers: dict[str, str]
1213+
answers: dict[str, str] | None = None
12181214
timed_out: bool = False
12191215

12201216

@@ -1287,27 +1283,6 @@ async def resolve_ask_user(
12871283
)
12881284

12891285

1290-
@router.post("/{chat_id}/messages/{message_id}/answer")
1291-
async def answer_ask_user(
1292-
chat_id: str, message_id: str, body: AskUserAnswerRequest, request: Request
1293-
):
1294-
"""Resolve a pending Plan-mode ask_user request and resume the chat."""
1295-
user_id = _get_user(request)
1296-
chat = await Chat.get_by_id(chat_id)
1297-
if not chat or chat.user_id != user_id:
1298-
raise HTTPException(404, "chat not found")
1299-
1300-
try:
1301-
await resolve_ask_user(
1302-
request.app, chat_id, message_id, body.call_id, body.answers, body.timed_out
1303-
)
1304-
except AskUserNotPendingError as exc:
1305-
raise HTTPException(409, str(exc)) from exc
1306-
except ValueError as exc:
1307-
raise HTTPException(422, str(exc)) from exc
1308-
return {"ok": True}
1309-
1310-
13111286
@router.post("/{chat_id}/messages/{message_id}/approve")
13121287
async def approve_tool(request: Request, chat_id: str, message_id: str, body: ApproveRequest):
13131288
"""Execute or reject a pending tool call, then continue."""
@@ -1335,6 +1310,24 @@ async def approve_tool(request: Request, chat_id: str, message_id: str, body: Ap
13351310
if not call:
13361311
raise HTTPException(400, "no pending tool call with that call_id")
13371312

1313+
if call.get("name") == "ask_user" and body.approved:
1314+
if body.answers is None and not body.timed_out:
1315+
raise HTTPException(400, "answers are required for ask_user")
1316+
try:
1317+
await resolve_ask_user(
1318+
request.app,
1319+
chat_id,
1320+
message_id,
1321+
body.call_id,
1322+
body.answers,
1323+
body.timed_out,
1324+
)
1325+
except AskUserNotPendingError as exc:
1326+
raise HTTPException(409, str(exc)) from exc
1327+
except ValueError as exc:
1328+
raise HTTPException(422, str(exc)) from exc
1329+
return {"ok": True}
1330+
13381331
model_id = msg.model or ""
13391332
workspace = chat.meta.get("workspace", "") if chat.meta else ""
13401333
from cptr.socket.main import emit_to_user

0 commit comments

Comments
 (0)