tokensafe 1.3.7 → 1.3.8
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/src/cli.py +6 -0
- package/src/deepseek_distiller.py +5 -0
- package/src/distiller.py +62 -0
- package/src/version_checker.py +1 -1
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-token-optimizer",
|
|
3
3
|
"displayName": "TokenSafe",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.8",
|
|
5
5
|
"description": "Zero-Loss Token Economy & Context Optimizer for AI Agents. Compresses prompts, slices AST/tool outputs, and prevents stuck loops.",
|
|
6
6
|
"logo": "assets/logo.svg",
|
|
7
7
|
"author": {
|
package/src/cli.py
CHANGED
|
@@ -195,7 +195,13 @@ def main():
|
|
|
195
195
|
print(" \033[1mTo unlock Neural LLM Distillation:\033[0m")
|
|
196
196
|
print(" 1. Start 7-day free trial or upgrade at: \033[36mhttps://tokensafe.dev\033[0m")
|
|
197
197
|
print(" 2. Activate your key: \033[32mtokensafe activate <KEY>\033[0m\n")
|
|
198
|
+
elif not UniversalDistiller.is_self_hosted():
|
|
199
|
+
print(f" \033[32m✔\033[0m \033[1mTokenSafe Cloud Distiller\033[0m [Active: gemini-flash-lite-latest via Managed Cloud]")
|
|
200
|
+
print(" Zero API keys required — managed centrally by your TokenSafe subscription.")
|
|
201
|
+
print(" Shared Team Cache & sub-millisecond cloud cache active.\n")
|
|
202
|
+
print(" \033[2m💡 Tip: To run self-hosted with custom BYOK keys in Docker, export TOKENSAFE_SELF_HOSTED=1.\033[0m\n")
|
|
198
203
|
else:
|
|
204
|
+
print(" \033[36mMode: Self-Hosted Docker (Custom BYOK Keys)\033[0m\n")
|
|
199
205
|
configured = UniversalDistiller.get_configured_providers()
|
|
200
206
|
all_p = UniversalDistiller.PROVIDERS
|
|
201
207
|
for key, p in all_p.items():
|
|
@@ -79,6 +79,11 @@ Rules:
|
|
|
79
79
|
if tier == "free":
|
|
80
80
|
return None
|
|
81
81
|
|
|
82
|
+
# In standard SaaS mode, delegate to UniversalDistiller's Managed Cloud Distillation
|
|
83
|
+
if os.environ.get("TOKENSAFE_SELF_HOSTED", "").lower() not in ("1", "true", "yes"):
|
|
84
|
+
from src.distiller import UniversalDistiller
|
|
85
|
+
return UniversalDistiller.distill(raw_text)
|
|
86
|
+
|
|
82
87
|
conf = cls._get_config()
|
|
83
88
|
if not conf["enabled"] or not conf["api_key"] or not raw_text or len(raw_text.strip()) < 10:
|
|
84
89
|
return None
|
package/src/distiller.py
CHANGED
|
@@ -63,6 +63,35 @@ Rules:
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
@classmethod
|
|
67
|
+
def is_self_hosted(cls) -> bool:
|
|
68
|
+
"""Determines if running in Docker self-hosted mode with custom BYOK keys."""
|
|
69
|
+
return os.environ.get("TOKENSAFE_SELF_HOSTED", "").lower() in ("1", "true", "yes")
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def _call_cloud_distill(cls, raw_text: str, lic_key: str) -> Optional[str]:
|
|
73
|
+
cloud_url = os.environ.get("TOKENSAFE_CLOUD_URL", "https://api.tokensafe.dev").rstrip("/")
|
|
74
|
+
endpoint = f"{cloud_url}/api/distill"
|
|
75
|
+
payload = {"prompt": raw_text.strip()}
|
|
76
|
+
req = urllib.request.Request(
|
|
77
|
+
endpoint,
|
|
78
|
+
data=json.dumps(payload).encode("utf-8"),
|
|
79
|
+
headers={
|
|
80
|
+
"Authorization": f"Bearer {lic_key}",
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
"User-Agent": "TokenSafe/1.3.7"
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
try:
|
|
86
|
+
with urllib.request.urlopen(req, timeout=cls.DEFAULT_TIMEOUT) as resp:
|
|
87
|
+
if resp.status == 200:
|
|
88
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
89
|
+
if data.get("success") and data.get("distilled"):
|
|
90
|
+
return data["distilled"].strip()
|
|
91
|
+
except Exception:
|
|
92
|
+
return None
|
|
93
|
+
return None
|
|
94
|
+
|
|
66
95
|
@classmethod
|
|
67
96
|
def get_configured_providers(cls) -> Dict[str, Dict[str, Any]]:
|
|
68
97
|
"""Scans environment and data/config.json for configured LLM distillation keys."""
|
|
@@ -70,6 +99,16 @@ Rules:
|
|
|
70
99
|
if tier == "free":
|
|
71
100
|
return {}
|
|
72
101
|
|
|
102
|
+
if not cls.is_self_hosted():
|
|
103
|
+
return {
|
|
104
|
+
"cloud": {
|
|
105
|
+
"provider": "cloud",
|
|
106
|
+
"name": "TokenSafe Cloud Distiller",
|
|
107
|
+
"model": "gemini-flash-lite-latest",
|
|
108
|
+
"status": "managed"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
73
112
|
config_file_data = {}
|
|
74
113
|
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
75
114
|
config_path = os.path.join(base_dir, "data", "config.json")
|
|
@@ -127,6 +166,29 @@ Rules:
|
|
|
127
166
|
if not providers:
|
|
128
167
|
return None
|
|
129
168
|
|
|
169
|
+
# 1. Managed Cloud Distillation (Default for Solo/Team SaaS)
|
|
170
|
+
if "cloud" in providers:
|
|
171
|
+
lic_key = os.environ.get("TOKENSAFE_LICENSE_KEY", "").strip()
|
|
172
|
+
if not lic_key:
|
|
173
|
+
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
174
|
+
lic_file = os.path.join(base_dir, "data", "license.json")
|
|
175
|
+
if os.path.exists(lic_file):
|
|
176
|
+
try:
|
|
177
|
+
with open(lic_file, "r", encoding="utf-8") as f:
|
|
178
|
+
lic_key = json.load(f).get("license_key", "").strip()
|
|
179
|
+
except Exception:
|
|
180
|
+
pass
|
|
181
|
+
|
|
182
|
+
if lic_key:
|
|
183
|
+
cloud_res = cls._call_cloud_distill(raw_text, lic_key)
|
|
184
|
+
if cloud_res:
|
|
185
|
+
clean = cls._sanitize_s_expression(cloud_res)
|
|
186
|
+
if clean:
|
|
187
|
+
DistillationCache.set(raw_text, clean, provider="cloud-managed")
|
|
188
|
+
return clean
|
|
189
|
+
return None
|
|
190
|
+
|
|
191
|
+
# 2. Self-Hosted Docker Mode (BYOK local providers)
|
|
130
192
|
# Determine order
|
|
131
193
|
pref = preferred_provider
|
|
132
194
|
if not pref:
|
package/src/version_checker.py
CHANGED
|
@@ -14,7 +14,7 @@ import urllib.request
|
|
|
14
14
|
import urllib.error
|
|
15
15
|
from typing import Dict, Any, Optional, Tuple
|
|
16
16
|
|
|
17
|
-
CURRENT_VERSION = "1.3.
|
|
17
|
+
CURRENT_VERSION = "1.3.8"
|
|
18
18
|
CACHE_TTL = 86400 # 24 hours
|
|
19
19
|
|
|
20
20
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|