@tokagent/tokagentos 2.0.12 → 2.0.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokagent/tokagentos",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "tokagentOS CLI - Create and upgrade tokagentOS project templates",
5
5
  "type": "module",
6
6
  "bin": {
@@ -113,43 +113,6 @@ function BillingPageView(): React.ReactElement {
113
113
  background: "#0a0a0f",
114
114
  }}
115
115
  >
116
- {/* BETA ticker — rendered in the parent React tree (not the iframe)
117
- so dashboard rebuilds don't overwrite it. Slim strip, non-sticky,
118
- uses the parent's locked lime accent. */}
119
- <div
120
- style={{
121
- display: "flex",
122
- alignItems: "center",
123
- gap: "0.5rem",
124
- padding: "8px 16px",
125
- background: "rgba(196, 245, 71, 0.08)",
126
- borderBottom: "1px solid rgba(196, 245, 71, 0.25)",
127
- color: "#c4f547",
128
- fontSize: "0.75rem",
129
- fontWeight: 600,
130
- letterSpacing: "0.06em",
131
- textTransform: "uppercase",
132
- flexShrink: 0,
133
- }}
134
- >
135
- <span
136
- style={{
137
- display: "inline-block",
138
- padding: "2px 8px",
139
- borderRadius: "999px",
140
- background: "#c4f547",
141
- color: "#0a0a0f",
142
- fontSize: "0.65rem",
143
- fontWeight: 700,
144
- letterSpacing: "0.08em",
145
- }}
146
- >
147
- BETA
148
- </span>
149
- <span style={{ color: "#9ca3af", fontWeight: 500, textTransform: "none", letterSpacing: 0 }}>
150
- The x402 rail is in active development — expect rapid iteration.
151
- </span>
152
- </div>
153
116
  {loading ? (
154
117
  <div
155
118
  style={{
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokagent/plugin-tokagent-billing",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "elizaOS plugin: Web3 credit-billing routes and middleware for the tokagentos LLM gateway.",
5
5
  "type": "module",
6
6
  "publishConfig": { "access": "public" },
@@ -716,10 +716,15 @@ function renderTopBar() {
716
716
 
717
717
  function renderKpis() {
718
718
  const c = state.credits;
719
- const balance = c?.ledger?.balance ?? c?.onChainCredits;
719
+ // Server returns BOTH nested (c.ledger.balance) and flat (c.balance).
720
+ // Prefer nested for clients that expect the structured shape, fall back
721
+ // to flat for forward/backward compat with the simpler API surface.
722
+ const balance = c?.ledger?.balance ?? c?.balance ?? c?.onChainCredits;
723
+ const reserved = c?.ledger?.reserved ?? c?.reserved ?? 0n;
724
+ const accrued = c?.ledger?.accrued ?? c?.accrued ?? 0n;
720
725
  $("#kpi-balance").textContent = fmtPton(balance);
721
- $("#kpi-reserved").textContent = fmtPton(c?.ledger?.reserved ?? 0n) + " PTON";
722
- $("#kpi-accrued").textContent = fmtPton(c?.ledger?.accrued ?? 0n) + " PTON";
726
+ $("#kpi-reserved").textContent = fmtPton(reserved) + " PTON";
727
+ $("#kpi-accrued").textContent = fmtPton(accrued) + " PTON";
723
728
  $("#kpi-balance-usd").textContent = fmtUsdFromAttoPton(balance, state.tonUsd);
724
729
  // Wallet holdings (outside the vault). ETH and PTON share 18 decimals so
725
730
  // fmtPton works for both — only the unit label differs.
@@ -83,11 +83,19 @@ async function handleGetCreditsMe(
83
83
 
84
84
  const row = rows[0];
85
85
 
86
+ // Response shape: both flat (legacy clients) and nested under `ledger`
87
+ // (the dashboard SPA which reads `c.ledger.balance`). Keeping both keys
88
+ // is cheap and avoids a contract break for any external caller already
89
+ // depending on the flat shape.
90
+ const balance = row ? row.balance.toString() : "0";
91
+ const reserved = row ? row.reserved.toString() : "0";
92
+ const accrued = row ? row.accrued.toString() : "0";
86
93
  res.status(200).json({
87
94
  wallet,
88
- balance: row ? row.balance.toString() : "0",
89
- reserved: row ? row.reserved.toString() : "0",
90
- accrued: row ? row.accrued.toString() : "0",
95
+ balance,
96
+ reserved,
97
+ accrued,
98
+ ledger: { balance, reserved, accrued },
91
99
  });
92
100
  }
93
101
 
@@ -263,7 +263,7 @@ async function handleCountTokens(
263
263
  * or `{ "available": false }` when no price is cached.
264
264
  */
265
265
  async function handlePrice(
266
- req: RouteRequest,
266
+ _req: RouteRequest,
267
267
  res: RouteResponse,
268
268
  _runtime: IAgentRuntime,
269
269
  ): Promise<void> {
@@ -271,11 +271,9 @@ async function handlePrice(
271
271
  const { config, twapCache } = getBillingState();
272
272
  if (!config.enabled) return billingUnavailable(res);
273
273
 
274
- const identity = await resolveBillingIdentity(toIncomingMessage(req));
275
- if (!identity) {
276
- res.status(401).json({ error: "Authentication required." });
277
- return;
278
- }
274
+ // TON/USD is a public oracle read — no identity required. The dashboard
275
+ // KPI shows this rate before the user has signed in, so gating it on
276
+ // SIWE auth would leave the price displayed as "—" until login completes.
279
277
 
280
278
  // 1. Priority override — operator-pinned price freeze.
281
279
  // `BILLING_FIXED_TON_USD` is env-only (not exposed in the setup wizard),
@@ -194,26 +194,53 @@ async function handleTopupQuote(
194
194
  return;
195
195
  }
196
196
 
197
- // Parse optional amountUsd from body; fall back to the configured default.
197
+ // Parse optional amountPton OR amountUsd from body; fall back to default.
198
+ // Prefer amountPton when both are present — it's the exact value the user
199
+ // signs in the EIP-3009 authorization, and settlement strictly equality-
200
+ // checks signature.value === quote.amountPton. Routing the user's intent
201
+ // through a USD round-trip would round and mismatch the signature.
198
202
  const body = req.body as Record<string, unknown> | undefined;
203
+ let amountPton: bigint;
199
204
  let amountUsd: number;
200
- if (body?.["amountUsd"] !== undefined) {
205
+ if (body?.["amountPton"] !== undefined) {
206
+ const raw = body["amountPton"];
207
+ let parsed: bigint;
208
+ try {
209
+ // Accept either a decimal string (atto-units) or a JS number for
210
+ // backward compat with older clients.
211
+ if (typeof raw === "string") parsed = BigInt(raw);
212
+ else if (typeof raw === "number" && Number.isFinite(raw) && raw > 0)
213
+ parsed = BigInt(Math.floor(raw));
214
+ else throw new Error("amountPton must be a positive decimal string or number (atto-units)");
215
+ } catch (e) {
216
+ res.status(400).json({
217
+ error: e instanceof Error ? e.message : "Invalid amountPton",
218
+ });
219
+ return;
220
+ }
221
+ if (parsed <= 0n) {
222
+ res.status(400).json({ error: "amountPton must be > 0" });
223
+ return;
224
+ }
225
+ amountPton = parsed;
226
+ // Derive USD for the response envelope. Settlement only checks PTON.
227
+ amountUsd = (Number(amountPton) / 1e18) * tonUsd;
228
+ } else if (body?.["amountUsd"] !== undefined) {
201
229
  const raw = body["amountUsd"];
202
230
  if (typeof raw !== "number" || !Number.isFinite(raw) || raw <= 0) {
203
231
  res.status(400).json({ error: "amountUsd must be a positive finite number." });
204
232
  return;
205
233
  }
206
234
  amountUsd = raw;
235
+ amountPton = usdToPton(amountUsd, tonUsd);
207
236
  } else {
208
- // Convert default PTON amount → USD.
209
- const defaultPton = config.topupAmountPton;
210
- // amountUsd = ptonAmount * tonUsd / 1e18
211
- amountUsd = Number(defaultPton) * tonUsd / 1e18;
237
+ // Neither provided — use configured default PTON amount.
238
+ amountPton = config.topupAmountPton;
239
+ amountUsd = Number(amountPton) * tonUsd / 1e18;
212
240
  }
213
241
 
214
- const amountPton = usdToPton(amountUsd, tonUsd);
215
242
  if (amountPton <= 0n) {
216
- res.status(400).json({ error: "Computed PTON amount is zero — check amountUsd." });
243
+ res.status(400).json({ error: "Computed PTON amount is zero — check amount." });
217
244
  return;
218
245
  }
219
246
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "generatedAt": "2026-05-19T14:06:57.055Z",
3
+ "generatedAt": "2026-05-19T14:54:21.961Z",
4
4
  "repoUrl": "https://github.com/elizaos/eliza",
5
5
  "templates": [
6
6
  {