tokensafe 1.3.2 → 1.3.4
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/__init__.py +1 -1
- package/src/dashboard.py +8 -8
- package/src/distiller.py +14 -3
- package/src/mcp_server.py +1 -1
- package/src/proxy.py +5 -1
- 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.4",
|
|
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/__init__.py
CHANGED
package/src/dashboard.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Terminal & Interactive HTML Dashboard for
|
|
2
|
+
Terminal & Interactive HTML Dashboard for TokenSafe Context & Token Optimizer.
|
|
3
3
|
Provides colorful CLI reports, Markdown exports, and rich modern HTML widgets.
|
|
4
4
|
"""
|
|
5
5
|
|
|
@@ -68,7 +68,7 @@ class Dashboard:
|
|
|
68
68
|
|
|
69
69
|
out = []
|
|
70
70
|
out.append(f"\n{BOLD}{CYAN}╔════════════════════════════════════════════════════════════════════╗{RESET}")
|
|
71
|
-
out.append(f"{BOLD}{CYAN}║ ⚡
|
|
71
|
+
out.append(f"{BOLD}{CYAN}║ ⚡ TOKENSAFE CONTEXT OPTIMIZER DASHBOARD ⚡ ║{RESET}")
|
|
72
72
|
out.append(f"{BOLD}{CYAN}╚════════════════════════════════════════════════════════════════════╝{RESET}\n")
|
|
73
73
|
|
|
74
74
|
# Top summary cards
|
|
@@ -105,8 +105,8 @@ class Dashboard:
|
|
|
105
105
|
|
|
106
106
|
out.append(f" [{DIM}{t_str}{RESET}] {CYAN}{ev_type:<15}{RESET} {detail_desc:<20} ➔ {GREEN}+{saved:,} saved{RESET} ({pct_ev:.1f}%)")
|
|
107
107
|
|
|
108
|
-
out.append(f"\n{DIM}Run `
|
|
109
|
-
out.append(f"{DIM}Run `agy-tokens html` to view interactive browser dashboard.{RESET}")
|
|
108
|
+
out.append(f"\n{DIM}Run `tokensafe test \"<prompt>\"` (or `agy-tokens`) to test compression on custom input.{RESET}")
|
|
109
|
+
out.append(f"{DIM}Run `tokensafe html` (or `agy-tokens html`) to view interactive browser dashboard.{RESET}")
|
|
110
110
|
|
|
111
111
|
if VersionChecker:
|
|
112
112
|
banner = VersionChecker.get_banner()
|
|
@@ -129,7 +129,7 @@ class Dashboard:
|
|
|
129
129
|
opt = summary["total_optimized_tokens"]
|
|
130
130
|
|
|
131
131
|
md = []
|
|
132
|
-
md.append("# ⚡
|
|
132
|
+
md.append("# ⚡ TokenSafe Context & Token Optimizer Report\n")
|
|
133
133
|
md.append(f"> **Cumulative Resource Efficiency:** **{pct:.1f}% Reduction** across {summary['total_events']} events.\n")
|
|
134
134
|
md.append("| Metric | Value |")
|
|
135
135
|
md.append("| :--- | :--- |")
|
|
@@ -208,7 +208,7 @@ class Dashboard:
|
|
|
208
208
|
<head>
|
|
209
209
|
<meta charset="UTF-8">
|
|
210
210
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
211
|
-
<title>⚡
|
|
211
|
+
<title>⚡ TokenSafe Context Optimizer Dashboard</title>
|
|
212
212
|
<style>
|
|
213
213
|
:root {{
|
|
214
214
|
--bg: #090a0f;
|
|
@@ -259,8 +259,8 @@ class Dashboard:
|
|
|
259
259
|
<div class="container">
|
|
260
260
|
<div class="header">
|
|
261
261
|
<div>
|
|
262
|
-
<h1 class="title">⚡
|
|
263
|
-
<p class="subtitle">
|
|
262
|
+
<h1 class="title">⚡ TokenSafe</h1>
|
|
263
|
+
<p class="subtitle">Autonomous Zero-Loss Token Economy & Context Preservation</p>
|
|
264
264
|
</div>
|
|
265
265
|
<div id="live-pill" class="subtitle" style="display: flex; align-items: center; gap: 6px;">
|
|
266
266
|
<span style="color: #10b981;">●</span> Live SQLite Tracking
|
package/src/distiller.py
CHANGED
|
@@ -54,7 +54,7 @@ Rules:
|
|
|
54
54
|
"name": "Google Gemini",
|
|
55
55
|
"env_key": "GEMINI_API_KEY",
|
|
56
56
|
"config_key": "gemini_api_key",
|
|
57
|
-
"default_model": "gemini-
|
|
57
|
+
"default_model": "gemini-flash-lite-latest",
|
|
58
58
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={key}"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -115,9 +115,20 @@ Rules:
|
|
|
115
115
|
return None
|
|
116
116
|
|
|
117
117
|
# Determine order
|
|
118
|
+
pref = preferred_provider
|
|
119
|
+
if not pref:
|
|
120
|
+
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
121
|
+
config_path = os.path.join(base_dir, "data", "config.json")
|
|
122
|
+
if os.path.exists(config_path):
|
|
123
|
+
try:
|
|
124
|
+
with open(config_path, "r", encoding="utf-8") as f:
|
|
125
|
+
pref = json.load(f).get("preferred_provider")
|
|
126
|
+
except Exception:
|
|
127
|
+
pass
|
|
128
|
+
|
|
118
129
|
order = []
|
|
119
|
-
if
|
|
120
|
-
order.append(
|
|
130
|
+
if pref and pref in providers:
|
|
131
|
+
order.append(pref)
|
|
121
132
|
# Add remaining in priority order
|
|
122
133
|
for p in ["gemini", "openai", "deepseek"]:
|
|
123
134
|
if p in providers and p not in order:
|
package/src/mcp_server.py
CHANGED
package/src/proxy.py
CHANGED
|
@@ -232,8 +232,12 @@ class TokenSafeProxyHandler(BaseHTTPRequestHandler):
|
|
|
232
232
|
generic_upstream_key = os.environ.get("TOKENSAFE_UPSTREAM_KEY", "")
|
|
233
233
|
|
|
234
234
|
# Infer upstream URL if not provided
|
|
235
|
+
pref = conf_keys.get("preferred_provider", "").lower()
|
|
235
236
|
if not custom_url:
|
|
236
|
-
if
|
|
237
|
+
if (pref == "gemini" and gemini_key) or (gemini_key and not deepseek_key and not openai_key):
|
|
238
|
+
upstream_url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"
|
|
239
|
+
resolved_key = gemini_key
|
|
240
|
+
elif openai_key and not deepseek_key:
|
|
237
241
|
upstream_url = "https://api.openai.com/v1/chat/completions"
|
|
238
242
|
resolved_key = openai_key
|
|
239
243
|
elif anthropic_key and not deepseek_key:
|
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.4"
|
|
18
18
|
CACHE_TTL = 86400 # 24 hours
|
|
19
19
|
|
|
20
20
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|