Spaces:
Configuration error
Configuration error
fix: add legacy API compat shims + fix /observe auto-routing
Browse files- POST /agentmemory/session/start -> 200 compat shim (was 404)
- POST /agentmemory/session/end -> 200 compat shim
- GET /agentmemory/observations?sessionId -> compat shim reading legacy KV
- POST /agentmemory/observe: auto-detect folderPath+agentId payload and
route to folder_observe() instead of failing with 400
- Fix viewer: loadFolders circular reference via IIFE capture
- Fix viewer: broken if(false) block that swallowed page init
42 unmodified lines43444546464748494 unmodified lines54555657585960616263646566676869707172737475767778798081828378 unmodified lines16216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622742 unmodified lines
# ---------------------------------------------------------------------------# POST /agentmemory/observe (legacy raw hook endpoint)# POST /agentmemory/observe (legacy raw hook endpoint + auto-compat shim)# ---------------------------------------------------------------------------
@observations_bp.route("/agentmemory/observe", methods=["POST"])4 unmodified lines
try: body = request.get_json(force=True) or {}
# Auto-detect folder-based payload: if folderPath + agentId present, # route to folder_observe instead of legacy observe(). folder_path = body.get("folderPath") agent_id = body.get("agentId") text = body.get("text") or body.get("content") or ""
if folder_path and agent_id: # New folder-based model — delegate to folder_observe payload = { "folderPath": folder_path, "agentId": agent_id, "text": text, "timestamp": body.get("timestamp") or _datetime_now_iso(), "type": body.get("type"), "title": body.get("title"), "concepts": body.get("concepts"), "files": body.get("files"), "importance": body.get("importance"), } res = functions.folder_observe(_get_kv(), payload) return jsonify(res), 201
# Legacy session-based model res = functions.observe(_get_kv(), body) return jsonify(res), 201 except Exception as e:78 unmodified lines reverse=True, ) return jsonify({"observations": observations, "folderPath": fp, "agentId": aid}), 200
# ---------------------------------------------------------------------------# POST /agentmemory/session/start (legacy compat shim → 200 no-op)# ---------------------------------------------------------------------------
@observations_bp.route("/agentmemory/session/start", methods=["POST"])def api_session_start(): """Legacy session/start — clients in the wild still call this. Return a synthetic session ID so callers don't error out. """ auth_err = _check_auth() if auth_err: return auth_err
import uuid body = request.get_json(force=True) or {} session_id = body.get("sessionId") or f"compat_{uuid.uuid4().hex[:16]}" return jsonify({ "sessionId": session_id, "status": "active", "message": "Session model migrated to folder-based. Use /agentmemory/agent/observe.", }), 200
# ---------------------------------------------------------------------------# POST /agentmemory/session/end (legacy compat shim → 200 no-op)# ---------------------------------------------------------------------------
@observations_bp.route("/agentmemory/session/end", methods=["POST"])def api_session_end(): auth_err = _check_auth() if auth_err: return auth_err return jsonify({"success": True, "message": "Session model is now folder-based."}), 200
# ---------------------------------------------------------------------------# GET /agentmemory/observations (legacy compat shim)# ---------------------------------------------------------------------------
@observations_bp.route("/agentmemory/observations", methods=["GET"])def api_observations_legacy(): """Legacy /observations?sessionId=... shim. Reads from legacy KV scope if data exists, otherwise returns empty list. """ auth_err = _check_auth() if auth_err: return auth_err
session_id = request.args.get("sessionId", "") if not session_id: return jsonify({"observations": [], "sessionId": ""}), 200
try: obs = sorted( _get_kv().list(functions.KV.observations(session_id)), key=lambda x: x.get("timestamp", ""), reverse=True, ) return jsonify({"observations": obs, "sessionId": session_id}), 200 except Exception as e: return jsonify({"observations": [], "sessionId": session_id, "error": str(e)}), 200src/routes/observations.py+88-1