@tangle-network/sandbox-ui 0.15.1 → 0.15.3

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.
@@ -0,0 +1,861 @@
1
+ import {
2
+ cn
3
+ } from "./chunk-EI44GEQ5.js";
4
+
5
+ // src/dashboard/model-picker.tsx
6
+ import * as React from "react";
7
+ import { ChevronDown, Search, Sparkles, Zap, Brain, Star, Loader2 } from "lucide-react";
8
+ import * as Popover from "@radix-ui/react-dropdown-menu";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ function canonicalModelId(model) {
11
+ const id = model.id;
12
+ if (id.includes("/")) return id;
13
+ const provider = model._provider ?? model.provider;
14
+ return provider ? `${provider}/${id}` : id;
15
+ }
16
+ function formatPricing(pricing) {
17
+ const prompt = Number(pricing?.prompt ?? 0);
18
+ const completion = Number(pricing?.completion ?? 0);
19
+ if (!prompt && !completion) return null;
20
+ const fmt = (n) => {
21
+ const perM = n * 1e6;
22
+ if (perM === 0) return "0";
23
+ if (perM >= 1) return `$${perM.toFixed(2)}`;
24
+ return `$${perM.toFixed(2)}`;
25
+ };
26
+ return `${fmt(prompt)} / ${fmt(completion)} per 1M`;
27
+ }
28
+ function formatContext(ctx) {
29
+ if (!ctx) return null;
30
+ if (ctx >= 1e6) return `${(ctx / 1e6).toFixed(1)}M ctx`;
31
+ if (ctx >= 1e3) return `${Math.round(ctx / 1e3)}k ctx`;
32
+ return `${ctx} ctx`;
33
+ }
34
+ var DEFAULT_PRESETS = [
35
+ {
36
+ id: "fast",
37
+ label: "Fast",
38
+ hint: "Cheapest, lowest latency",
39
+ icon: Zap,
40
+ match: (models) => {
41
+ const ids = models.map(canonicalModelId);
42
+ return ids.find((m) => /gpt-5\.\d+-mini$/.test(m)) ?? ids.find((m) => /gpt-5-mini$/.test(m)) ?? ids.find((m) => m.endsWith("/claude-haiku-4.5")) ?? ids.find((m) => /haiku/.test(m));
43
+ }
44
+ },
45
+ {
46
+ id: "balanced",
47
+ label: "Balanced",
48
+ hint: "Best value for most chat",
49
+ icon: Sparkles,
50
+ match: (models) => {
51
+ const ids = models.map(canonicalModelId);
52
+ return ids.find((m) => /^openai\/gpt-5\.\d+$/.test(m)) ?? ids.find((m) => /^openai\/gpt-5$/.test(m)) ?? ids.find((m) => m.endsWith("/claude-sonnet-4-6")) ?? ids.find((m) => /sonnet/.test(m));
53
+ }
54
+ },
55
+ {
56
+ id: "best",
57
+ label: "Best",
58
+ hint: "Hardest reasoning, highest quality",
59
+ icon: Brain,
60
+ match: (models) => {
61
+ const ids = models.map(canonicalModelId);
62
+ return ids.find((m) => /^openai\/gpt-5\.\d+-pro$/.test(m)) ?? ids.find((m) => /^openai\/o3$/.test(m)) ?? ids.find((m) => m.endsWith("/claude-opus-4-7")) ?? ids.find((m) => /opus/.test(m));
63
+ }
64
+ }
65
+ ];
66
+ function ModelPicker({
67
+ value,
68
+ onChange,
69
+ models,
70
+ loading = false,
71
+ recents,
72
+ presets = DEFAULT_PRESETS,
73
+ excludeProviders,
74
+ modalities,
75
+ variant = "field",
76
+ label = "Model",
77
+ placeholder = "Choose a model",
78
+ className,
79
+ triggerClassName,
80
+ disabled
81
+ }) {
82
+ const [query, setQuery] = React.useState("");
83
+ const [open, setOpen] = React.useState(false);
84
+ const filtered = React.useMemo(() => {
85
+ const excluded = new Set((excludeProviders ?? []).map((p) => p.toLowerCase()));
86
+ const allowedModalities = modalities ? new Set(modalities) : null;
87
+ const q = query.trim().toLowerCase();
88
+ return models.filter((m) => {
89
+ const provider = (m._provider ?? m.provider ?? "").toLowerCase();
90
+ if (excluded.has(provider)) return false;
91
+ if (allowedModalities && m.architecture?.modality && !allowedModalities.has(m.architecture.modality)) return false;
92
+ if (!q) return true;
93
+ const id = canonicalModelId(m).toLowerCase();
94
+ const name = (m.name ?? "").toLowerCase();
95
+ return id.includes(q) || name.includes(q) || provider.includes(q);
96
+ });
97
+ }, [models, query, modalities, excludeProviders]);
98
+ const grouped = React.useMemo(() => {
99
+ const groups = /* @__PURE__ */ new Map();
100
+ for (const m of filtered) {
101
+ const provider = m._provider ?? m.provider ?? "other";
102
+ const list = groups.get(provider);
103
+ if (list) list.push(m);
104
+ else groups.set(provider, [m]);
105
+ }
106
+ return Array.from(groups.entries()).sort(([a], [b]) => a.localeCompare(b));
107
+ }, [filtered]);
108
+ const current = React.useMemo(
109
+ () => models.find((m) => canonicalModelId(m) === value),
110
+ [models, value]
111
+ );
112
+ const currentLabel = current?.name ?? current?.id ?? value;
113
+ const recentIds = React.useMemo(() => {
114
+ if (!recents?.length) return [];
115
+ const lookup = new Map(models.map((m) => [canonicalModelId(m), m]));
116
+ return recents.map((id) => lookup.get(id)).filter((m) => Boolean(m)).slice(0, 4);
117
+ }, [recents, models]);
118
+ const handleSelect = (id) => {
119
+ onChange(id);
120
+ setOpen(false);
121
+ setQuery("");
122
+ };
123
+ const trigger = variant === "pill" ? /* @__PURE__ */ jsxs(
124
+ "button",
125
+ {
126
+ type: "button",
127
+ disabled,
128
+ className: cn(
129
+ "inline-flex items-center gap-1.5 rounded-full border border-border bg-card",
130
+ "px-2.5 py-1 text-xs font-medium text-foreground",
131
+ "transition-colors duration-[var(--transition-fast)]",
132
+ "hover:border-primary/30 hover:bg-accent/30",
133
+ "focus:outline-none focus:border-primary/40",
134
+ "data-[state=open]:border-primary/40 data-[state=open]:bg-accent/30",
135
+ "disabled:opacity-50 disabled:cursor-not-allowed",
136
+ className,
137
+ triggerClassName
138
+ ),
139
+ children: [
140
+ /* @__PURE__ */ jsx(Sparkles, { className: "h-3 w-3 text-muted-foreground" }),
141
+ /* @__PURE__ */ jsx("span", { className: "truncate max-w-[160px]", children: currentLabel || placeholder }),
142
+ /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 text-muted-foreground transition-transform data-[state=open]:rotate-180" })
143
+ ]
144
+ }
145
+ ) : /* @__PURE__ */ jsxs(
146
+ "button",
147
+ {
148
+ type: "button",
149
+ disabled,
150
+ className: cn(
151
+ "flex w-full items-center justify-between gap-2 rounded-[var(--radius-md)]",
152
+ "border border-border bg-card px-3 py-2.5 text-sm text-left",
153
+ "transition-colors duration-[var(--transition-fast)]",
154
+ "hover:border-primary/20 hover:bg-accent/30",
155
+ "focus:outline-none focus:border-primary/30",
156
+ "data-[state=open]:border-primary/30 data-[state=open]:bg-accent/30",
157
+ "disabled:opacity-50 disabled:cursor-not-allowed",
158
+ className,
159
+ triggerClassName
160
+ ),
161
+ children: [
162
+ /* @__PURE__ */ jsx("span", { className: cn("truncate", current ? "text-foreground font-medium" : "text-muted-foreground"), children: currentLabel || placeholder }),
163
+ /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4 shrink-0 text-muted-foreground transition-transform data-[state=open]:rotate-180" })
164
+ ]
165
+ }
166
+ );
167
+ return /* @__PURE__ */ jsxs("div", { className: cn(variant === "field" ? "space-y-1.5" : "inline-flex", variant === "field" ? className : void 0), children: [
168
+ variant === "field" && label && /* @__PURE__ */ jsx("label", { className: "block text-xs font-medium text-muted-foreground uppercase tracking-[0.06em]", children: label }),
169
+ /* @__PURE__ */ jsxs(Popover.Root, { open, onOpenChange: setOpen, children: [
170
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: trigger }),
171
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
172
+ Popover.Content,
173
+ {
174
+ sideOffset: 4,
175
+ align: variant === "pill" ? "start" : "start",
176
+ className: cn(
177
+ "z-50 w-[var(--radix-dropdown-menu-trigger-width)] min-w-[320px] max-w-[460px]",
178
+ "max-h-[440px] overflow-hidden flex flex-col",
179
+ "rounded-[var(--radius-md)] border border-border bg-card shadow-[var(--shadow-dropdown)]",
180
+ "data-[state=open]:animate-in data-[state=closed]:animate-out",
181
+ "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
182
+ "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95"
183
+ ),
184
+ children: [
185
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3 py-2", children: [
186
+ /* @__PURE__ */ jsx(Search, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
187
+ /* @__PURE__ */ jsx(
188
+ "input",
189
+ {
190
+ type: "text",
191
+ value: query,
192
+ onChange: (e) => setQuery(e.target.value),
193
+ onKeyDown: (e) => {
194
+ if (e.key.length === 1) e.stopPropagation();
195
+ },
196
+ placeholder: "Search models...",
197
+ autoFocus: true,
198
+ className: "flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
199
+ }
200
+ ),
201
+ loading && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" })
202
+ ] }),
203
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-y-auto", children: [
204
+ !query && presets.length > 0 && /* @__PURE__ */ jsx(Section, { label: "Presets", children: presets.map((preset) => {
205
+ const Icon = preset.icon ?? Star;
206
+ const matchedId = preset.match(models);
207
+ if (!matchedId) return null;
208
+ const matched = models.find((m) => canonicalModelId(m) === matchedId);
209
+ const isCurrent = matchedId === value;
210
+ return /* @__PURE__ */ jsxs(
211
+ PickerItem,
212
+ {
213
+ onSelect: () => handleSelect(matchedId),
214
+ active: isCurrent,
215
+ children: [
216
+ /* @__PURE__ */ jsx(Icon, { className: "h-3.5 w-3.5 shrink-0 text-[var(--accent-text)]" }),
217
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
218
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
219
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: preset.label }),
220
+ /* @__PURE__ */ jsxs("span", { className: "text-[10px] text-muted-foreground truncate", children: [
221
+ "\u2192 ",
222
+ matched?.name ?? matchedId
223
+ ] })
224
+ ] }),
225
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: preset.hint })
226
+ ] })
227
+ ]
228
+ },
229
+ preset.id
230
+ );
231
+ }) }),
232
+ !query && recentIds.length > 0 && /* @__PURE__ */ jsx(Section, { label: "Recent", children: recentIds.map((m) => /* @__PURE__ */ jsx(
233
+ ModelRow,
234
+ {
235
+ model: m,
236
+ active: canonicalModelId(m) === value,
237
+ onSelect: handleSelect
238
+ },
239
+ `recent-${canonicalModelId(m)}`
240
+ )) }),
241
+ grouped.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-3 py-8 text-center text-xs text-muted-foreground", children: loading ? "Loading models..." : query ? "No models match." : "No models available." }) : grouped.map(([provider, list]) => /* @__PURE__ */ jsx(Section, { label: provider, children: list.map((m) => /* @__PURE__ */ jsx(
242
+ ModelRow,
243
+ {
244
+ model: m,
245
+ active: canonicalModelId(m) === value,
246
+ onSelect: handleSelect
247
+ },
248
+ canonicalModelId(m)
249
+ )) }, provider))
250
+ ] }),
251
+ /* @__PURE__ */ jsxs("div", { className: "border-t border-border px-3 py-1.5 text-[10px] text-muted-foreground", children: [
252
+ filtered.length,
253
+ " of ",
254
+ models.length,
255
+ " model",
256
+ models.length === 1 ? "" : "s"
257
+ ] })
258
+ ]
259
+ }
260
+ ) })
261
+ ] })
262
+ ] });
263
+ }
264
+ function Section({ label, children }) {
265
+ return /* @__PURE__ */ jsxs("div", { className: "py-1", children: [
266
+ /* @__PURE__ */ jsx("div", { className: "px-3 pt-1.5 pb-0.5 text-[10px] font-mono uppercase tracking-widest text-muted-foreground", children: label }),
267
+ /* @__PURE__ */ jsx("div", { children })
268
+ ] });
269
+ }
270
+ function PickerItem({
271
+ onSelect,
272
+ active,
273
+ children
274
+ }) {
275
+ return /* @__PURE__ */ jsx(
276
+ Popover.Item,
277
+ {
278
+ onSelect: (e) => {
279
+ e.preventDefault();
280
+ onSelect();
281
+ },
282
+ className: cn(
283
+ "flex cursor-pointer items-start gap-2 px-3 py-2 outline-none",
284
+ "transition-colors duration-[var(--transition-fast)]",
285
+ "hover:bg-accent/40 focus:bg-accent/40",
286
+ active && "bg-[var(--accent-surface-soft)] text-[var(--accent-text)]"
287
+ ),
288
+ children
289
+ }
290
+ );
291
+ }
292
+ function ModelRow({
293
+ model,
294
+ active,
295
+ onSelect
296
+ }) {
297
+ const id = canonicalModelId(model);
298
+ const pricing = formatPricing(model.pricing);
299
+ const ctx = formatContext(model.context_length);
300
+ return /* @__PURE__ */ jsx(PickerItem, { onSelect: () => onSelect(id), active, children: /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
301
+ /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
302
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium truncate", children: model.name ?? model.id }),
303
+ ctx && /* @__PURE__ */ jsx("span", { className: "shrink-0 text-[10px] text-muted-foreground", children: ctx })
304
+ ] }),
305
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-[11px] text-muted-foreground", children: [
306
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: id }),
307
+ pricing && /* @__PURE__ */ jsxs(Fragment, { children: [
308
+ /* @__PURE__ */ jsx("span", { className: "shrink-0", children: "\xB7" }),
309
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 font-mono", children: pricing })
310
+ ] })
311
+ ] })
312
+ ] }) });
313
+ }
314
+
315
+ // src/dashboard/billing-dashboard.tsx
316
+ import { Button } from "@tangle-network/ui/primitives";
317
+ import { Badge } from "@tangle-network/ui/primitives";
318
+ import {
319
+ Card,
320
+ CardContent,
321
+ CardDescription,
322
+ CardHeader,
323
+ CardTitle
324
+ } from "@tangle-network/ui/primitives";
325
+ import { Progress } from "@tangle-network/ui/primitives";
326
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
327
+ var variantColors = {
328
+ sandbox: {
329
+ accent: "text-[var(--accent-text)]",
330
+ accentBg: "bg-[var(--accent-surface-soft)]",
331
+ border: "border-[var(--border-accent)]",
332
+ progress: "bg-[image:var(--accent-gradient-strong)]"
333
+ }
334
+ };
335
+ function formatCredits(value) {
336
+ if (value >= 1e6) {
337
+ return `${(value / 1e6).toFixed(1)}M`;
338
+ }
339
+ if (value >= 1e3) {
340
+ return `${(value / 1e3).toFixed(1)}K`;
341
+ }
342
+ return value.toLocaleString();
343
+ }
344
+ function formatDate(dateStr) {
345
+ const date = new Date(dateStr);
346
+ return date.toLocaleDateString("en-US", {
347
+ month: "long",
348
+ day: "numeric",
349
+ year: "numeric"
350
+ });
351
+ }
352
+ function getStatusBadgeVariant(status) {
353
+ switch (status.toLowerCase()) {
354
+ case "active":
355
+ return "success";
356
+ case "trialing":
357
+ case "past_due":
358
+ return "warning";
359
+ case "canceled":
360
+ case "unpaid":
361
+ return "error";
362
+ default:
363
+ return "secondary";
364
+ }
365
+ }
366
+ function CreditCardIcon({ className }) {
367
+ return /* @__PURE__ */ jsxs2(
368
+ "svg",
369
+ {
370
+ xmlns: "http://www.w3.org/2000/svg",
371
+ viewBox: "0 0 24 24",
372
+ fill: "none",
373
+ stroke: "currentColor",
374
+ strokeWidth: "2",
375
+ strokeLinecap: "round",
376
+ strokeLinejoin: "round",
377
+ className: cn("h-5 w-5", className),
378
+ children: [
379
+ /* @__PURE__ */ jsx2("title", { children: "Credit card icon" }),
380
+ /* @__PURE__ */ jsx2("rect", { width: "20", height: "14", x: "2", y: "5", rx: "2" }),
381
+ /* @__PURE__ */ jsx2("line", { x1: "2", x2: "22", y1: "10", y2: "10" })
382
+ ]
383
+ }
384
+ );
385
+ }
386
+ function CoinsIcon({ className }) {
387
+ return /* @__PURE__ */ jsxs2(
388
+ "svg",
389
+ {
390
+ xmlns: "http://www.w3.org/2000/svg",
391
+ viewBox: "0 0 24 24",
392
+ fill: "none",
393
+ stroke: "currentColor",
394
+ strokeWidth: "2",
395
+ strokeLinecap: "round",
396
+ strokeLinejoin: "round",
397
+ className: cn("h-5 w-5", className),
398
+ children: [
399
+ /* @__PURE__ */ jsx2("title", { children: "Coins icon" }),
400
+ /* @__PURE__ */ jsx2("circle", { cx: "8", cy: "8", r: "6" }),
401
+ /* @__PURE__ */ jsx2("path", { d: "M18.09 10.37A6 6 0 1 1 10.34 18" }),
402
+ /* @__PURE__ */ jsx2("path", { d: "M7 6h1v4" }),
403
+ /* @__PURE__ */ jsx2("path", { d: "m16.71 13.88.7.71-2.82 2.82" })
404
+ ]
405
+ }
406
+ );
407
+ }
408
+ function ChartIcon({ className }) {
409
+ return /* @__PURE__ */ jsxs2(
410
+ "svg",
411
+ {
412
+ xmlns: "http://www.w3.org/2000/svg",
413
+ viewBox: "0 0 24 24",
414
+ fill: "none",
415
+ stroke: "currentColor",
416
+ strokeWidth: "2",
417
+ strokeLinecap: "round",
418
+ strokeLinejoin: "round",
419
+ className: cn("h-5 w-5", className),
420
+ children: [
421
+ /* @__PURE__ */ jsx2("title", { children: "Chart icon" }),
422
+ /* @__PURE__ */ jsx2("path", { d: "M3 3v18h18" }),
423
+ /* @__PURE__ */ jsx2("path", { d: "m19 9-5 5-4-4-3 3" })
424
+ ]
425
+ }
426
+ );
427
+ }
428
+ function BillingDashboard({
429
+ subscription,
430
+ balance,
431
+ usage,
432
+ onManageSubscription,
433
+ onAddCredits,
434
+ variant = "sandbox",
435
+ className,
436
+ cardClassName
437
+ }) {
438
+ const colors2 = variantColors[variant];
439
+ const totalCredits = balance.available + balance.used;
440
+ const usagePercent = totalCredits > 0 ? balance.used / totalCredits * 100 : 0;
441
+ const sortedModels = Object.entries(usage.byModel).sort(
442
+ ([, a], [, b]) => b - a
443
+ );
444
+ return /* @__PURE__ */ jsxs2("div", { className: cn("grid gap-6 lg:grid-cols-3", className), children: [
445
+ /* @__PURE__ */ jsxs2(Card, { variant, className: cn("lg:col-span-1", cardClassName), children: [
446
+ /* @__PURE__ */ jsx2(CardHeader, { children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
447
+ /* @__PURE__ */ jsxs2(CardTitle, { className: "flex items-center gap-2 text-base", children: [
448
+ /* @__PURE__ */ jsx2(CreditCardIcon, { className: colors2.accent }),
449
+ "Current Plan"
450
+ ] }),
451
+ subscription && /* @__PURE__ */ jsx2(Badge, { variant: getStatusBadgeVariant(subscription.status), children: subscription.status })
452
+ ] }) }),
453
+ /* @__PURE__ */ jsx2(CardContent, { className: "space-y-4", children: subscription ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
454
+ /* @__PURE__ */ jsxs2("div", { children: [
455
+ /* @__PURE__ */ jsx2("p", { className: cn("font-bold text-2xl", colors2.accent), children: subscription.tierName }),
456
+ /* @__PURE__ */ jsxs2("p", { className: "text-muted-foreground text-sm", children: [
457
+ "Renews ",
458
+ formatDate(subscription.renewsAt)
459
+ ] })
460
+ ] }),
461
+ /* @__PURE__ */ jsx2(
462
+ Button,
463
+ {
464
+ variant: "outline",
465
+ className: "w-full",
466
+ onClick: onManageSubscription,
467
+ children: "Manage Subscription"
468
+ }
469
+ )
470
+ ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
471
+ /* @__PURE__ */ jsxs2("div", { children: [
472
+ /* @__PURE__ */ jsx2("p", { className: "font-bold text-2xl text-muted-foreground", children: "No Active Plan" }),
473
+ /* @__PURE__ */ jsx2("p", { className: "text-muted-foreground text-sm", children: "Subscribe to get started" })
474
+ ] }),
475
+ /* @__PURE__ */ jsx2(
476
+ Button,
477
+ {
478
+ variant,
479
+ className: "w-full",
480
+ onClick: onManageSubscription,
481
+ children: "View Plans"
482
+ }
483
+ )
484
+ ] }) })
485
+ ] }),
486
+ /* @__PURE__ */ jsxs2(Card, { variant, className: cn("lg:col-span-1", cardClassName), children: [
487
+ /* @__PURE__ */ jsxs2(CardHeader, { children: [
488
+ /* @__PURE__ */ jsxs2(CardTitle, { className: "flex items-center gap-2 text-base", children: [
489
+ /* @__PURE__ */ jsx2(CoinsIcon, { className: colors2.accent }),
490
+ "Credit Balance"
491
+ ] }),
492
+ /* @__PURE__ */ jsxs2(CardDescription, { children: [
493
+ formatCredits(balance.available),
494
+ " credits remaining"
495
+ ] })
496
+ ] }),
497
+ /* @__PURE__ */ jsxs2(CardContent, { className: "space-y-4", children: [
498
+ /* @__PURE__ */ jsxs2("div", { className: "space-y-2", children: [
499
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between text-sm", children: [
500
+ /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: "Used" }),
501
+ /* @__PURE__ */ jsx2("span", { className: "font-medium", children: formatCredits(balance.used) })
502
+ ] }),
503
+ /* @__PURE__ */ jsx2(Progress, { value: usagePercent, variant, className: "h-3" }),
504
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between text-sm", children: [
505
+ /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: "Available" }),
506
+ /* @__PURE__ */ jsx2("span", { className: cn("font-medium", colors2.accent), children: formatCredits(balance.available) })
507
+ ] })
508
+ ] }),
509
+ /* @__PURE__ */ jsx2(Button, { variant, className: "w-full", onClick: onAddCredits, children: "Add Credits" })
510
+ ] })
511
+ ] }),
512
+ /* @__PURE__ */ jsxs2(Card, { variant, className: cn("lg:col-span-1", cardClassName), children: [
513
+ /* @__PURE__ */ jsxs2(CardHeader, { children: [
514
+ /* @__PURE__ */ jsxs2(CardTitle, { className: "flex items-center gap-2 text-base", children: [
515
+ /* @__PURE__ */ jsx2(ChartIcon, { className: colors2.accent }),
516
+ "Usage Breakdown"
517
+ ] }),
518
+ /* @__PURE__ */ jsx2(CardDescription, { children: usage.period })
519
+ ] }),
520
+ /* @__PURE__ */ jsxs2(CardContent, { className: "space-y-4", children: [
521
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-baseline justify-between", children: [
522
+ /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground text-sm", children: "Total Usage" }),
523
+ /* @__PURE__ */ jsx2("span", { className: cn("font-bold text-2xl", colors2.accent), children: formatCredits(usage.total) })
524
+ ] }),
525
+ /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
526
+ /* @__PURE__ */ jsx2("p", { className: "font-medium text-muted-foreground text-xs uppercase tracking-wider", children: "By Model" }),
527
+ /* @__PURE__ */ jsxs2("div", { className: "space-y-2", children: [
528
+ sortedModels.slice(0, 5).map(([model, credits]) => {
529
+ const modelPercent = usage.total > 0 ? credits / usage.total * 100 : 0;
530
+ return /* @__PURE__ */ jsxs2("div", { className: "space-y-1", children: [
531
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between text-sm", children: [
532
+ /* @__PURE__ */ jsx2("span", { className: "truncate text-muted-foreground", children: model }),
533
+ /* @__PURE__ */ jsx2("span", { className: "ml-2 font-medium", children: formatCredits(credits) })
534
+ ] }),
535
+ /* @__PURE__ */ jsx2("div", { className: "h-1.5 w-full overflow-hidden rounded-full bg-muted", children: /* @__PURE__ */ jsx2(
536
+ "div",
537
+ {
538
+ className: cn(
539
+ "h-full rounded-full transition-all",
540
+ variant === "sandbox" && colors2.progress
541
+ ),
542
+ style: { width: `${modelPercent}%` }
543
+ }
544
+ ) })
545
+ ] }, model);
546
+ }),
547
+ sortedModels.length > 5 && /* @__PURE__ */ jsxs2("p", { className: "text-muted-foreground text-xs", children: [
548
+ "+",
549
+ sortedModels.length - 5,
550
+ " more models"
551
+ ] }),
552
+ sortedModels.length === 0 && /* @__PURE__ */ jsx2("p", { className: "text-muted-foreground text-sm", children: "No usage this period" })
553
+ ] })
554
+ ] })
555
+ ] })
556
+ ] })
557
+ ] });
558
+ }
559
+
560
+ // src/dashboard/pricing-page.tsx
561
+ import { Check, Zap as Zap2 } from "lucide-react";
562
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
563
+ function formatPrice(cents) {
564
+ if (!Number.isFinite(cents) || cents < 0) return "$0";
565
+ return cents % 100 === 0 ? `$${cents / 100}` : `$${(cents / 100).toFixed(2)}`;
566
+ }
567
+ function PricingPage({
568
+ tiers,
569
+ currentTierId,
570
+ billingPeriod,
571
+ onBillingPeriodChange,
572
+ onSelectTier,
573
+ loading = false,
574
+ className
575
+ }) {
576
+ const tiersWithRecommended = tiers.map((tier, i) => ({
577
+ ...tier,
578
+ recommended: tier.recommended ?? (tiers.length === 3 && i === 1)
579
+ }));
580
+ return /* @__PURE__ */ jsxs3("div", { className: cn("w-full space-y-10", className), children: [
581
+ /* @__PURE__ */ jsx3("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxs3("div", { className: "inline-flex items-center rounded-full border border-border bg-muted/50 p-1", children: [
582
+ /* @__PURE__ */ jsx3(
583
+ "button",
584
+ {
585
+ type: "button",
586
+ onClick: () => onBillingPeriodChange("monthly"),
587
+ className: cn(
588
+ "rounded-full px-5 py-2 text-sm font-medium transition-all",
589
+ billingPeriod === "monthly" ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
590
+ ),
591
+ children: "Monthly"
592
+ }
593
+ ),
594
+ /* @__PURE__ */ jsxs3(
595
+ "button",
596
+ {
597
+ type: "button",
598
+ onClick: () => onBillingPeriodChange("yearly"),
599
+ className: cn(
600
+ "rounded-full px-5 py-2 text-sm font-medium transition-all",
601
+ billingPeriod === "yearly" ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
602
+ ),
603
+ children: [
604
+ "Yearly",
605
+ /* @__PURE__ */ jsx3("span", { className: "ml-2 rounded-full bg-[var(--surface-success-bg)] px-2 py-0.5 text-[10px] font-bold text-[var(--surface-success-text)]", children: "Save 20%" })
606
+ ]
607
+ }
608
+ )
609
+ ] }) }),
610
+ /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-1 gap-6 lg:grid-cols-3 items-start", children: tiersWithRecommended.map((tier) => {
611
+ const isCurrentTier = tier.id === currentTierId;
612
+ const isRecommended = tier.recommended;
613
+ const isFree = tier.monthlyPriceCents === 0;
614
+ const price = billingPeriod === "yearly" && tier.yearlyPriceCents !== void 0 ? tier.yearlyPriceCents : tier.monthlyPriceCents;
615
+ const displayPrice = billingPeriod === "yearly" ? Math.round(price / 12) : price;
616
+ return /* @__PURE__ */ jsxs3(
617
+ "div",
618
+ {
619
+ className: cn(
620
+ "relative flex flex-col rounded-2xl border transition-all",
621
+ isRecommended ? "border-primary shadow-[var(--shadow-glow)] scale-[1.02] z-10" : "border-border hover:border-primary/30"
622
+ ),
623
+ children: [
624
+ isRecommended && /* @__PURE__ */ jsx3("div", { className: "absolute -top-4 left-1/2 -translate-x-1/2", children: /* @__PURE__ */ jsxs3("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-primary px-4 py-1.5 text-xs font-bold text-primary-foreground shadow-sm", children: [
625
+ /* @__PURE__ */ jsx3(Zap2, { className: "h-3 w-3" }),
626
+ "Most Popular"
627
+ ] }) }),
628
+ isCurrentTier && !isRecommended && /* @__PURE__ */ jsx3("div", { className: "absolute -top-4 left-1/2 -translate-x-1/2", children: /* @__PURE__ */ jsx3("span", { className: "inline-flex items-center rounded-full bg-muted border border-border px-4 py-1.5 text-xs font-bold text-foreground", children: "Current Plan" }) }),
629
+ /* @__PURE__ */ jsxs3("div", { className: cn("flex flex-col p-8", isRecommended && "pt-10"), children: [
630
+ /* @__PURE__ */ jsxs3("div", { className: "mb-6", children: [
631
+ /* @__PURE__ */ jsx3("h3", { className: "text-lg font-bold text-foreground", children: tier.name }),
632
+ /* @__PURE__ */ jsx3("p", { className: "mt-1 text-sm text-muted-foreground", children: tier.description })
633
+ ] }),
634
+ /* @__PURE__ */ jsxs3("div", { className: "mb-8", children: [
635
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-baseline gap-1", children: [
636
+ /* @__PURE__ */ jsx3("span", { className: cn("text-5xl font-extrabold tracking-tight", isRecommended ? "text-primary" : "text-foreground"), children: isFree ? "Free" : formatPrice(displayPrice) }),
637
+ !isFree && /* @__PURE__ */ jsx3("span", { className: "text-muted-foreground text-sm font-medium", children: "/mo" })
638
+ ] }),
639
+ billingPeriod === "yearly" && tier.yearlyPriceCents !== void 0 && !isFree && /* @__PURE__ */ jsxs3("p", { className: "mt-1 text-xs text-muted-foreground", children: [
640
+ formatPrice(tier.yearlyPriceCents),
641
+ " billed annually"
642
+ ] })
643
+ ] }),
644
+ /* @__PURE__ */ jsx3(
645
+ "button",
646
+ {
647
+ type: "button",
648
+ onClick: () => onSelectTier(tier.id),
649
+ disabled: isCurrentTier || loading,
650
+ className: cn(
651
+ "w-full rounded-xl py-3 text-sm font-bold transition-all active:scale-[0.98] disabled:opacity-50",
652
+ isRecommended ? "bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm" : isCurrentTier ? "bg-muted text-muted-foreground border border-border cursor-default" : "bg-card text-foreground border border-border hover:border-primary/50 hover:bg-muted"
653
+ ),
654
+ children: isCurrentTier ? "Current Plan" : isFree ? "Get Started" : "Subscribe"
655
+ }
656
+ ),
657
+ /* @__PURE__ */ jsx3("div", { className: "my-8 border-t border-border" }),
658
+ /* @__PURE__ */ jsx3("ul", { className: "space-y-3.5 flex-1", children: tier.features.map((feature) => /* @__PURE__ */ jsxs3("li", { className: "flex items-start gap-3", children: [
659
+ /* @__PURE__ */ jsx3("div", { className: cn(
660
+ "mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full",
661
+ isRecommended ? "bg-primary/10 text-primary" : "bg-muted text-muted-foreground"
662
+ ), children: /* @__PURE__ */ jsx3(Check, { className: "h-3 w-3" }) }),
663
+ /* @__PURE__ */ jsx3("span", { className: "text-sm text-foreground/80", children: feature })
664
+ ] }, feature)) })
665
+ ] })
666
+ ]
667
+ },
668
+ tier.id
669
+ );
670
+ }) })
671
+ ] });
672
+ }
673
+
674
+ // src/dashboard/usage-chart.tsx
675
+ import * as React2 from "react";
676
+ import { Card as Card2, CardContent as CardContent2, CardHeader as CardHeader2, CardTitle as CardTitle2 } from "@tangle-network/ui/primitives";
677
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
678
+ var colors = {
679
+ bar: "bg-[image:var(--accent-gradient-strong)]",
680
+ barHover: "hover:brightness-110",
681
+ text: "text-[var(--accent-text)]"
682
+ };
683
+ function formatDate2(dateStr) {
684
+ const date = new Date(dateStr);
685
+ return date.toLocaleDateString("en-US", { month: "short", day: "numeric" });
686
+ }
687
+ function formatValue(value) {
688
+ if (value >= 1e6) {
689
+ return `${(value / 1e6).toFixed(1)}M`;
690
+ }
691
+ if (value >= 1e3) {
692
+ return `${(value / 1e3).toFixed(1)}K`;
693
+ }
694
+ return value.toLocaleString();
695
+ }
696
+ function UsageChart({ data, title, unit, className }) {
697
+ const maxValue = Math.max(...data.map((d) => d.value), 1);
698
+ const total = data.reduce((sum, d) => sum + d.value, 0);
699
+ const [hoveredIndex, setHoveredIndex] = React2.useState(null);
700
+ return /* @__PURE__ */ jsxs4(Card2, { className, children: [
701
+ /* @__PURE__ */ jsxs4(CardHeader2, { className: "flex flex-row items-center justify-between pb-2", children: [
702
+ /* @__PURE__ */ jsx4(CardTitle2, { className: "font-medium text-base", children: title }),
703
+ /* @__PURE__ */ jsxs4("div", { className: "text-right", children: [
704
+ /* @__PURE__ */ jsx4("span", { className: cn("font-bold text-2xl", colors.text), children: formatValue(total) }),
705
+ /* @__PURE__ */ jsx4("span", { className: "ml-1 text-muted-foreground text-sm", children: unit })
706
+ ] })
707
+ ] }),
708
+ /* @__PURE__ */ jsxs4(CardContent2, { children: [
709
+ /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
710
+ /* @__PURE__ */ jsxs4("div", { className: "absolute top-0 left-0 flex h-48 flex-col justify-between text-muted-foreground text-xs", children: [
711
+ /* @__PURE__ */ jsx4("span", { children: formatValue(maxValue) }),
712
+ /* @__PURE__ */ jsx4("span", { children: formatValue(Math.round(maxValue / 2)) }),
713
+ /* @__PURE__ */ jsx4("span", { children: "0" })
714
+ ] }),
715
+ /* @__PURE__ */ jsx4("div", { className: "ml-10 flex h-48 items-end gap-1", children: data.map((point, index) => {
716
+ const heightPercent = point.value / maxValue * 100;
717
+ const isHovered = hoveredIndex === index;
718
+ return (
719
+ // biome-ignore lint/a11y/noStaticElementInteractions: chart bar uses hover for tooltip display
720
+ /* @__PURE__ */ jsxs4(
721
+ "div",
722
+ {
723
+ className: "group relative flex flex-1 flex-col items-center",
724
+ onMouseEnter: () => setHoveredIndex(index),
725
+ onMouseLeave: () => setHoveredIndex(null),
726
+ children: [
727
+ isHovered && /* @__PURE__ */ jsxs4("div", { className: "absolute -top-12 z-10 rounded-lg bg-popover px-3 py-1.5 text-sm shadow-lg", children: [
728
+ /* @__PURE__ */ jsxs4("p", { className: "font-medium", children: [
729
+ formatValue(point.value),
730
+ " ",
731
+ unit
732
+ ] }),
733
+ /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground text-xs", children: formatDate2(point.date) })
734
+ ] }),
735
+ /* @__PURE__ */ jsx4(
736
+ "div",
737
+ {
738
+ className: cn(
739
+ "min-h-[2px] w-full rounded-t-sm transition-all duration-200",
740
+ colors.bar,
741
+ colors.barHover,
742
+ isHovered && "opacity-80"
743
+ ),
744
+ style: { height: `${Math.max(heightPercent, 1)}%` }
745
+ }
746
+ )
747
+ ]
748
+ },
749
+ point.date
750
+ )
751
+ );
752
+ }) }),
753
+ /* @__PURE__ */ jsx4("div", { className: "mt-2 ml-10 flex gap-1", children: data.map((point, index) => /* @__PURE__ */ jsx4(
754
+ "div",
755
+ {
756
+ className: cn(
757
+ "flex-1 truncate text-center text-muted-foreground text-xs",
758
+ hoveredIndex === index && colors.text
759
+ ),
760
+ children: data.length <= 7 || index % Math.ceil(data.length / 7) === 0 ? formatDate2(point.date) : ""
761
+ },
762
+ point.date
763
+ )) })
764
+ ] }),
765
+ /* @__PURE__ */ jsxs4("div", { className: "mt-4 grid grid-cols-3 gap-4 border-border border-t pt-4", children: [
766
+ /* @__PURE__ */ jsxs4("div", { className: "text-center", children: [
767
+ /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground text-xs", children: "Average" }),
768
+ /* @__PURE__ */ jsxs4("p", { className: "font-medium", children: [
769
+ formatValue(Math.round(total / data.length)),
770
+ " ",
771
+ unit
772
+ ] })
773
+ ] }),
774
+ /* @__PURE__ */ jsxs4("div", { className: "text-center", children: [
775
+ /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground text-xs", children: "Peak" }),
776
+ /* @__PURE__ */ jsxs4("p", { className: "font-medium", children: [
777
+ formatValue(maxValue),
778
+ " ",
779
+ unit
780
+ ] })
781
+ ] }),
782
+ /* @__PURE__ */ jsxs4("div", { className: "text-center", children: [
783
+ /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground text-xs", children: "Total" }),
784
+ /* @__PURE__ */ jsxs4("p", { className: cn("font-medium", colors.text), children: [
785
+ formatValue(total),
786
+ " ",
787
+ unit
788
+ ] })
789
+ ] })
790
+ ] })
791
+ ] })
792
+ ] });
793
+ }
794
+
795
+ // src/dashboard/template-card.tsx
796
+ import { ArrowRight } from "lucide-react";
797
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
798
+ function TemplateCard({ template, onUseTemplate, className }) {
799
+ return /* @__PURE__ */ jsxs5(
800
+ "div",
801
+ {
802
+ className: cn(
803
+ "group relative flex flex-col justify-between rounded-2xl border border-border bg-card p-6 transition-all hover:border-primary/30 hover:shadow-md",
804
+ className
805
+ ),
806
+ children: [
807
+ /* @__PURE__ */ jsxs5("div", { children: [
808
+ /* @__PURE__ */ jsx5("div", { className: "mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-muted border border-border", children: template.icon ?? /* @__PURE__ */ jsx5("span", { className: "text-lg font-bold text-primary", children: template.name.charAt(0).toUpperCase() }) }),
809
+ /* @__PURE__ */ jsx5("h3", { className: "mb-1 text-base font-bold text-foreground", children: template.name }),
810
+ /* @__PURE__ */ jsx5("p", { className: "text-sm text-muted-foreground leading-relaxed line-clamp-2", children: template.description }),
811
+ template.tags && template.tags.length > 0 && /* @__PURE__ */ jsx5("div", { className: "mt-3 flex flex-wrap gap-1.5", children: template.tags.map((tag, i) => /* @__PURE__ */ jsx5(
812
+ "span",
813
+ {
814
+ className: "rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground",
815
+ children: tag
816
+ },
817
+ `${tag}-${i}`
818
+ )) })
819
+ ] }),
820
+ /* @__PURE__ */ jsxs5(
821
+ "button",
822
+ {
823
+ type: "button",
824
+ onClick: () => onUseTemplate(template.id),
825
+ className: "mt-5 inline-flex w-full items-center justify-center gap-2 rounded-xl bg-primary/10 border border-primary/20 px-4 py-2.5 text-sm font-bold text-primary transition-colors hover:bg-primary hover:text-primary-foreground active:scale-[0.98]",
826
+ children: [
827
+ "Use Template",
828
+ /* @__PURE__ */ jsx5(ArrowRight, { className: "h-4 w-4 transition-transform group-hover:translate-x-0.5" })
829
+ ]
830
+ }
831
+ )
832
+ ]
833
+ }
834
+ );
835
+ }
836
+
837
+ // src/dashboard/info-panel.tsx
838
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
839
+ function InfoPanel({ label, title, description, className }) {
840
+ return /* @__PURE__ */ jsxs6("div", { className: cn("rounded-lg bg-[var(--brand-strong)] p-5 text-[var(--brand-strong-text)] relative overflow-hidden", className), children: [
841
+ /* @__PURE__ */ jsxs6("div", { className: "relative z-10", children: [
842
+ /* @__PURE__ */ jsx6("p", { className: "text-[10px] font-bold uppercase tracking-widest text-[var(--brand-strong-text-dim)]", children: label }),
843
+ /* @__PURE__ */ jsx6("h3", { className: "mt-1 text-lg font-bold", children: title }),
844
+ /* @__PURE__ */ jsx6("p", { className: "mt-1 text-sm text-[var(--brand-strong-text-muted)]", children: description })
845
+ ] }),
846
+ /* @__PURE__ */ jsx6("div", { className: "absolute right-0 top-0 h-full w-1/3 bg-white/5 -skew-x-12 translate-x-12 pointer-events-none" })
847
+ ] });
848
+ }
849
+
850
+ export {
851
+ canonicalModelId,
852
+ formatPricing,
853
+ formatContext,
854
+ ModelPicker,
855
+ BillingDashboard,
856
+ formatPrice,
857
+ PricingPage,
858
+ UsageChart,
859
+ TemplateCard,
860
+ InfoPanel
861
+ };