tokensafe 2.8.0 → 2.8.1
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/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/src/license_manager.py +40 -1
- package/src/mcp_server.py +1 -1
- package/src/metrics.py +14 -0
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "2.8.
|
|
4
|
+
"version": "2.8.1",
|
|
5
5
|
"description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
|
|
6
6
|
"main": "bin/tokensafe.js",
|
|
7
7
|
"bin": {
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "2.8.
|
|
4
|
+
"version": "2.8.1",
|
|
5
5
|
"description": "Reduce your AI bills by up to 99% locally. Your agents read only needed code, keep prompt caches intact across turns, and keep secrets out of git.",
|
|
6
6
|
"logo": "assets/logo.svg",
|
|
7
7
|
"author": {
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "dev.tokensafe/tokensafe",
|
|
4
4
|
"title": "TokenSafe",
|
|
5
5
|
"description": "Reduce your AI bills by up to 99% locally: focused code, warm prompt caches & zero secret leaks.",
|
|
6
|
-
"version": "2.8.
|
|
6
|
+
"version": "2.8.1",
|
|
7
7
|
"websiteUrl": "https://tokensafe.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/tokensafe-dev/tokensafe",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"registryType": "npm",
|
|
31
31
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
32
32
|
"identifier": "tokensafe",
|
|
33
|
-
"version": "2.8.
|
|
33
|
+
"version": "2.8.1",
|
|
34
34
|
"runtimeHint": "npx",
|
|
35
35
|
"transport": {
|
|
36
36
|
"type": "stdio"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"registryType": "pypi",
|
|
47
47
|
"registryBaseUrl": "https://pypi.org",
|
|
48
48
|
"identifier": "tokensafe",
|
|
49
|
-
"version": "2.8.
|
|
49
|
+
"version": "2.8.1",
|
|
50
50
|
"runtimeHint": "uvx",
|
|
51
51
|
"transport": {
|
|
52
52
|
"type": "stdio"
|
package/src/license_manager.py
CHANGED
|
@@ -448,6 +448,43 @@ class LicenseManager:
|
|
|
448
448
|
trial_note = " (7-Day Trial)" if payload.get("trial") else ""
|
|
449
449
|
return True, f"Successfully activated TokenSafe {tier_name}{trial_note}!"
|
|
450
450
|
|
|
451
|
+
@classmethod
|
|
452
|
+
def _get_server_quota_floor(cls, tracker: Optional[Any] = None) -> int:
|
|
453
|
+
"""Reads server-verified quota floor from mirror ledger (.qledger.json) within 30-day window."""
|
|
454
|
+
if tracker and hasattr(tracker, "get_server_quota_floor"):
|
|
455
|
+
try:
|
|
456
|
+
floor = int(tracker.get_server_quota_floor() or 0)
|
|
457
|
+
if floor > 0:
|
|
458
|
+
return floor
|
|
459
|
+
except Exception:
|
|
460
|
+
pass
|
|
461
|
+
try:
|
|
462
|
+
mirror_paths = []
|
|
463
|
+
if tracker and hasattr(tracker, "_quota_mirror_path"):
|
|
464
|
+
try:
|
|
465
|
+
mirror_paths.append(tracker._quota_mirror_path())
|
|
466
|
+
except Exception:
|
|
467
|
+
pass
|
|
468
|
+
base_dir = os.environ.get("TOKENSAFE_DATA_DIR") or (
|
|
469
|
+
os.path.dirname(os.environ["TOKENSAFE_DB_PATH"]) if os.environ.get("TOKENSAFE_DB_PATH") else None
|
|
470
|
+
)
|
|
471
|
+
if base_dir:
|
|
472
|
+
mirror_paths.append(os.path.join(base_dir, ".qledger.json"))
|
|
473
|
+
mirror_paths.append(os.path.join(os.path.dirname(DATA_DIR), ".qledger.json"))
|
|
474
|
+
mirror_paths.append(os.path.join(DATA_DIR, ".qledger.json"))
|
|
475
|
+
|
|
476
|
+
for mirror_path in mirror_paths:
|
|
477
|
+
if os.path.exists(mirror_path):
|
|
478
|
+
with open(mirror_path, "r", encoding="utf-8") as f:
|
|
479
|
+
data = json.load(f)
|
|
480
|
+
if isinstance(data, dict) and time.time() - float(data.get("server_floor_ts", 0)) <= 30 * 86400:
|
|
481
|
+
floor = int(data.get("server_floor", 0) or 0)
|
|
482
|
+
if floor > 0:
|
|
483
|
+
return floor
|
|
484
|
+
except Exception:
|
|
485
|
+
pass
|
|
486
|
+
return 0
|
|
487
|
+
|
|
451
488
|
@classmethod
|
|
452
489
|
def check_quota(cls, tracker: Optional[Any] = None) -> Dict[str, Any]:
|
|
453
490
|
"""
|
|
@@ -493,7 +530,9 @@ class LicenseManager:
|
|
|
493
530
|
except Exception:
|
|
494
531
|
tracker = None
|
|
495
532
|
|
|
496
|
-
|
|
533
|
+
local_saved = tracker.get_monthly_saved_tokens() if tracker else 0
|
|
534
|
+
server_floor = cls._get_server_quota_floor(tracker)
|
|
535
|
+
monthly_saved = max(local_saved, server_floor)
|
|
497
536
|
exceeded = monthly_saved >= max_tokens
|
|
498
537
|
|
|
499
538
|
warning = None
|
package/src/mcp_server.py
CHANGED
package/src/metrics.py
CHANGED
|
@@ -372,6 +372,20 @@ class MetricsTracker:
|
|
|
372
372
|
except Exception:
|
|
373
373
|
_do()
|
|
374
374
|
|
|
375
|
+
def get_server_quota_floor(self) -> int:
|
|
376
|
+
"""Returns the active server-verified measured quota floor from mirror ledger (within 30-day window)."""
|
|
377
|
+
mirror_path = self._quota_mirror_path()
|
|
378
|
+
try:
|
|
379
|
+
if os.path.exists(mirror_path):
|
|
380
|
+
with open(mirror_path, "r", encoding="utf-8") as f:
|
|
381
|
+
data = json.load(f)
|
|
382
|
+
if isinstance(data, dict):
|
|
383
|
+
if time.time() - float(data.get("server_floor_ts", 0)) <= 30 * 86400:
|
|
384
|
+
return int(data.get("server_floor", 0) or 0)
|
|
385
|
+
except Exception:
|
|
386
|
+
pass
|
|
387
|
+
return 0
|
|
388
|
+
|
|
375
389
|
def record_event(
|
|
376
390
|
self,
|
|
377
391
|
session_id: str,
|
package/src/telemetry_sync.py
CHANGED
|
@@ -228,7 +228,7 @@ class TelemetrySync:
|
|
|
228
228
|
current_last_id = last_id
|
|
229
229
|
headers = {
|
|
230
230
|
"Content-Type": "application/json",
|
|
231
|
-
"User-Agent": "TokenSafe-Sync/2.8.
|
|
231
|
+
"User-Agent": "TokenSafe-Sync/2.8.1"
|
|
232
232
|
}
|
|
233
233
|
if active_key:
|
|
234
234
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/version_checker.py
CHANGED
|
@@ -17,7 +17,7 @@ import urllib.request
|
|
|
17
17
|
import urllib.error
|
|
18
18
|
from typing import Dict, Any, Optional, Tuple
|
|
19
19
|
|
|
20
|
-
CURRENT_VERSION = "2.8.
|
|
20
|
+
CURRENT_VERSION = "2.8.1"
|
|
21
21
|
CACHE_TTL = 86400 # 24 hours
|
|
22
22
|
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
23
23
|
# answer for a full day — otherwise an update released right after an outage
|