memorybot 0.2.1__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: memorybot
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: MemoryBot CLI — your personal knowledge graph from the command line
5
5
  Project-URL: Homepage, https://www.memorybot.com
6
6
  Project-URL: Repository, https://github.com/nolanlove/memorybot-cli
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "memorybot"
7
- version = "0.2.1"
7
+ version = "0.3.1"
8
8
  description = "MemoryBot CLI — your personal knowledge graph from the command line"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,3 +1,3 @@
1
1
  """MemoryBot CLI."""
2
2
 
3
- __version__ = "0.2.1"
3
+ __version__ = "0.3.1"
@@ -2,12 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Any
5
+ import os
6
+ from typing import Any, Optional
6
7
 
7
8
  import httpx
8
9
 
9
10
  from .auth import refresh_access_token
10
- from .config import Config
11
+ from .config import Config, resolve_access_token, resolve_server_url
11
12
 
12
13
  TOOL_EXEC_PATH = "/memory/api/tool-exec/"
13
14
 
@@ -28,15 +29,21 @@ class ToolError(RuntimeError):
28
29
 
29
30
 
30
31
  class Client:
31
- def __init__(self, cfg: Config, server_url: str) -> None:
32
- self.cfg = cfg
33
- self.server_url = server_url
32
+ def __init__(self, cfg: Optional[Config] = None, server_url: Optional[str] = None) -> None:
33
+ self.cfg = cfg if cfg is not None else Config.load()
34
+ self.server_url = server_url or resolve_server_url(None, self.cfg)
35
+
36
+ def _token(self) -> str:
37
+ token = resolve_access_token(self.cfg)
38
+ if not token:
39
+ raise RuntimeError(
40
+ "No credentials. Run `mb login`, or set MEMORYBOT_TOKEN."
41
+ )
42
+ return token
34
43
 
35
44
  def _headers(self) -> dict[str, str]:
36
- if not self.cfg.access_token:
37
- raise RuntimeError("Not logged in. Run `mb login`.")
38
45
  return {
39
- "Authorization": f"Bearer {self.cfg.access_token}",
46
+ "Authorization": f"Bearer {self._token()}",
40
47
  "Content-Type": "application/json",
41
48
  }
42
49
 
@@ -50,7 +57,11 @@ class Client:
50
57
  body = {"tool": tool, "arguments": arguments}
51
58
 
52
59
  resp = httpx.post(url, headers=self._headers(), json=body, timeout=60.0)
53
- if resp.status_code == 401 and refresh_access_token(self.cfg, self.server_url):
60
+ # Only attempt refresh when using the saved-config token; env-var
61
+ # tokens are short-lived by design and the caller is expected to
62
+ # re-mint via mint_session_token instead.
63
+ env_token = bool(os.environ.get("MEMORYBOT_TOKEN"))
64
+ if resp.status_code == 401 and not env_token and refresh_access_token(self.cfg, self.server_url):
54
65
  resp = httpx.post(url, headers=self._headers(), json=body, timeout=60.0)
55
66
  if resp.status_code >= 400:
56
67
  raise APIError(resp.status_code, resp.text)
@@ -63,3 +63,15 @@ def resolve_server_url(cli_override: Optional[str], cfg: Config) -> str:
63
63
  if env:
64
64
  return env.rstrip("/")
65
65
  return cfg.server_url.rstrip("/")
66
+
67
+
68
+ def resolve_access_token(cfg: Config) -> Optional[str]:
69
+ """Precedence: MEMORYBOT_TOKEN env > config.
70
+
71
+ Env-var path is used by LLM Python sandboxes that bootstrap auth via
72
+ the MCP `mint_session_token` tool — no `mb login` needed.
73
+ """
74
+ env = os.environ.get("MEMORYBOT_TOKEN")
75
+ if env:
76
+ return env.strip()
77
+ return cfg.access_token
File without changes
File without changes
File without changes