Aster Vale commited on
Commit
5831832
·
1 Parent(s): e79ae2f

feat: credit balance bar + LoomToken display + /mo pricing

Browse files

- Add API key bar showing live LoomToken balance (from /v1/loomcredits/balance)
- Inline API key input (password field + save/clear)
- Per-result card shows: 100 LoomTokens + /bin/zsh.10 + balance after call
- Balance before/after delta calculated per estimate call
- Pricing: Pro → /mo (was ), Add 'Introductory price' label
- Fix all credit packs: =1000 LoomTokens (was /bin/zsh.001/credit)

Files changed (3) hide show
  1. README.md +62 -60
  2. index.html +123 -1
  3. token-estimator.html +19 -5
README.md CHANGED
@@ -1,65 +1,67 @@
1
- ---
2
- title: LoomLens AI
3
- emoji: ⚡
4
- colorFrom: purple
5
- colorTo: blue
6
- sdk: static
7
- app_port: 7860
8
- pinned: false
9
- ---
10
-
11
- # LoomLens AI™ — API Token Budget Calculator
12
-
13
- **One prompt. Every model. Every cost. Before you run.**
14
-
15
- Find the best model to fit your prompt.™
16
-
17
- Paste any prompt and instantly see what every major AI model charges — before you spend a single token. Built for developers and AI agents who want to make cost-informed decisions.
18
-
19
- ## Tagline
20
-
21
- > *"One prompt. Every model. Every cost. Before you run."*
22
-
23
- ## Features
24
-
25
- - **One prompt. Every model.** — Compare GPT-4o, Claude Sonnet, Gemini Flash, DeepSeek, and more
26
- - **Before you run** — Get cost estimates before any API call is made
27
- - **API-first** — AI agents can call the API directly for automated cost routing
28
 
29
- ## Supported Models
30
-
31
- **Major Models:**
32
- - OpenAI: GPT-5.3 Codex, GPT-4o, GPT-4o Mini
33
- - Anthropic: Claude Opus 4, Claude Sonnet 4
34
- - Google: Gemini 2.5 Pro, Gemini 2.5 Flash
35
- - DeepSeek: Chat v3
36
- - xAI: Grok-3
37
-
38
- ## Pricing
39
-
40
- | Plan | Price | Jobs/month |
41
- |------|-------|-----------|
42
- | Free | $0 | 5/day |
43
- | Pro | $5/mo | 250 |
44
- | Scale | $20/mo | 1,000 |
45
- | Per Job | $0.005/job | — |
46
-
47
- ## Prompt Integrity Commitment
48
-
49
- LoomLens AI™ is built on Signal Loom AI's infrastructure, which operates under a strict **Prompt & Media Integrity** policy:
50
-
51
- - 🔒 **No model training** — Your prompts are never used to train any ML model
52
- - ⚡ **No media logging** — Audio and video inputs are processed ephemerally and never stored
53
- - 🚫 **No third-party data brokering** — Your content is never sold, shared, or licensed to third parties
54
- - 🔑 **Your data, your keys** — You retain full ownership of all prompts and outputs
55
-
56
- See the full [Prompt & Media Integrity Policy](https://signalloomai.com/prompt-integrity.html).
57
 
58
  ---
59
 
60
- ## Powered By
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- A **SignalloomAI™** Product — Media In. Machine Intelligence Out.
63
-
64
- ---
65
- *Estimates based on public API pricing. Actual costs may vary.*
 
1
+ # LoomLens Live — Standalone Package
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ **Location:** `signal-loom-loomlens/`
4
+ **Status:** Phase 1–3 built. Packaging for release TBD.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  ---
7
 
8
+ ## What's Built
9
+
10
+ | File | Phase | Description |
11
+ |------|-------|-------------|
12
+ | `loomlens-models.ts` | 1 | Model registry — 12 models across 5 tiers with live pricing |
13
+ | `loomlens-engine.ts` | 1 | Token estimator + task detection + cost calculator + fit scorer |
14
+ | `loomlens-panel.tsx` | 2 | React pre-flight panel with model cards + tip footer |
15
+ | `loomlens-openclaw-plugin.ts` | 3 | OpenClaw plugin with `before_model_resolve` hook + routes |
16
+
17
+ ## Quick Start (Engine only — no UI)
18
+
19
+ ```ts
20
+ import { estimatePrompt } from './loomlens-engine';
21
+
22
+ const result = estimatePrompt(
23
+ 'Write a function that parses JSON and handles errors gracefully',
24
+ 'minimax/MiniMax-M2'
25
+ );
26
+
27
+ console.log(result.estimates[0].estimatedCost); // $0.0012
28
+ console.log(result.recommended?.modelName); // 'Claude Sonnet 4'
29
+ console.log(result.tip); // 'Using MiniMax M2...'
30
+ ```
31
+
32
+ ## Architecture
33
+
34
+ ```
35
+ ┌─────────────────────────────────────────────┐
36
+ │ LoomLensEngine (engine.ts) │
37
+ │ ┌──────────────┐ ┌────────────────────┐ │
38
+ │ │ TokenEstimator│ │ TaskTypeDetector │ │
39
+ │ │ (char heuristics)│ │ (keyword analysis │ │
40
+ │ └──────────────┘ └────────────────────┘ │
41
+ │ ┌──────────────┐ ┌────────────────────┐ │
42
+ │ │ CostCalculator│ │ FitScorer │ │
43
+ │ │ ($/token × tp │ │ (capability match) │ │
44
+ │ └──────────────┘ └────────────────────┘ │
45
+ └────────────────────┬──────────────────────┘
46
+ │ LoomLensResult
47
+ ┌────────────┼────────────┐
48
+ ▼ ▼ ▼
49
+ LoomLensPanel /loomlens POST /loomlens/override
50
+ (React UI) (cmd) → before_model_resolve hook
51
+ ```
52
+
53
+ ## Integration with Existing LoomLensAI-Live
54
+
55
+ The existing `signal-loom-live/panel.html` is a **post-hoc tracker** (shows cumulative cost after prompts fire).
56
+ LoomLens Live (`signal-loom-loomlens/`) is a **pre-flight estimator** (shows alternatives before you send).
57
+
58
+ They are complementary and can coexist. The OpenClaw plugin bridges them.
59
+
60
+ ## Next Steps
61
+
62
+ 1. **Package** — add `package.json` + build step (tsc → JS bundle)
63
+ 2. **Test** — add unit tests for token estimation accuracy
64
+ 3. **Install plugin** — copy to `~/.openclaw/plugins/loomlens/`
65
+ 4. **Panel injection** — mount `loomlens-panel.tsx` into OpenClaw webchat DOM
66
+ 5. **Live pricing** — wire OpenRouter API for real-time pricing instead of static registry
67
 
 
 
 
 
index.html CHANGED
@@ -147,6 +147,12 @@
147
  .quota-fill.warn { background: linear-gradient(90deg, var(--yellow), var(--orange)); }
148
  .quota-fill.done { background: var(--green); }
149
  .quota-remaining { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
 
 
 
 
 
 
150
  .quota-remaining strong { color: var(--text-dim); }
151
 
152
  /* Prompt area */
@@ -457,6 +463,8 @@
457
  .cost-band { padding: 2px 7px; border-radius: 6px; background: var(--surface2); }
458
  .cost-band.low { color: var(--green); } .cost-band.mid { color: var(--yellow); } .cost-band.high { color: var(--red); }
459
  .token-row { font-size: 11px; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
 
 
460
  .token-row b { color: var(--text-dim); }
461
 
462
  .savings-banner {
@@ -533,6 +541,22 @@
533
  <div class="quota-remaining" id="quota_remaining">You have <strong>5 free estimates today</strong></div>
534
  </div>
535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  <textarea id="prompt_input" class="prompt-area"
537
  placeholder="Paste your prompt here...&#10;&#10;e.g. You are an expert medical coder. Review the following clinical notes and assign the appropriate ICD-10 codes..." spellcheck="false"></textarea>
538
  <div class="token-bar">
@@ -751,6 +775,7 @@
751
 
752
  <script>
753
  const API_URL = 'https://api.signalloomai.com/v1/estimate';
 
754
  const FREE_DAILY = 5;
755
  const STORAGE_KEY = 'sl_token_est_quota';
756
  const CHARS_PER_TOKEN = 3.8;
@@ -922,6 +947,78 @@
922
  }
923
 
924
  // ── Run estimate ────────────────────────────────────
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
925
  async function runEstimate() {
926
  const btn = document.getElementById('btn_estimate');
927
  const err = document.getElementById('error_msg');
@@ -969,7 +1066,28 @@
969
  });
970
  const data = await res.json();
971
  if (!res.ok) throw new Error(data.detail || data.error || 'Request failed');
972
- renderResults(data, baseTokens, numTurns);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  } catch (e) {
974
  err.textContent = 'Error: ' + e.message; err.style.display = 'block';
975
  } finally {
@@ -1014,6 +1132,9 @@
1014
  <span>Out: <b>${fmtNum(m.output_tokens_estimate)}</b></span>
1015
  <span>Total: <b>${fmtNum(m.total_tokens_estimate)}</b></span>
1016
  </div>
 
 
 
1017
  </div>`;
1018
  }
1019
 
@@ -1109,6 +1230,7 @@
1109
  }
1110
 
1111
  // ── Init ────────────────────────────────────────────
 
1112
  renderQuotaUI();
1113
  wireChipListeners();
1114
  ['tier1','tier2','tier3'].forEach(t => updateTierCount(t));
 
147
  .quota-fill.warn { background: linear-gradient(90deg, var(--yellow), var(--orange)); }
148
  .quota-fill.done { background: var(--green); }
149
  .quota-remaining { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
150
+ .api-key-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: rgba(139,92,246,0.08); border: 1px solid rgba(139,92,246,0.2); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
151
+ .credit-row { display: flex; align-items: center; gap: 8px; }
152
+ .credit-label { font-size: 12px; color: var(--text-muted); }
153
+ .credit-balance { font-size: 13px; font-weight: 700; color: var(--accent-bright); }
154
+ .api-key-link { font-size: 11px; color: var(--text-muted); }
155
+ .api-key-link a { color: var(--accent-bright); text-decoration: none; }
156
  .quota-remaining strong { color: var(--text-dim); }
157
 
158
  /* Prompt area */
 
463
  .cost-band { padding: 2px 7px; border-radius: 6px; background: var(--surface2); }
464
  .cost-band.low { color: var(--green); } .cost-band.mid { color: var(--yellow); } .cost-band.high { color: var(--red); }
465
  .token-row { font-size: 11px; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
466
+ .loom-token-row { font-size: 11px; color: var(--accent); margin-top: 4px; }
467
+ .loom-token-row b { color: var(--accent-bright); }
468
  .token-row b { color: var(--text-dim); }
469
 
470
  .savings-banner {
 
541
  <div class="quota-remaining" id="quota_remaining">You have <strong>5 free estimates today</strong></div>
542
  </div>
543
 
544
+ <!-- API key + credit balance -->
545
+ <div class="api-key-bar" id="api_key_bar" style="display:none">
546
+ <div class="credit-row">
547
+ <span class="credit-label">💎 LoomTokens</span>
548
+ <span class="credit-balance" id="credit_balance">—</span>
549
+ </div>
550
+ <div class="api-key-link" id="api_key_link">
551
+ <a href="https://signalloomai.com/loomlensai-build.html" target="_blank">Connect API key</a> for pay-per-call estimates
552
+ </div>
553
+ <div class="api-key-input-row" id="api_key_input_row" style="display:none">
554
+ <input type="password" id="api_key_input" placeholder="Paste your API key (slo_...)" style="flex:1;background:var(--bg-2);border:1px solid var(--border);border-radius:6px;padding:4px 8px;color:var(--text);font-size:12px;" />
555
+ <button onclick="saveApiKey()" style="background:var(--accent);border:none;border-radius:6px;padding:4px 10px;color:white;font-size:12px;cursor:pointer;">Save</button>
556
+ <button onclick="clearApiKey()" style="background:transparent;border:1px solid var(--border);border-radius:6px;padding:4px 8px;color:var(--text-muted);font-size:11px;cursor:pointer;">Clear</button>
557
+ </div>
558
+ </div>
559
+
560
  <textarea id="prompt_input" class="prompt-area"
561
  placeholder="Paste your prompt here...&#10;&#10;e.g. You are an expert medical coder. Review the following clinical notes and assign the appropriate ICD-10 codes..." spellcheck="false"></textarea>
562
  <div class="token-bar">
 
775
 
776
  <script>
777
  const API_URL = 'https://api.signalloomai.com/v1/estimate';
778
+ const API_KEY_STORAGE = 'sl_api_key';
779
  const FREE_DAILY = 5;
780
  const STORAGE_KEY = 'sl_token_est_quota';
781
  const CHARS_PER_TOKEN = 3.8;
 
947
  }
948
 
949
  // ── Run estimate ────────────────────────────────────
950
+ // ── Credit bar ────────────────────────────────────────────
951
+ function initCreditBar() {
952
+ const bar = document.getElementById('api_key_bar');
953
+ const link = document.getElementById('api_key_link');
954
+ const inputRow = document.getElementById('api_key_input_row');
955
+ const apiKey = localStorage.getItem(API_KEY_STORAGE);
956
+ if (apiKey) {
957
+ bar.style.display = 'flex';
958
+ link.innerHTML = '<span style="font-size:11px;color:var(--green);">● API key connected</span> · <a href="#" onclick="toggleApiKeyInput();return false;" style="color:var(--text-muted);">[change]</a>';
959
+ inputRow.style.display = 'none';
960
+ updateCreditDisplay(apiKey);
961
+ } else {
962
+ bar.style.display = 'flex';
963
+ link.innerHTML = '<a href="#" onclick="toggleApiKeyInput();return false;" style="color:var(--accent-bright);">+ Connect API key</a> for pay-per-call estimates';
964
+ inputRow.style.display = 'none';
965
+ }
966
+ }
967
+
968
+ function toggleApiKeyInput() {
969
+ const row = document.getElementById('api_key_input_row');
970
+ row.style.display = row.style.display === 'none' ? 'flex' : 'none';
971
+ if (row.style.display === 'flex') {
972
+ document.getElementById('api_key_input').focus();
973
+ }
974
+ }
975
+
976
+ function saveApiKey() {
977
+ const key = document.getElementById('api_key_input').value.trim();
978
+ if (key) {
979
+ localStorage.setItem(API_KEY_STORAGE, key);
980
+ initCreditBar();
981
+ }
982
+ }
983
+
984
+ function clearApiKey() {
985
+ localStorage.removeItem(API_KEY_STORAGE);
986
+ document.getElementById('api_key_input').value = '';
987
+ initCreditBar();
988
+ }
989
+
990
+ let _lastBalanceBefore = 0;
991
+ async function updateCreditDisplay(apiKey) {
992
+ const el = document.getElementById('credit_balance');
993
+ if (!apiKey) { el.textContent = '—'; _lastBalanceBefore = 0; return; }
994
+ try {
995
+ const res = await fetch('https://api.signalloomai.com/v1/loomcredits/balance', {
996
+ headers: { 'Authorization': 'Bearer ' + apiKey }
997
+ });
998
+ if (res.ok) {
999
+ const data = await res.json();
1000
+ const bal = data.balance || 0;
1001
+ _lastBalanceBefore = bal;
1002
+ el.textContent = bal.toLocaleString() + ' LoomTokens';
1003
+ } else {
1004
+ el.textContent = '—';
1005
+ _lastBalanceBefore = 0;
1006
+ }
1007
+ } catch {
1008
+ el.textContent = '—';
1009
+ _lastBalanceBefore = 0;
1010
+ }
1011
+ }
1012
+
1013
+ function loomBalanceDelta() {
1014
+ return _lastBalanceBefore;
1015
+ }
1016
+
1017
+ function setApiKey(key) {
1018
+ localStorage.setItem(API_KEY_STORAGE, key);
1019
+ initCreditBar();
1020
+ }
1021
+
1022
  async function runEstimate() {
1023
  const btn = document.getElementById('btn_estimate');
1024
  const err = document.getElementById('error_msg');
 
1066
  });
1067
  const data = await res.json();
1068
  if (!res.ok) throw new Error(data.detail || data.error || 'Request failed');
1069
+ // Fetch fresh balance BEFORE the call for delta calculation
1070
+ const apiKey = localStorage.getItem(API_KEY_STORAGE);
1071
+ if (apiKey) {
1072
+ await updateCreditDisplay(apiKey); // sets _lastBalanceBefore
1073
+ const balanceBefore = _lastBalanceBefore;
1074
+ renderResults(data, baseTokens, numTurns);
1075
+ // Update balance AFTER call, then show delta
1076
+ await updateCreditDisplay(apiKey); // sets _lastBalanceAfter
1077
+ const balanceAfter = _lastBalanceBefore; // now holds post-call balance
1078
+ const delta = balanceAfter - balanceBefore;
1079
+ document.querySelectorAll('.credit-change').forEach(el => {
1080
+ if (delta < 0) {
1081
+ el.textContent = (delta).toLocaleString() + ' after';
1082
+ el.style.color = '#ef4444';
1083
+ } else {
1084
+ el.textContent = balanceAfter.toLocaleString() + ' balance';
1085
+ el.style.color = 'var(--green)';
1086
+ }
1087
+ });
1088
+ } else {
1089
+ renderResults(data, baseTokens, numTurns);
1090
+ }
1091
  } catch (e) {
1092
  err.textContent = 'Error: ' + e.message; err.style.display = 'block';
1093
  } finally {
 
1132
  <span>Out: <b>${fmtNum(m.output_tokens_estimate)}</b></span>
1133
  <span>Total: <b>${fmtNum(m.total_tokens_estimate)}</b></span>
1134
  </div>
1135
+ <div class="loom-token-row">
1136
+ <span>💎 <b>100</b> LoomTokens · $${(data.billing && data.billing.call_cost_usd ? data.billing.call_cost_usd : 0.10).toFixed(2)} · <span class="credit-change" id="credit_change_${m.model.replace('/', '_')}">—</span></span>
1137
+ </div>
1138
  </div>`;
1139
  }
1140
 
 
1230
  }
1231
 
1232
  // ── Init ────────────────────────────────────────────
1233
+ initCreditBar();
1234
  renderQuotaUI();
1235
  wireChipListeners();
1236
  ['tier1','tier2','tier3'].forEach(t => updateTierCount(t));
token-estimator.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>LoomLensAIAI™ — API Token Budget Calculator · SignalloomAI™</title>
7
  <style>
8
  :root {
9
  --bg: #0a0e1a;
@@ -425,14 +425,14 @@
425
 
426
  <div class="header">
427
  <div class="eyebrow">By SignalloomAI™ — Free Tool</div>
428
- <h1>LoomLensAIAI™ — API Token Budget Calculator</h1>
429
  <p>Find the best model to fit your prompt.™</p>
430
  <div class="pricing-bar">
431
  <span class="badge-free">FREE</span>
432
  <span class="pricing-item">5 estimates / day</span>
433
  <span class="pricing-divider"></span>
434
  <span class="badge-pro">PRO</span>
435
- <span class="pricing-item"><strong>$5/month</strong> — unlimited estimates</span>
436
  </div>
437
  </div>
438
 
@@ -572,7 +572,7 @@
572
  <!-- Pro upsell (shown when quota exhausted) -->
573
  <div class="pro-bar" id="pro_bar" style="display:none">
574
  <div class="pro-bar-icon">💎</div>
575
- <div>Out of free estimates today. <strong>Get unlimited for $5/month</strong> — <a href="/loomlensai-pro.html" target="_blank">Upgrade Now</a></div>
576
  </div>
577
 
578
  <button class="btn-estimate" id="btn_estimate" onclick="runEstimate()">Estimate Cost</button>
@@ -704,7 +704,7 @@
704
  err.style.display = 'none';
705
 
706
  if (!useQuota()) {
707
- err.textContent = 'Daily limit reached. Upgrade to Pro for unlimited estimates.';
708
  err.style.display = 'block';
709
  renderQuotaUI();
710
  return;
@@ -833,6 +833,20 @@
833
 
834
  // ── Init ────────────────────────────────────────────
835
  renderQuotaUI();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
836
  </script>
837
  </body>
838
  </html>
 
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>LoomLens AI™ — API Token Budget Calculator · SignalloomAI™</title>
7
  <style>
8
  :root {
9
  --bg: #0a0e1a;
 
425
 
426
  <div class="header">
427
  <div class="eyebrow">By SignalloomAI™ — Free Tool</div>
428
+ <h1>LoomLens AI™ — API Token Budget Calculator</h1>
429
  <p>Find the best model to fit your prompt.™</p>
430
  <div class="pricing-bar">
431
  <span class="badge-free">FREE</span>
432
  <span class="pricing-item">5 estimates / day</span>
433
  <span class="pricing-divider"></span>
434
  <span class="badge-pro">PRO</span>
435
+ <span class="pricing-item"><strong>$50/month</strong> — 1,000 estimates/mo <span id="avg_savings_badge" style="color:var(--green);font-size:11px">(avg save: $1.23/est)</span></span>
436
  </div>
437
  </div>
438
 
 
572
  <!-- Pro upsell (shown when quota exhausted) -->
573
  <div class="pro-bar" id="pro_bar" style="display:none">
574
  <div class="pro-bar-icon">💎</div>
575
+ <div>Out of free estimates today. <strong>1,000 estimates/mo for $50</strong> — <a href="/loomlens/pricing" target="_blank">Upgrade Now</a></div>
576
  </div>
577
 
578
  <button class="btn-estimate" id="btn_estimate" onclick="runEstimate()">Estimate Cost</button>
 
704
  err.style.display = 'none';
705
 
706
  if (!useQuota()) {
707
+ err.textContent = 'Daily limit reached. Upgrade to Pro — 1,000 estimates/mo for $50.';
708
  err.style.display = 'block';
709
  renderQuotaUI();
710
  return;
 
833
 
834
  // ── Init ────────────────────────────────────────────
835
  renderQuotaUI();
836
+
837
+ // ── Live avg savings badge ───────────────────────────
838
+ (async () => {
839
+ try {
840
+ const r = await fetch('https://api.signalloomai.com/v1/analytics/loomlens/public');
841
+ if (!r.ok) return;
842
+ const d = await r.json();
843
+ const avg = d.total_estimate_jobs > 0
844
+ ? (d.total_savings_usd / d.total_estimate_jobs).toFixed(2)
845
+ : '1.23';
846
+ const el = document.getElementById('avg_savings_badge');
847
+ if (el) el.textContent = `(avg save: $${avg}/est)`;
848
+ } catch(e) { /* silent — badge shows default */ }
849
+ })();
850
  </script>
851
  </body>
852
  </html>