tokensafe 2.2.0 → 2.3.0

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.
package/src/proxy.py CHANGED
@@ -26,6 +26,7 @@ from src.secret_redactor import SecretRedactor
26
26
  from src.graph_engine import GraphEngine
27
27
  from src.cache_normalizer import PromptCacheNormalizer
28
28
  from src.governor import ContextGovernor
29
+ from src.paths import resolve_data_dir
29
30
 
30
31
  DEFAULT_PORT = 8765
31
32
  DEFAULT_HOST = os.environ.get("HOST", os.environ.get("TOKENSAFE_HOST", "0.0.0.0"))
@@ -164,10 +165,7 @@ class TokenSafeProxyHandler(BaseHTTPRequestHandler):
164
165
  when the proxy is in the loop it REPLACES the last user message with the
165
166
  TOCP form, so hook-side injection would double-count the same prompt."""
166
167
  try:
167
- marker = os.path.join(
168
- os.environ.get("TOKENSAFE_DATA_DIR", os.path.join(BASE_DIR, "data")),
169
- ".proxy_active",
170
- )
168
+ marker = os.path.join(resolve_data_dir(), ".proxy_active")
171
169
  with open(marker, "w", encoding="utf-8") as f:
172
170
  f.write(str(int(__import__("time").time())))
173
171
  except Exception:
@@ -253,7 +251,7 @@ class TokenSafeProxyHandler(BaseHTTPRequestHandler):
253
251
  custom_url = os.environ.get("TOKENSAFE_UPSTREAM_URL", "")
254
252
 
255
253
  # Supported keys from environment or config
256
- data_dir = os.environ.get("TOKENSAFE_DATA_DIR", os.path.join(BASE_DIR, "data"))
254
+ data_dir = resolve_data_dir()
257
255
  conf_keys = {}
258
256
  config_path = os.path.join(data_dir, "config.json")
259
257
  if os.path.exists(config_path):
package/src/team_cache.py CHANGED
@@ -28,8 +28,9 @@ class TeamCache:
28
28
  """Checks if current active license belongs to a Team tier subscription."""
29
29
  key = os.environ.get("TOKENSAFE_LICENSE_KEY", "").strip()
30
30
  if not key:
31
+ from src.paths import resolve_data_dir
31
32
  candidate_paths = [
32
- os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data", "license.json"),
33
+ os.path.join(resolve_data_dir(), "license.json"),
33
34
  os.path.join(os.getcwd(), "data", "license.json"),
34
35
  os.path.expanduser("~/.tokensafe/license.json")
35
36
  ]
@@ -31,7 +31,9 @@ if PROJECT_ROOT not in sys.path:
31
31
  from src.license_manager import LicenseManager
32
32
  from src.metrics import resolve_measurement
33
33
 
34
- DATA_DIR = os.path.join(PROJECT_ROOT, "data")
34
+ from src.paths import resolve_data_dir
35
+
36
+ DATA_DIR = resolve_data_dir()
35
37
  METRICS_DB_PATH = os.path.join(DATA_DIR, "metrics.db")
36
38
  SYNC_STATE_PATH = os.path.join(DATA_DIR, "sync_state.json")
37
39
  SYNC_LOCK_PATH = os.path.join(DATA_DIR, ".sync.lock")
@@ -264,7 +266,7 @@ class TelemetrySync:
264
266
  rollup_synced = bool(state.get("lifetime_rollup_synced", False))
265
267
  headers = {
266
268
  "Content-Type": "application/json",
267
- "User-Agent": "TokenSafe-Sync/2.2.0"
269
+ "User-Agent": "TokenSafe-Sync/2.3.0"
268
270
  }
269
271
  if active_key:
270
272
  headers["Authorization"] = f"Bearer {active_key}"
@@ -16,7 +16,7 @@ import urllib.request
16
16
  import urllib.error
17
17
  from typing import Dict, Any, Optional, Tuple
18
18
 
19
- CURRENT_VERSION = "2.2.0"
19
+ CURRENT_VERSION = "2.3.0"
20
20
  CACHE_TTL = 86400 # 24 hours
21
21
  # When the cloud is unreachable we must NOT cache the synthesized "up to date"
22
22
  # answer for a full day — otherwise an update released right after an outage
@@ -24,8 +24,10 @@ CACHE_TTL = 86400 # 24 hours
24
24
  # "broken" while the backend was redeploying).
25
25
  FALLBACK_CACHE_TTL = 900 # 15 minutes
26
26
 
27
+ from src.paths import resolve_data_dir
28
+
27
29
  PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
28
- DATA_DIR = os.path.join(PROJECT_ROOT, "data")
30
+ DATA_DIR = resolve_data_dir()
29
31
  CACHE_FILE = os.path.join(DATA_DIR, "version_cache.json")
30
32
  CLOUD_CHECK_URL = os.environ.get("TOKENSAFE_VERSION_URL", "https://api.tokensafe.dev/api/version/check")
31
33
 
@@ -17,20 +17,22 @@ import sqlite3
17
17
  from contextlib import contextmanager
18
18
  from typing import Dict, List, Any, Optional, Tuple
19
19
 
20
+ from src.paths import resolve_data_dir
21
+
20
22
  PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
21
- DATA_DIR = os.environ.get("TOKENSAFE_DATA_DIR", os.path.join(PROJECT_ROOT, "data"))
23
+ DATA_DIR = resolve_data_dir()
22
24
  CLOUD_DB_PATH = os.environ.get("TOKENSAFE_CLOUD_DB_PATH", os.path.join(DATA_DIR, "cloud.db"))
23
25
 
24
26
 
25
27
  @contextmanager
26
28
  def _open_digest_db(db_path: str):
27
- """Yields BunnyDB/cloud connection for default DB path, or local sqlite3 for custom paths."""
29
+ """Yields Cloud DB/cloud connection for default DB path, or local sqlite3 for custom paths."""
28
30
  if db_path == CLOUD_DB_PATH:
29
31
  try:
30
32
  from src.cloud.db import get_db_connection
31
- from src.cloud.config import BUNNY_DB_URL, BUNNY_DB_TOKEN, CLOUD_DB_PATH as CLOUD_CFG_DB_PATH
33
+ from src.cloud.config import CLOUD_DB_URL, CLOUD_DB_TOKEN, CLOUD_DB_PATH as CLOUD_CFG_DB_PATH
32
34
 
33
- if (BUNNY_DB_URL and BUNNY_DB_TOKEN) or os.path.exists(CLOUD_CFG_DB_PATH):
35
+ if (CLOUD_DB_URL and CLOUD_DB_TOKEN) or os.path.exists(CLOUD_CFG_DB_PATH):
34
36
  with get_db_connection() as conn:
35
37
  yield conn
36
38
  return
@@ -71,7 +73,7 @@ class WeeklyDigestGenerator:
71
73
  ) -> Optional[Dict[str, Any]]:
72
74
  """
73
75
  Retrieves 7-day telemetry for team owned by owner_email.
74
- Supports both BunnyDB (cloud) and local SQLite databases.
76
+ Supports both Cloud DB (cloud) and local SQLite databases.
75
77
  Returns aggregated digest data or None if no eligible records found.
76
78
  """
77
79
  clean_email = (owner_email or "").strip().lower()