feat(tool-approval): add run_python preview support

This commit is contained in:
JOJO 2026-04-12 01:13:12 +08:00
parent 6a21a642d0
commit bd891029df
2 changed files with 16 additions and 3 deletions

View File

@ -99,6 +99,16 @@ def _build_tool_approval_preview(web_terminal, function_name: str, arguments: Di
preview["summary"] = f"执行命令: {args.get('command') or ''}"
return preview
if function_name in {"run_python", "runpython"}:
code = str(args.get("code") or "")
timeout = args.get("timeout")
preview["code"] = code
preview["timeout"] = timeout
# 兼容前端已有 command 展示分支
preview["command"] = code
preview["summary"] = f"执行 Python 代码timeout={timeout if timeout is not None else '未提供'}s"
return preview
if function_name in {"create_file", "create_folder", "delete_file"}:
preview["path"] = args.get("path")
preview["summary"] = f"{function_name}: {args.get('path') or ''}"

View File

@ -69,7 +69,7 @@
<pre
v-else-if="isCommandPreview(item)"
class="approval-lines approval-lines--cmd"
>{{ item.preview?.command || '' }}</pre>
>{{ item.preview?.code || item.preview?.command || '' }}</pre>
<div v-else class="approval-kv">
<div><strong>工具</strong>{{ item.tool_name }}</div>
@ -126,7 +126,8 @@ defineEmits<{
}>();
const isEditPreview = (item: any) => item?.tool_name === 'edit_file' && item?.preview?.edit_context;
const isCommandPreview = (item: any) => ['run_command', 'terminal_input'].includes(item?.tool_name);
const isCommandPreview = (item: any) =>
['run_command', 'terminal_input', 'run_python', 'runpython'].includes(item?.tool_name);
const isWritePreview = (item: any) => item?.tool_name === 'write_file';
const isRenamePreview = (item: any) => item?.tool_name === 'rename_file';
const isPathOnlyPreview = (item: any) =>
@ -149,7 +150,9 @@ const getToolLabel = (toolName: string) => {
delete_file: '删除文件',
rename_file: '重命名文件',
write_file: '写入文件',
edit_file: '编辑文件'
edit_file: '编辑文件',
run_python: '执行 Python',
runpython: '执行 Python'
};
return map[name] || name || '待审批操作';
};