Files
Athena-Deck/integrations/openwebui-tool-context-guard/verify_config.py
T

22 lines
2.5 KiB
Python

"""Read-only installed-configuration verification. Prints no prompts/credentials.
Run in OpenWebUI's Python environment; use a separate real UI chat for requests.
"""
import argparse, hashlib, json, sqlite3, sys, urllib.request
from datetime import timedelta
p=argparse.ArgumentParser();p.add_argument('--db',default='/app/backend/data/webui.db');p.add_argument('--backend',default='/app/backend');p.add_argument('--base-url',default='http://127.0.0.1:8080');p.add_argument('--user-id');a=p.parse_args()
sys.path.insert(0,a.backend)
from open_webui.utils.auth import create_token
c=sqlite3.connect('file:'+a.db+'?mode=ro',uri=True);c.row_factory=sqlite3.Row
uid=a.user_id or c.execute("select id from user where role='admin' limit 1").fetchone()[0]
token=create_token({'id':uid},timedelta(minutes=5))
def api(path):
return json.load(urllib.request.urlopen(urllib.request.Request(a.base_url.rstrip('/')+path,headers={'Authorization':'Bearer '+token}),timeout=60))
def cfg(k):
r=c.execute('select value from config where key=?',(k,)).fetchone();return (json.loads(r[0]) if isinstance(r[0],str) else r[0]) if r else None
params=cfg('models.default_params') or {};meta=cfg('models.default_metadata') or {};ui=cfg('ui.default_interface_settings') or {};raw=api('/api/v1/users/user/settings?raw=true')
models=api('/api/models');models=models if isinstance(models,list) else models.get('data',[])
checks={'single_global_prompt':bool(ui.get('system')) and not params.get('system'),'native_tool_calling':params.get('function_calling')=='native','no_personal_system_override':'system' not in raw.get('ui',{}),'same_tools_for_all_models':all((m.get('info',{}).get('meta') or {}).get('toolIds')==meta.get('toolIds') for m in models),'no_model_system_override':all(not json.loads(r[0] or '{}').get('system') for r in c.execute('select params from model'))}
func=c.execute("select is_active,is_global,valves from function where id='athena_tool_context_guard'").fetchone();valves=json.loads(func['valves'] or '{}') if func else {};checks['global_guard_active']=bool(func and func['is_active'] and func['is_global']);checks['window_map_present']=bool(valves.get('profile_windows'));checks['background_thinking_none']=(cfg('task.model.params') or {}).get('reasoning_effort')=='none'
print(json.dumps({'checks':checks,'prompt_chars':len(ui.get('system') or ''),'prompt_sha256':hashlib.sha256((ui.get('system') or '').encode()).hexdigest(),'models':len(models),'audit_scope_count':len(valves.get('audit_chat_ids',[]))},indent=2))
assert all(checks.values()),'Configuration mismatch: see boolean checks above'