memorybot 0.2.0__tar.gz → 0.3.0__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.0
3
+ Version: 0.3.0
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.0"
7
+ version = "0.3.0"
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.0"
3
+ __version__ = "0.3.0"
@@ -2,12 +2,13 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import os
5
6
  from typing import Any
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
11
12
 
12
13
  TOOL_EXEC_PATH = "/memory/api/tool-exec/"
13
14
 
@@ -32,11 +33,17 @@ class Client:
32
33
  self.cfg = cfg
33
34
  self.server_url = server_url
34
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
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)
@@ -52,6 +52,7 @@ class Config:
52
52
  self.refresh_token = None
53
53
  self.expires_at = None
54
54
  self.user_email = None
55
+ self.server_url = DEFAULT_SERVER_URL
55
56
 
56
57
 
57
58
  def resolve_server_url(cli_override: Optional[str], cfg: Config) -> str:
@@ -62,3 +63,15 @@ def resolve_server_url(cli_override: Optional[str], cfg: Config) -> str:
62
63
  if env:
63
64
  return env.rstrip("/")
64
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