File size: 1,260 Bytes
fbf3c28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
id: db_admin
title: DB Admin (unsafe)
author: admin
description: Run read/write SQL against the Open WebUI SQLite database.
version: 0.1.0
license: Proprietary
"""

import os
import sqlite3


class Tools:
    def query(self, sql: str) -> dict:
        """Run SELECT-like SQL; returns rows."""
        db = os.environ.get(
            "WEBUI_DB", "/data/adaptai/migrate/vast/workspace-vast1-2/webui/webui.db"
        )
        con = sqlite3.connect(db)
        cur = con.cursor()
        try:
            cur.execute(sql)
            rows = cur.fetchall()
            return {"rows": rows}
        finally:
            con.close()

    def exec(self, sql: str) -> dict:
        if os.environ.get("OUI_DB_ADMIN_WRITE", "0") != "1":
            return {
                "ok": False,
                "error": "DB write disabled: set OUI_DB_ADMIN_WRITE=1 to enable",
            }
        """Run mutation SQL (UPDATE/DELETE)."""
        db = os.environ.get(
            "WEBUI_DB", "/data/adaptai/migrate/vast/workspace-vast1-2/webui/webui.db"
        )
        con = sqlite3.connect(db)
        cur = con.cursor()
        try:
            cur.executescript(sql)
            con.commit()
            return {"ok": True}
        finally:
            con.close()