amfs-http-server 0.3.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amfs-http-server
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: AMFS HTTP/REST API server with SSE support
5
5
  License-Expression: Apache-2.0
6
6
  Requires-Python: >=3.11
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "amfs-http-server"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "AMFS HTTP/REST API server with SSE support"
5
5
  requires-python = ">=3.11"
6
6
  license = "Apache-2.0"
@@ -1704,6 +1704,72 @@ async def recover_snapshot(
1704
1704
  }
1705
1705
 
1706
1706
 
1707
+ # ──────────────────────────────────────────────────────────────────────
1708
+ # Rollback
1709
+ # ──────────────────────────────────────────────────────────────────────
1710
+
1711
+
1712
+ @app.post("/api/v1/rollback")
1713
+ async def rollback(
1714
+ body: dict[str, Any],
1715
+ _auth: str | None = Depends(verify_api_key),
1716
+ ) -> dict[str, Any]:
1717
+ """Rollback an agent's memory to a specific event or timestamp.
1718
+
1719
+ Accepts either ``target_event_id`` (looks up the event to get its
1720
+ timestamp and agent) or ``target_timestamp`` + ``agent_id``.
1721
+ """
1722
+ mem = _get_memory()
1723
+ target_event_id = body.get("target_event_id")
1724
+ target_timestamp = body.get("target_timestamp")
1725
+ agent_id = body.get("agent_id")
1726
+
1727
+ if target_event_id:
1728
+ event = mem._adapter.get_event(target_event_id, mem.namespace)
1729
+ if event is None:
1730
+ raise HTTPException(status_code=404, detail="Event not found")
1731
+ timestamp = event.created_at
1732
+ agent_id = agent_id or event.agent_id
1733
+ elif target_timestamp:
1734
+ if not agent_id:
1735
+ raise HTTPException(
1736
+ status_code=400,
1737
+ detail="agent_id is required when using target_timestamp",
1738
+ )
1739
+ timestamp = datetime.fromisoformat(target_timestamp)
1740
+ else:
1741
+ raise HTTPException(
1742
+ status_code=400,
1743
+ detail="Provide target_event_id or target_timestamp",
1744
+ )
1745
+
1746
+ count = mem._adapter.rollback_to_timestamp(
1747
+ agent_id, "main", timestamp, mem.namespace,
1748
+ )
1749
+
1750
+ try:
1751
+ mem._adapter.log_event(Event(
1752
+ namespace=mem.namespace,
1753
+ agent_id=agent_id,
1754
+ branch="main",
1755
+ event_type=EventType.ROLLBACK,
1756
+ summary=f"Rolled back to {timestamp.isoformat()}",
1757
+ details={
1758
+ "rolled_back_to": timestamp.isoformat(),
1759
+ "entries_restored": count,
1760
+ "source_event_id": target_event_id,
1761
+ },
1762
+ ))
1763
+ except Exception:
1764
+ logger.debug("Failed to log rollback event", exc_info=True)
1765
+
1766
+ return {
1767
+ "entries_restored": count,
1768
+ "rolled_back_to": timestamp.isoformat(),
1769
+ "agent_id": agent_id,
1770
+ }
1771
+
1772
+
1707
1773
  # ──────────────────────────────────────────────────────────────────────
1708
1774
  # Agent-scoped branches & pull requests
1709
1775
  # ──────────────────────────────────────────────────────────────────────