Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/python/src/memoria/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _map_error(resp: httpx.Response) -> MemoriaAPIError:

def _backoff(attempt: int) -> float:
"""Exponential backoff: 0.5s, 1s, 2s, …"""
return 0.5 * (2 ** attempt)
return 0.5 * float(2**attempt)


class _HttpTransport:
Expand Down
45 changes: 26 additions & 19 deletions sdk/python/src/memoria/resources/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
import builtins
from typing import TYPE_CHECKING, Any, cast

from ..models import ApplyResult, Branch

Expand Down Expand Up @@ -39,7 +40,7 @@ def checkout(self, name: str) -> None:

def diff(self, name: str) -> dict[str, Any]:
"""Return high-level diff statistics (no pagination)."""
return self._client._request("GET", f"/v1/branches/{name}/diff") # type: ignore[return-value]
return cast(dict[str, Any], self._client._request("GET", f"/v1/branches/{name}/diff"))

def diff_items(
self,
Expand All @@ -50,8 +51,9 @@ def diff_items(
) -> dict[str, Any]:
"""Return per-entry diff with optional pagination."""
params = _strip_none({"limit": limit, "cursor": cursor})
return self._client._request( # type: ignore[return-value]
"GET", f"/v1/branches/{name}/diff-items", params=params
return cast(
dict[str, Any],
self._client._request("GET", f"/v1/branches/{name}/diff-items", params=params),
)

def merge(self, name: str, *, strategy: str = "accept") -> None:
Expand All @@ -64,10 +66,10 @@ def apply(
self,
name: str,
*,
adds: list[str] | None = None,
removes: list[str] | None = None,
updates: list[dict[str, str]] | None = None,
accept_branch_conflicts: list[str] | None = None,
adds: builtins.list[str] | None = None,
removes: builtins.list[str] | None = None,
updates: builtins.list[dict[str, str]] | None = None,
accept_branch_conflicts: builtins.list[str] | None = None,
) -> ApplyResult:
body = _strip_none(
{
Expand Down Expand Up @@ -97,8 +99,9 @@ def pick(
"dry_run": dry_run,
}
)
return self._client._request( # type: ignore[return-value]
"POST", f"/v1/branches/{name}/pick", json=body
return cast(
dict[str, Any],
self._client._request("POST", f"/v1/branches/{name}/pick", json=body),
)


Expand All @@ -125,7 +128,9 @@ async def checkout(self, name: str) -> None:
await self._client._arequest("POST", f"/v1/branches/{name}/checkout", json={})

async def diff(self, name: str) -> dict[str, Any]:
return await self._client._arequest("GET", f"/v1/branches/{name}/diff") # type: ignore[return-value]
return cast(
dict[str, Any], await self._client._arequest("GET", f"/v1/branches/{name}/diff")
)

async def diff_items(
self,
Expand All @@ -135,8 +140,9 @@ async def diff_items(
cursor: str | None = None,
) -> dict[str, Any]:
params = _strip_none({"limit": limit, "cursor": cursor})
return await self._client._arequest( # type: ignore[return-value]
"GET", f"/v1/branches/{name}/diff-items", params=params
return cast(
dict[str, Any],
await self._client._arequest("GET", f"/v1/branches/{name}/diff-items", params=params),
)

async def merge(self, name: str, *, strategy: str = "accept") -> None:
Expand All @@ -151,10 +157,10 @@ async def apply(
self,
name: str,
*,
adds: list[str] | None = None,
removes: list[str] | None = None,
updates: list[dict[str, str]] | None = None,
accept_branch_conflicts: list[str] | None = None,
adds: builtins.list[str] | None = None,
removes: builtins.list[str] | None = None,
updates: builtins.list[dict[str, str]] | None = None,
accept_branch_conflicts: builtins.list[str] | None = None,
) -> ApplyResult:
body = _strip_none(
{
Expand Down Expand Up @@ -184,6 +190,7 @@ async def pick(
"dry_run": dry_run,
}
)
return await self._client._arequest( # type: ignore[return-value]
"POST", f"/v1/branches/{name}/pick", json=body
return cast(
dict[str, Any],
await self._client._arequest("POST", f"/v1/branches/{name}/pick", json=body),
)
13 changes: 7 additions & 6 deletions sdk/python/src/memoria/resources/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import builtins
import json
import math
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -451,7 +452,7 @@ def query(
*,
extra_metadata_filter: dict[str, Any] | None = None,
subject_id: str | None = None,
memory_types: list[str] | None = None,
memory_types: builtins.list[str] | None = None,
session_id: str | None = None,
trust_tier: str | None = None,
branch: str | None = None,
Expand Down Expand Up @@ -533,10 +534,10 @@ def delete(
def purge(
self,
*,
memory_ids: list[str] | None = None,
memory_ids: builtins.list[str] | None = None,
topic: str | None = None,
session_id: str | None = None,
memory_types: list[str] | None = None,
memory_types: builtins.list[str] | None = None,
reason: str | None = None,
branch: str | None = None,
) -> PurgeResult:
Expand Down Expand Up @@ -746,7 +747,7 @@ async def query(
*,
extra_metadata_filter: dict[str, Any] | None = None,
subject_id: str | None = None,
memory_types: list[str] | None = None,
memory_types: builtins.list[str] | None = None,
session_id: str | None = None,
trust_tier: str | None = None,
branch: str | None = None,
Expand Down Expand Up @@ -828,10 +829,10 @@ async def delete(
async def purge(
self,
*,
memory_ids: list[str] | None = None,
memory_ids: builtins.list[str] | None = None,
topic: str | None = None,
session_id: str | None = None,
memory_types: list[str] | None = None,
memory_types: builtins.list[str] | None = None,
reason: str | None = None,
branch: str | None = None,
) -> PurgeResult:
Expand Down
21 changes: 15 additions & 6 deletions sdk/python/src/memoria/resources/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import builtins
from typing import TYPE_CHECKING, Any

from ..exceptions import MemoriaValidationError
Expand All @@ -28,10 +29,14 @@ def list(self, *, limit: int = 20, offset: int = 0) -> list[Snapshot]:
params = {"limit": limit, "offset": offset}
data = self._client._request("GET", "/v1/snapshots", params=params)
# Server may return {"snapshots": [...], "has_more": bool} or a plain list
# An empty body (204) or a null field would otherwise be iterated as None.
items: builtins.list[Any]
if isinstance(data, dict):
items = data.get("snapshots", data.get("items", []))
else:
items = data.get("snapshots") or data.get("items") or []
elif isinstance(data, builtins.list):
items = data
else:
items = []
return [Snapshot.from_dict(s) for s in items]

def rollback(self, name: str) -> None:
Expand All @@ -41,7 +46,7 @@ def delete(
self,
name: str | None = None,
*,
names: list[str] | None = None,
names: builtins.list[str] | None = None,
prefix: str | None = None,
older_than: str | None = None,
) -> None:
Expand Down Expand Up @@ -85,10 +90,14 @@ async def create(self, name: str, *, description: str | None = None) -> Snapshot
async def list(self, *, limit: int = 20, offset: int = 0) -> list[Snapshot]:
params = {"limit": limit, "offset": offset}
data = await self._client._arequest("GET", "/v1/snapshots", params=params)
# An empty body (204) or a null field would otherwise be iterated as None.
items: builtins.list[Any]
if isinstance(data, dict):
items = data.get("snapshots", data.get("items", []))
else:
items = data.get("snapshots") or data.get("items") or []
elif isinstance(data, builtins.list):
items = data
else:
items = []
return [Snapshot.from_dict(s) for s in items]

async def rollback(self, name: str) -> None:
Expand All @@ -98,7 +107,7 @@ async def delete(
self,
name: str | None = None,
*,
names: list[str] | None = None,
names: builtins.list[str] | None = None,
prefix: str | None = None,
older_than: str | None = None,
) -> None:
Expand Down
Loading