From 6f04d48166f4ea25265cd8fcf6d144441d74af20 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 16 Nov 2026 14:21:04 +0900 Subject: [PATCH] refac --- backend/open_webui/utils/agents/acp.py | 8 ++++---- backend/open_webui/utils/agents/claude_code.py | 4 ++-- backend/open_webui/utils/agents/codex.py | 2 +- backend/open_webui/utils/agents/output.py | 13 ++++++++----- backend/open_webui/utils/agents/pi.py | 2 +- backend/open_webui/utils/tool_approval.py | 5 +++-- src/lib/components/chat/Chat.svelte | 10 ++++++++-- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/backend/open_webui/utils/agents/acp.py b/backend/open_webui/utils/agents/acp.py index 5ba418e3a2..718fdcbef2 100644 --- a/backend/open_webui/utils/agents/acp.py +++ b/backend/open_webui/utils/agents/acp.py @@ -36,7 +36,7 @@ def answer_value(value): return value -async def elicit(output, params, native): +async def elicit(output, params, request): """Present ACP's flat form schema through the existing ask-user card.""" if params.get('mode') != 'form': return {'action': 'decline'} @@ -65,7 +65,7 @@ async def elicit(output, params, native): ) if not questions: return {'action': 'decline'} - resolution = await output.approve('ask_user', {'questions': questions}, native) + resolution = await output.approve('ask_user', {'questions': questions}, request) if resolution['action'] != 'answer' or resolution.get('timed_out'): return {'action': 'decline'} content = {} @@ -141,7 +141,7 @@ async def run(transport, output, prompt, images, options, *, auth_method=None): call_id, tool.get('title') or tool.get('kind', 'agent_tool'), tool.get('rawInput') or {}, - native=tool.copy(), + provider_data=tool.copy(), result=tool.get('rawOutput', tool.get('content', [])), done=tool.get('status') in {'completed', 'failed'}, ) @@ -150,7 +150,7 @@ async def run(transport, output, prompt, images, options, *, auth_method=None): 'agent_plan', 'Plan', {'entries': update.get('entries', [])}, - native=update, + provider_data=update, result=update.get('entries', []), done=True, ) diff --git a/backend/open_webui/utils/agents/claude_code.py b/backend/open_webui/utils/agents/claude_code.py index 71359046c6..837415d585 100644 --- a/backend/open_webui/utils/agents/claude_code.py +++ b/backend/open_webui/utils/agents/claude_code.py @@ -113,7 +113,7 @@ async def run(transport, output, prompt, images, options): elif block['type'] == 'thinking' and not streamed_thinking: await output.text(block['thinking'], reasoning=True) elif block['type'] == 'tool_use': - await output.tool(block['id'], block['name'], block['input'], native=block) + await output.tool(block['id'], block['name'], block['input'], provider_data=block) elif kind == 'user': blocks = message.get('message', {}).get('content', []) for block in blocks if isinstance(blocks, list) else []: @@ -123,7 +123,7 @@ async def run(transport, output, prompt, images, options): block['tool_use_id'], previous.get('name', 'agent_tool'), json.loads(previous.get('arguments', '{}')), - native=block, + provider_data=block, result=block.get('content'), done=True, ) diff --git a/backend/open_webui/utils/agents/codex.py b/backend/open_webui/utils/agents/codex.py index 0849c29103..8da8010b74 100644 --- a/backend/open_webui/utils/agents/codex.py +++ b/backend/open_webui/utils/agents/codex.py @@ -143,7 +143,7 @@ async def run(transport, output, prompt, images, options): item.get('id', params.get('itemId')), item.get('type', 'agent_tool'), item, - native=item, + provider_data=item, result=item.get('aggregatedOutput', item), done=method == 'item/completed', ) diff --git a/backend/open_webui/utils/agents/output.py b/backend/open_webui/utils/agents/output.py index f9ef89c1e9..3ccff810d8 100644 --- a/backend/open_webui/utils/agents/output.py +++ b/backend/open_webui/utils/agents/output.py @@ -17,7 +17,7 @@ from redis.asyncio import Redis class Output: - """Use WebUI's persisted output cards; provider runners retain native item data.""" + """Use WebUI's persisted output cards; each item keeps the provider's own event in provider_data.""" def __init__(self, metadata, user, check_connection, form_data): self.metadata, self.user = metadata, user @@ -109,13 +109,16 @@ class Output: self.content += text await self.flush() - async def tool(self, call_id, name, arguments, native=None, result=None, done=False): + async def tool(self, call_id, name, arguments, provider_data=None, result=None, done=False): item = next((i for i in self.items if i.get('call_id') == call_id and i['type'] == 'function_call'), None) if item is None: item = {'type': 'function_call', 'id': call_id, 'call_id': call_id} self.items.append(item) item.update( - name=name, arguments=json.dumps(arguments), status='completed' if done else 'in_progress', native=native + name=name, + arguments=json.dumps(arguments), + status='completed' if done else 'in_progress', + provider_data=provider_data, ) if done: self.items[:] = [ @@ -134,7 +137,7 @@ class Output: ) await self.flush(force=True) - async def approve(self, name, arguments, native, timeout=None): + async def approve(self, name, arguments, provider_data, timeout=None): call_id = f'approval_{uuid4().hex}' item = { 'type': 'function_call', @@ -143,7 +146,7 @@ class Output: 'name': name, 'arguments': json.dumps(arguments), 'status': 'pending', - 'native': native, + 'provider_data': provider_data, } resolution = None # Questions need an answer even when tool execution has Full access. diff --git a/backend/open_webui/utils/agents/pi.py b/backend/open_webui/utils/agents/pi.py index f30cbe0935..a5e38ce4d0 100644 --- a/backend/open_webui/utils/agents/pi.py +++ b/backend/open_webui/utils/agents/pi.py @@ -94,7 +94,7 @@ async def run(transport, output, prompt, images, options): call_id, tool.get('toolName', 'agent_tool'), tool.get('args', {}), - native=tool.copy(), + provider_data=tool.copy(), result=tool.get('result', tool.get('partialResult')), done=kind == 'tool_execution_end', ) diff --git a/backend/open_webui/utils/tool_approval.py b/backend/open_webui/utils/tool_approval.py index d74360f341..a2fcc507b0 100644 --- a/backend/open_webui/utils/tool_approval.py +++ b/backend/open_webui/utils/tool_approval.py @@ -102,7 +102,8 @@ async def resolve_tool_call_output( function_call.setdefault('call_id', form_data.call_id) tool_name = function_call.get('name') - if function_call.get('native') is not None: + # Terminal agent requests carry the provider's event; older saved messages call it 'native'. + if function_call.get('provider_data') is not None or function_call.get('native') is not None: from open_webui.utils.auth import decode_token token = (message.get('meta') or {}).get('agent') @@ -122,7 +123,7 @@ async def resolve_tool_call_output( raise HTTPException(400, 'Answers must be keyed by question') function_call['agent_resolution'] = form_data.model_dump() function_call['status'] = 'queued' - # The running native client consumes this persisted response. Do not start a model/tool loop. + # The running agent client consumes this persisted response. Do not start a model/tool loop. return {'chat': chat, 'output': output, 'resume': None} if ( diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 2349f84f95..71542f789e 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -51,6 +51,7 @@ terminalServers, functions, selectedFolder as _selectedFolder, + folders as _folders, showEmbeds as _showEmbeds, selectedTerminalId as _selectedTerminalId, showFileNavPath, @@ -4226,14 +4227,19 @@ let titleInput: HTMLInputElement; let generatingTitle = false; let titleEditChatId = ''; - $: if (loading || isShared || $temporaryChatEnabled || $chatId !== titleEditChatId) + // Folder owners can rename chats others made in their folders. + $: canRename = + !isShared || + (!!chat?.folder_id && + $_folders.find((folder) => folder.id === chat.folder_id)?.user_id === $user?.id); + $: if (loading || !canRename || $temporaryChatEnabled || $chatId !== titleEditChatId) editingTitle = false; $: tabTitleEditor = editingTitle ? renderTitleEditor : undefined; export const startRename = async () => { if ( loading || - isShared || + !canRename || !$chatId || $temporaryChatEnabled || isTemporaryChatId($chatId) ||