feat: desk ia

This commit is contained in:
OpenSquared
2026-06-29 19:50:18 +02:00
parent f7acca2152
commit 551ebc3ef4
2 changed files with 12 additions and 5 deletions

View File

@@ -1146,11 +1146,13 @@ def init_db():
]
for _desk in _AI_DESK_DEFAULTS:
try:
# Guard by type, not name — so renaming a desk doesn't trigger a re-seed
c.execute(
"INSERT OR IGNORE INTO ai_desks (name, type, active, system_prompt, instruments, config) "
"VALUES (?,?,?,?,?,?)",
"INSERT INTO ai_desks (name, type, active, system_prompt, instruments, config) "
"SELECT ?,?,?,?,?,? WHERE NOT EXISTS (SELECT 1 FROM ai_desks WHERE type = ?)",
(_desk["name"], _desk["type"], _desk["active"],
_desk["system_prompt"], _desk["instruments"], _desk["config"])
_desk["system_prompt"], _desk["instruments"], _desk["config"],
_desk["type"])
)
except Exception:
pass

View File

@@ -544,13 +544,18 @@ def _get_relevant_events(
(SELECT GROUP_CONCAT(DISTINCT a.instrument)
FROM causal_event_analyses a
WHERE a.market_event_id = e.id) AS analyzed_instruments,
(SELECT a.template_id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS template_id,
(SELECT a.template_id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS cea_template_id,
(SELECT a.id FROM causal_event_analyses a WHERE a.market_event_id = e.id ORDER BY a.id DESC LIMIT 1) AS analysis_id
FROM market_events e
ORDER BY e.start_date DESC
""").fetchall()
conn.close()
all_events = [dict(r) for r in rows]
# Use cea_template_id (from causal_event_analyses) explicitly to avoid
# any collision with an e.* column named template_id
all_events = [
{**dict(r), "template_id": r["cea_template_id"]}
for r in rows
]
except Exception as e:
logger.warning(f"[instrument_service] Could not load market events: {e}")
return []