Agent Zero AI framework
api cleanup, microphone permission
frdel99b4accd7b5e
diff --git a/python/api/backup_create.py b/python/api/backup_create.pyindex d66aa4dcd..307fb62c0 100644--- a/python/api/backup_create.py+++ b/python/api/backup_create.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response, send_file+from python.helpers.api import ApiHandler, Request, Response, send_filefrom python.helpers.backup import BackupServicefrom python.helpers.persist_chat import save_tmp_chatsdiff --git a/python/api/backup_get_defaults.py b/python/api/backup_get_defaults.pyindex 7b9bf2652..3a3f4cf9e 100644--- a/python/api/backup_get_defaults.py+++ b/python/api/backup_get_defaults.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.backup import BackupServicediff --git a/python/api/backup_inspect.py b/python/api/backup_inspect.pyindex 72cb1fe2e..97e247e0e 100644--- a/python/api/backup_inspect.py+++ b/python/api/backup_inspect.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.backup import BackupServicefrom werkzeug.datastructures import FileStoragediff --git a/python/api/backup_preview_grouped.py b/python/api/backup_preview_grouped.pyindex 17eedbda6..bcaf9a981 100644--- a/python/api/backup_preview_grouped.py+++ b/python/api/backup_preview_grouped.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.backup import BackupServicefrom typing import Dict, Anydiff --git a/python/api/backup_restore.py b/python/api/backup_restore.pyindex 1b38cb79c..86bf2a82a 100644--- a/python/api/backup_restore.py+++ b/python/api/backup_restore.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom werkzeug.datastructures import FileStoragefrom python.helpers.backup import BackupServicefrom python.helpers.persist_chat import load_tmp_chatsdiff --git a/python/api/backup_restore_preview.py b/python/api/backup_restore_preview.pyindex a73dbf2ad..d5d6e1bb5 100644--- a/python/api/backup_restore_preview.py+++ b/python/api/backup_restore_preview.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom werkzeug.datastructures import FileStoragefrom python.helpers.backup import BackupServiceimport jsondiff --git a/python/api/backup_test.py b/python/api/backup_test.pyindex fbaee7665..d0234a784 100644--- a/python/api/backup_test.py+++ b/python/api/backup_test.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.backup import BackupServicediff --git a/python/api/download_work_dir_file.py b/python/api/download_work_dir_file.pyindex eca4c2507..09ca4019f 100644--- a/python/api/download_work_dir_file.py+++ b/python/api/download_work_dir_file.py@@ -1,9 +1,7 @@import base64from io import BytesIO-from python.helpers.api import ApiHandler, Input, Output, Request, Response-from flask import send_file-+from python.helpers.api import ApiHandler, Input, Output, Request, Response, send_filefrom python.helpers import files, runtimefrom python.api import file_infoimport osdiff --git a/python/api/get_work_dir_files.py b/python/api/get_work_dir_files.pyindex bfe6f8e12..4f640e8aa 100644--- a/python/api/get_work_dir_files.py+++ b/python/api/get_work_dir_files.py@@ -1,8 +1,6 @@-from python.helpers.api import ApiHandler-from flask import Request, Response-+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.file_browser import FileBrowser-from python.helpers import files, runtime+from python.helpers import runtimeclass GetWorkDirFiles(ApiHandler):diff --git a/python/api/health.py b/python/api/health.pyindex 7cf0965f4..72a6b83f8 100644--- a/python/api/health.py+++ b/python/api/health.py@@ -1,8 +1,5 @@-from python.helpers.api import ApiHandler-from flask import Request, Response-from python.helpers import errors--from python.helpers import git+from python.helpers.api import ApiHandler, Request, Response+from python.helpers import errors, gitclass HealthCheck(ApiHandler):diff --git a/python/api/history_get.py b/python/api/history_get.pyindex 9b1359c49..7ff40e3fe 100644--- a/python/api/history_get.py+++ b/python/api/history_get.py@@ -1,6 +1,4 @@-from python.helpers import tokens-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responseclass GetHistory(ApiHandler):diff --git a/python/api/image_get.py b/python/api/image_get.pyindex acca85dc7..8c6e3dd9c 100644--- a/python/api/image_get.py+++ b/python/api/image_get.py@@ -1,11 +1,7 @@import base64import os-import re-from typing import override-from python.helpers.api import ApiHandler-from python.helpers import files-from flask import Request, Response, send_file-from python.helpers import runtime+from python.helpers.api import ApiHandler, Request, Response, send_file+from python.helpers import files, runtimeimport iofrom mimetypes import guess_typediff --git a/python/api/import_knowledge.py b/python/api/import_knowledge.pyindex 30d2d8716..667964075 100644--- a/python/api/import_knowledge.py+++ b/python/api/import_knowledge.py@@ -1,7 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response--from python.helpers.file_browser import FileBrowser+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import files, memoryimport osfrom werkzeug.utils import secure_filenamediff --git a/python/api/mcp_server_get_detail.py b/python/api/mcp_server_get_detail.pyindex e5e385aac..0608aadc5 100644--- a/python/api/mcp_server_get_detail.py+++ b/python/api/mcp_server_get_detail.py@@ -1,7 +1,4 @@-from math import log-from python.helpers.api import ApiHandler-from flask import Request, Response-+from python.helpers.api import ApiHandler, Request, Responsefrom typing import Anyfrom python.helpers.mcp_handler import MCPConfigdiff --git a/python/api/mcp_server_get_log.py b/python/api/mcp_server_get_log.pyindex eadf25bb8..f9488c7df 100644--- a/python/api/mcp_server_get_log.py+++ b/python/api/mcp_server_get_log.py@@ -1,6 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response-+from python.helpers.api import ApiHandler, Request, Responsefrom typing import Anyfrom python.helpers.mcp_handler import MCPConfigdiff --git a/python/api/mcp_servers_apply.py b/python/api/mcp_servers_apply.pyindex f5a5aef4b..08f513652 100644--- a/python/api/mcp_servers_apply.py+++ b/python/api/mcp_servers_apply.py@@ -1,6 +1,5 @@import time-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom typing import Anydiff --git a/python/api/mcp_servers_status.py b/python/api/mcp_servers_status.pyindex 8d25dcb7b..be2654930 100644--- a/python/api/mcp_servers_status.py+++ b/python/api/mcp_servers_status.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom typing import Anydiff --git a/python/api/message.py b/python/api/message.pyindex 69e2db12a..2f88f4784 100644--- a/python/api/message.py+++ b/python/api/message.py@@ -1,6 +1,5 @@from agent import AgentContext, UserMessage-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import filesimport osdiff --git a/python/api/message_async.py b/python/api/message_async.pyindex 22d9192ef..f3e85dfb5 100644--- a/python/api/message_async.py+++ b/python/api/message_async.py@@ -1,10 +1,4 @@from agent import AgentContext-from python.helpers.api import ApiHandler-from flask import Request, Response--from python.helpers import files-import os-from werkzeug.utils import secure_filenamefrom python.helpers.defer import DeferredTaskfrom python.api.message import Messagediff --git a/python/api/nudge.py b/python/api/nudge.pyindex 62a497853..64683da07 100644--- a/python/api/nudge.py+++ b/python/api/nudge.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responseclass Nudge(ApiHandler):async def process(self, input: dict, request: Request) -> dict | Response:diff --git a/python/api/pause.py b/python/api/pause.pyindex 95fea1b07..e4b20ecfb 100644--- a/python/api/pause.py+++ b/python/api/pause.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responseclass Pause(ApiHandler):diff --git a/python/api/poll.py b/python/api/poll.pyindex df3e22c80..05af6df8b 100644--- a/python/api/poll.py+++ b/python/api/poll.py@@ -1,7 +1,4 @@-import time-from datetime import datetime-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom agent import AgentContextdiff --git a/python/api/restart.py b/python/api/restart.pyindex 864e16968..678fe7490 100644--- a/python/api/restart.py+++ b/python/api/restart.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import processdiff --git a/python/api/rfc.py b/python/api/rfc.pyindex 82fa2f739..f2fa112d1 100644--- a/python/api/rfc.py+++ b/python/api/rfc.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import runtimediff --git a/python/api/settings_get.py b/python/api/settings_get.pyindex 2ecdbef38..f807bc60a 100644--- a/python/api/settings_get.py+++ b/python/api/settings_get.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import settingsdiff --git a/python/api/settings_set.py b/python/api/settings_set.pyindex 6700aace5..c24a3cc66 100644--- a/python/api/settings_set.py+++ b/python/api/settings_set.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import settingsdiff --git a/python/api/synthesize.py b/python/api/synthesize.pyindex 2c1c75b1a..15fc2d7c9 100644--- a/python/api/synthesize.py+++ b/python/api/synthesize.py@@ -1,8 +1,6 @@# api/synthesize.py-import re-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import runtime, settings, kokoro_ttsdiff --git a/python/api/transcribe.py b/python/api/transcribe.pyindex dd6573c8d..5ad4ade63 100644--- a/python/api/transcribe.py+++ b/python/api/transcribe.py@@ -1,5 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import runtime, settings, whisperdiff --git a/python/api/tunnel.py b/python/api/tunnel.pyindex 8279330f1..ca5d64f42 100644--- a/python/api/tunnel.py+++ b/python/api/tunnel.py@@ -1,6 +1,5 @@-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import runtime-from python.helpers.api import ApiHandlerfrom python.helpers.tunnel_manager import TunnelManagerclass Tunnel(ApiHandler):diff --git a/python/api/tunnel_proxy.py b/python/api/tunnel_proxy.pyindex efcd39a77..c8b1bd75b 100644--- a/python/api/tunnel_proxy.py+++ b/python/api/tunnel_proxy.py@@ -1,6 +1,5 @@-from flask import Request, Response+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import dotenv, runtime-from python.helpers.api import ApiHandlerfrom python.helpers.tunnel_manager import TunnelManagerimport requestsdiff --git a/python/api/upload.py b/python/api/upload.pyindex 02aaa7186..4a596a577 100644--- a/python/api/upload.py+++ b/python/api/upload.py@@ -1,6 +1,4 @@-from python.helpers.api import ApiHandler-from flask import Request, Response-+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers import filesfrom werkzeug.utils import secure_filenamediff --git a/python/api/upload_work_dir_files.py b/python/api/upload_work_dir_files.pyindex 74035b02d..8bf85e664 100644--- a/python/api/upload_work_dir_files.py+++ b/python/api/upload_work_dir_files.py@@ -1,8 +1,6 @@import base64from werkzeug.datastructures import FileStorage-from python.helpers.api import ApiHandler-from flask import Request, Response, send_file-+from python.helpers.api import ApiHandler, Request, Responsefrom python.helpers.file_browser import FileBrowserfrom python.helpers import files, runtimefrom python.api import get_work_dir_filesdiff --git a/python/helpers/api.py b/python/helpers/api.pyindex 8110386c3..5d0e171f5 100644--- a/python/helpers/api.py+++ b/python/helpers/api.py@@ -3,7 +3,7 @@ import jsonimport threadingfrom typing import Union, TypedDict, Dict, Anyfrom attr import dataclass-from flask import Request, Response, jsonify, Flask, session, request+from flask import Request, Response, jsonify, Flask, session, request, send_filefrom agent import AgentContextfrom initialize import initialize_agentfrom python.helpers.print_style import PrintStylediff --git a/webui/components/settings/speech/microphone-setting-store.js b/webui/components/settings/speech/microphone-setting-store.jsindex ddc45e4e0..4d079d53c 100644--- a/webui/components/settings/speech/microphone-setting-store.js+++ b/webui/components/settings/speech/microphone-setting-store.js@@ -24,9 +24,44 @@ const model = {this.selectedDevice = this.devices.length > 0 ? this.devices[0].deviceId : "";},- requestPermission() {- navigator.mediaDevices.getUserMedia({ audio: true });- setTimeout(() => this.loadDevices(), 1000);+ // track permission request state+ requestingPermission: false,+ permissionTimer: null,+ permissionAttempts: 0,++ // request microphone permission and poll for devices+ async requestPermission() {+ // set flag first so UI can update immediately+ clearTimeout(this.permissionTimer);+ this.requestingPermission = true;+ this.permissionAttempts = 0;++ // request permission in next tick to allow UI to update+ setTimeout(async () => {+ try {+ await navigator.mediaDevices.getUserMedia({ audio: true });+ // start polling for devices+ this.pollForDevices();+ } catch (err) {+ console.error("Microphone permission denied");+ this.requestingPermission = false;+ }+ }, 0);+ },++ // poll for devices until found or timeout (60s)+ async pollForDevices() {+ await this.loadDevices();++ // check if we found devices with valid IDs+ if (this.devices.some(d => d.deviceId && d.deviceId !== "") || this.permissionAttempts >= 60) {+ this.requestingPermission = false;+ return;+ }++ // continue polling+ this.permissionAttempts++;+ this.permissionTimer = setTimeout(() => this.pollForDevices(), 1000);},async selectDevice(deviceId) {diff --git a/webui/components/settings/speech/microphone.html b/webui/components/settings/speech/microphone.htmlindex 2a6b97a16..7f4154afd 100644--- a/webui/components/settings/speech/microphone.html+++ b/webui/components/settings/speech/microphone.html@@ -25,8 +25,14 @@:selected="option.deviceId === $store.microphoneSetting.selectedDevice"></option></template></select>- <button class="btn btn-field" x-show="$store.microphoneSetting.devices.length == 0"- @click="$store.microphoneSetting.requestPermission()">Request permission</button>+ <button class="btn btn-field"+ x-show="$store.microphoneSetting.devices.length == 0 && !$store.microphoneSetting.requestingPermission"+ @click="$store.microphoneSetting.requestPermission()">Request permission to select device</button>+ <button class="btn btn-field"+ x-show="$store.microphoneSetting.requestingPermission"+ @click="$store.microphoneSetting.requestPermission()">+ <span>Waiting for devices... [retry]</span>+ </button></div></template>