Advanced mode: chat-driven form filling (fill_form tool), 10 official WA forms auto-grabbed + auto-mapped, doc vault, web search, per-user doc RAG
This commit is contained in:
65
store.py
65
store.py
@@ -35,6 +35,7 @@ def init_db():
|
||||
display_name TEXT DEFAULT '',
|
||||
avatar INTEGER DEFAULT 0,
|
||||
about_me TEXT DEFAULT '',
|
||||
profile_pic TEXT DEFAULT '',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
@@ -63,6 +64,16 @@ def init_db():
|
||||
citations TEXT DEFAULT '',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS files (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
category TEXT DEFAULT 'Other',
|
||||
filename TEXT NOT NULL,
|
||||
orig_name TEXT NOT NULL,
|
||||
mime TEXT DEFAULT '',
|
||||
size INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
""")
|
||||
c.commit()
|
||||
# migrations for pre-existing DBs
|
||||
@@ -74,6 +85,11 @@ def init_db():
|
||||
c.commit()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
c.execute("ALTER TABLE profiles ADD COLUMN profile_pic TEXT DEFAULT ''")
|
||||
c.commit()
|
||||
except Exception:
|
||||
pass
|
||||
c.close()
|
||||
|
||||
|
||||
@@ -127,26 +143,27 @@ def get_profile(uid):
|
||||
row = c.execute("SELECT * FROM profiles WHERE user_id=?", (uid,)).fetchone()
|
||||
c.close()
|
||||
if not row:
|
||||
return {"display_name": "", "avatar": 0, "about_me": ""}
|
||||
return {"display_name": "", "avatar": 0, "about_me": "", "profile_pic": ""}
|
||||
return {"display_name": row["display_name"], "avatar": row["avatar"],
|
||||
"about_me": row["about_me"]}
|
||||
"about_me": row["about_me"], "profile_pic": row["profile_pic"] or ""}
|
||||
|
||||
|
||||
def set_profile(uid, display_name=None, avatar=None, about_me=None):
|
||||
def set_profile(uid, display_name=None, avatar=None, about_me=None, profile_pic=None):
|
||||
cur = get_profile(uid)
|
||||
dn = cur["display_name"] if display_name is None else display_name
|
||||
av = cur["avatar"] if avatar is None else avatar
|
||||
am = cur["about_me"] if about_me is None else about_me
|
||||
pp = cur.get("profile_pic", "") if profile_pic is None else profile_pic
|
||||
c = _conn()
|
||||
c.execute("""INSERT INTO profiles (user_id, display_name, avatar, about_me, updated_at)
|
||||
VALUES (?,?,?,?, CURRENT_TIMESTAMP)
|
||||
c.execute("""INSERT INTO profiles (user_id, display_name, avatar, about_me, profile_pic, updated_at)
|
||||
VALUES (?,?,?,?,?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(user_id) DO UPDATE SET
|
||||
display_name=excluded.display_name, avatar=excluded.avatar,
|
||||
about_me=excluded.about_me, updated_at=CURRENT_TIMESTAMP""",
|
||||
(uid, dn, av, am))
|
||||
about_me=excluded.about_me, profile_pic=excluded.profile_pic, updated_at=CURRENT_TIMESTAMP""",
|
||||
(uid, dn, av, am, pp))
|
||||
c.commit()
|
||||
c.close()
|
||||
return {"display_name": dn, "avatar": av, "about_me": am}
|
||||
return {"display_name": dn, "avatar": av, "about_me": am, "profile_pic": pp}
|
||||
|
||||
|
||||
def get_settings(uid):
|
||||
@@ -203,3 +220,35 @@ def set_settings(uid, **fields):
|
||||
c.commit()
|
||||
c.close()
|
||||
return get_settings(uid)
|
||||
|
||||
|
||||
# ── Document vault ──
|
||||
def add_file(uid, category, filename, orig_name, mime, size):
|
||||
c = _conn()
|
||||
c.execute("INSERT INTO files (user_id, category, filename, orig_name, mime, size) VALUES (?,?,?,?,?,?)",
|
||||
(uid, category, filename, orig_name, mime, size))
|
||||
c.commit()
|
||||
fid = c.execute("SELECT last_insert_rowid()").fetchone()[0]
|
||||
c.close()
|
||||
return fid
|
||||
|
||||
|
||||
def list_files(uid):
|
||||
c = _conn()
|
||||
rows = c.execute("SELECT * FROM files WHERE user_id=? ORDER BY created_at DESC, id DESC", (uid,)).fetchall()
|
||||
c.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def get_file(uid, fid):
|
||||
c = _conn()
|
||||
row = c.execute("SELECT * FROM files WHERE id=? AND user_id=?", (fid, uid)).fetchone()
|
||||
c.close()
|
||||
return dict(row) if row else None
|
||||
|
||||
|
||||
def delete_file(uid, fid):
|
||||
c = _conn()
|
||||
c.execute("DELETE FROM files WHERE id=? AND user_id=?", (fid, uid))
|
||||
c.commit()
|
||||
c.close()
|
||||
|
||||
Reference in New Issue
Block a user