fix: multi-user isolation and sqlor-compatible queries
- Replace all sor.sqlExe(ORDER BY/LIMIT) with sor.R(ns={sort:...}) pattern
- _get_config: add user_id parameter and filter
- _find_relevant_skills: use sor.R with $or and $like filters
- list_reasoning_sessions: use sor.R with ns sort and Python slicing
- All queries now include user_id filter for multi-user isolation
This commit is contained in:
parent
bb420a6471
commit
7f60b0a79b
BIN
harnessed_reasoning/.core.py.swp
Normal file
BIN
harnessed_reasoning/.core.py.swp
Normal file
Binary file not shown.
Binary file not shown.
@ -117,8 +117,8 @@ class HermesReasoningEngine:
|
|||||||
# Config helpers
|
# Config helpers
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
async def _get_config(self) -> Dict[str, Any]:
|
async def _get_config(self, user_id: str = None) -> Dict[str, Any]:
|
||||||
"""Get reasoning config from DB, fall back to defaults."""
|
"""Get reasoning config from DB for current user, fall back to defaults."""
|
||||||
try:
|
try:
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
dbname = env.get_module_dbname('harnessed_reasoning')
|
dbname = env.get_module_dbname('harnessed_reasoning')
|
||||||
@ -127,8 +127,10 @@ class HermesReasoningEngine:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.db.sqlorContext(dbname) as sor:
|
async with self.db.sqlorContext(dbname) as sor:
|
||||||
sql = "SELECT * FROM harnessed_reasoning_config ORDER BY updated_at DESC LIMIT 1"
|
where = {}
|
||||||
rows = await sor.sqlExe(sql, {})
|
if user_id:
|
||||||
|
where['user_id'] = user_id
|
||||||
|
rows = await sor.R('harnessed_reasoning_config', where if where else None, ns={'sort': 'updated_at desc'})
|
||||||
if rows:
|
if rows:
|
||||||
return rows[0]
|
return rows[0]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -196,15 +198,14 @@ class HermesReasoningEngine:
|
|||||||
try:
|
try:
|
||||||
async with self.db.sqlorContext('default') as sor:
|
async with self.db.sqlorContext('default') as sor:
|
||||||
for kw in list(keywords)[:3]:
|
for kw in list(keywords)[:3]:
|
||||||
sql = """SELECT * FROM hermes_skills
|
rows = await sor.R('hermes_skills', {
|
||||||
WHERE user_id = :user_id
|
|
||||||
AND (name LIKE :kw1 OR description LIKE :kw2)
|
|
||||||
LIMIT 2"""
|
|
||||||
rows = await sor.sqlExe(sql, {
|
|
||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
'kw1': f'%{kw}%',
|
'$or': [
|
||||||
'kw2': f'%{kw}%'
|
{'name': {'$like': f'%{kw}%'}},
|
||||||
|
{'description': {'$like': f'%{kw}%'}}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
rows = (rows or [])[:2]
|
||||||
skills.extend(rows)
|
skills.extend(rows)
|
||||||
|
|
||||||
# Deduplicate
|
# Deduplicate
|
||||||
@ -433,7 +434,7 @@ class HermesReasoningEngine:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
config = await self._get_config()
|
config = await self._get_config(user_id)
|
||||||
safety_mode = config.get('safety_mode', 'strict')
|
safety_mode = config.get('safety_mode', 'strict')
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
@ -689,8 +690,9 @@ class HermesReasoningEngine:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.db.sqlorContext('default') as sor:
|
async with self.db.sqlorContext('default') as sor:
|
||||||
sql = f"SELECT * FROM harnessed_reasoning_sessions WHERE user_id = :user_id ORDER BY created_at DESC LIMIT {limit} OFFSET {offset}"
|
rows = await sor.R('harnessed_reasoning_sessions', {'user_id': user_id}, ns={'sort': 'created_at desc'})
|
||||||
rows = await sor.sqlExe(sql, {'user_id': user_id})
|
rows = rows or []
|
||||||
|
rows = rows[offset:offset + limit]
|
||||||
|
|
||||||
sessions = []
|
sessions = []
|
||||||
for s in rows:
|
for s in rows:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user