@locusgraph/loop 0.1.0 → 0.2.1

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.
Files changed (115) hide show
  1. package/README.md +2 -0
  2. package/dist/agent/pulse/gradient-label.js +36 -15
  3. package/dist/agent/pulse/marks/bars-mark.js +24 -10
  4. package/dist/agent/pulse/marks/glyph-mark.js +17 -11
  5. package/dist/agent/pulse/marks/locus-mark.js +39 -28
  6. package/dist/agent/pulse/marks/orb-mark.js +21 -8
  7. package/dist/agent/pulse/marks/spinner-mark.js +20 -1
  8. package/dist/agent/pulse/pulse.js +63 -35
  9. package/dist/agent/pulse/use-loop-animation.js +14 -16
  10. package/dist/agent/steps/step-icon.js +40 -24
  11. package/dist/agent/steps/steps.js +72 -25
  12. package/dist/agent/thinking/thinking.js +203 -23
  13. package/dist/agent/thinking/thought-duration.js +7 -9
  14. package/dist/agent/tool/json-block.js +18 -11
  15. package/dist/agent/tool/tool-status.js +28 -18
  16. package/dist/agent/tool/tool.js +184 -6
  17. package/dist/approval/inbox/inbox-row.d.ts +3 -2
  18. package/dist/approval/inbox/inbox-row.js +96 -7
  19. package/dist/approval/inbox/inbox-selection.js +7 -13
  20. package/dist/approval/inbox/inbox.d.ts +2 -1
  21. package/dist/approval/inbox/inbox.js +99 -18
  22. package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
  23. package/dist/approval/inbox/virtual-inbox-list.js +53 -0
  24. package/dist/approval/memory/memory-choices.js +27 -22
  25. package/dist/approval/memory/memory-review.js +108 -17
  26. package/dist/approval/memory/memory-row.js +80 -19
  27. package/dist/approval/plan/plan-review.js +129 -28
  28. package/dist/approval/plan/plan-step-row.js +91 -44
  29. package/dist/approval/plan/plan-steps.js +24 -23
  30. package/dist/approval/plan/question-choices.js +73 -40
  31. package/dist/approval/plan/question.d.ts +1 -1
  32. package/dist/approval/plan/question.js +108 -27
  33. package/dist/approval/run/run-bar.js +94 -22
  34. package/dist/approval/shared/decision-line.js +1 -1
  35. package/dist/approval/shared/risk-badge.js +32 -16
  36. package/dist/approval/shared/time.js +5 -8
  37. package/dist/approval/shared/use-focus-on-mount.js +7 -6
  38. package/dist/approval/spend/raise-cap-form.js +64 -19
  39. package/dist/approval/spend/spend-gate.js +124 -21
  40. package/dist/approval/spend/spend-math.js +7 -8
  41. package/dist/approval/spend/spend-meter.js +136 -35
  42. package/dist/approval/tool/approval.js +113 -27
  43. package/dist/approval/tool/args/args-editor.js +104 -26
  44. package/dist/approval/tool/args/args-field.js +79 -22
  45. package/dist/approval/tool/args/args-validation.js +38 -47
  46. package/dist/approval/tool/deny-form.js +43 -10
  47. package/dist/approval/tool/tool-inputs.js +62 -38
  48. package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
  49. package/dist/chat/chat/chat-item-spacing.js +19 -0
  50. package/dist/chat/chat/chat.d.ts +2 -1
  51. package/dist/chat/chat/chat.js +181 -5
  52. package/dist/chat/chat/use-stick-to-bottom.js +71 -48
  53. package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
  54. package/dist/chat/chat/virtual-chat-items.js +60 -0
  55. package/dist/chat/composer/composer-actions.js +69 -17
  56. package/dist/chat/composer/composer.js +330 -32
  57. package/dist/chat/composer/use-auto-grow.js +9 -9
  58. package/dist/chat/files/file-meta.js +19 -19
  59. package/dist/chat/files/files.js +92 -29
  60. package/dist/chat/reply/fenced-code.js +23 -21
  61. package/dist/chat/reply/markdown-components.js +137 -17
  62. package/dist/chat/reply/reply.js +30 -10
  63. package/dist/chat/turn/group-parts.js +43 -29
  64. package/dist/chat/turn/turn.js +87 -30
  65. package/dist/cost/context.js +104 -23
  66. package/dist/cost/cost-steps.js +67 -14
  67. package/dist/cost/cost.js +128 -23
  68. package/dist/cost/model-picker.js +51 -6
  69. package/dist/cost/shared/context-breakdown.js +83 -10
  70. package/dist/cost/shared/meter-marks.js +49 -9
  71. package/dist/cost/shared/model-option-row.js +56 -22
  72. package/dist/cost/shared/step-cost-row.js +65 -22
  73. package/dist/cost/shared/usage-totals.js +22 -18
  74. package/dist/memory/cite.js +62 -12
  75. package/dist/memory/memorized.js +65 -11
  76. package/dist/memory/recall.js +101 -17
  77. package/dist/memory/shared/host-label.js +19 -22
  78. package/dist/memory/shared/source-mark.js +11 -3
  79. package/dist/memory/sources.js +78 -14
  80. package/dist/shared/decision-summary.js +51 -14
  81. package/dist/shared/panel-empty.js +20 -3
  82. package/dist/shared/panel.js +69 -13
  83. package/dist/shared/status-dot.js +16 -8
  84. package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
  85. package/dist/shared/virtual/use-list-virtualizer.js +68 -0
  86. package/dist/thread/actions/action-button.js +22 -3
  87. package/dist/thread/actions/actions.js +184 -13
  88. package/dist/thread/actions/branch-switcher.js +28 -5
  89. package/dist/thread/canvas/canvas.js +205 -5
  90. package/dist/thread/canvas/version-switcher.js +54 -8
  91. package/dist/thread/code/code.js +186 -24
  92. package/dist/thread/code/copy-code-button.js +30 -14
  93. package/dist/thread/code/highlight.js +30 -29
  94. package/dist/thread/history/history-rows.d.ts +16 -0
  95. package/dist/thread/history/history-rows.js +23 -0
  96. package/dist/thread/history/history.d.ts +3 -2
  97. package/dist/thread/history/history.js +174 -5
  98. package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
  99. package/dist/thread/history/row/history-row.js +58 -0
  100. package/dist/thread/history/row/thread-item-menu.js +31 -0
  101. package/dist/thread/history/row/thread-title-editor.js +38 -0
  102. package/dist/thread/history/thread-groups.d.ts +1 -1
  103. package/dist/thread/history/thread-groups.js +40 -34
  104. package/dist/thread/history/virtual-history-list.d.ts +11 -0
  105. package/dist/thread/history/virtual-history-list.js +71 -0
  106. package/dist/thread/index.d.ts +1 -1
  107. package/dist/thread/starters/starters.js +33 -8
  108. package/dist/thread/use-copied.js +18 -16
  109. package/dist/types.js +1 -1
  110. package/package.json +6 -4
  111. package/dist/thread/history/history-row.js +0 -17
  112. package/dist/thread/history/thread-item-menu.js +0 -6
  113. package/dist/thread/history/thread-title-editor.js +0 -25
  114. /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
  115. /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
@@ -1,35 +1,116 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { cn, HoverCard, HoverCardContent, HoverCardTrigger } from "@locusgraph/components";
3
2
  import { formatCount, nearLimitPercent, quotaPercent } from "@locusgraph/utils";
4
3
  import { ContextBreakdown } from "./shared/context-breakdown.js";
5
4
  import { MeterBar, MeterRing } from "./shared/meter-marks.js";
6
5
  import { formatTokensShort } from "./shared/usage-totals.js";
6
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
7
7
  export function contextStatus(usedTokens, limitTokens) {
8
- if (usedTokens >= limitTokens)
9
- return "full";
10
- const percent = quotaPercent({ used: usedTokens, included: limitTokens });
11
- return percent >= nearLimitPercent ? "near" : "ok";
8
+ if (usedTokens >= limitTokens) return "full";
9
+ const percent = quotaPercent({
10
+ used: usedTokens,
11
+ included: limitTokens
12
+ });
13
+ return percent >= nearLimitPercent ? "near" : "ok";
12
14
  }
13
15
  const statusTone = {
14
- ok: "text-muted-foreground",
15
- near: "text-warn",
16
- full: "text-destructive",
16
+ ok: "text-muted-foreground",
17
+ near: "text-warn",
18
+ full: "text-destructive"
17
19
  };
18
- function RingContent({ percent, status }) {
19
- return (_jsxs(_Fragment, { children: [_jsx(MeterRing, { percent: percent, status: status }), _jsxs("span", { className: "font-mono text-[11px] tabular-nums", children: [percent, "%"] })] }));
20
+ function RingContent({
21
+ percent,
22
+ status
23
+ }) {
24
+ return /*#__PURE__*/_jsxs(_Fragment, {
25
+ children: [/*#__PURE__*/_jsx(MeterRing, {
26
+ percent: percent,
27
+ status: status
28
+ }), /*#__PURE__*/_jsxs("span", {
29
+ className: "font-mono text-[11px] tabular-nums",
30
+ children: [percent, "%"]
31
+ })]
32
+ });
20
33
  }
21
- function BarContent({ label, usedTokens, limitTokens, percent, status, }) {
22
- return (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex items-baseline justify-between gap-4 font-mono text-[11px] tabular-nums", children: [_jsx("span", { className: "eyebrow", children: label }), _jsxs("span", { className: cn(status === "ok" && "text-foreground"), children: [percent, "% \u00B7 ", formatTokensShort(usedTokens), " / ", formatTokensShort(limitTokens)] })] }), _jsx(MeterBar, { percent: percent, status: status })] }));
34
+ function BarContent({
35
+ label,
36
+ usedTokens,
37
+ limitTokens,
38
+ percent,
39
+ status
40
+ }) {
41
+ return /*#__PURE__*/_jsxs(_Fragment, {
42
+ children: [/*#__PURE__*/_jsxs("span", {
43
+ className: "flex items-baseline justify-between gap-4 font-mono text-[11px] tabular-nums",
44
+ children: [/*#__PURE__*/_jsx("span", {
45
+ className: "eyebrow",
46
+ children: label
47
+ }), /*#__PURE__*/_jsxs("span", {
48
+ className: cn(status === "ok" && "text-foreground"),
49
+ children: [percent, "% \xB7 ", formatTokensShort(usedTokens), " / ", formatTokensShort(limitTokens)]
50
+ })]
51
+ }), /*#__PURE__*/_jsx(MeterBar, {
52
+ percent: percent,
53
+ status: status
54
+ })]
55
+ });
23
56
  }
24
- export function Context({ usedTokens, limitTokens, breakdown, variant = "bar", label = "Context", className, }) {
25
- const percent = quotaPercent({ used: usedTokens, included: limitTokens });
26
- const status = contextStatus(usedTokens, limitTokens);
27
- const summary = `${formatCount(usedTokens)} of ${formatCount(limitTokens)} tokens`;
28
- const hasBreakdown = breakdown !== undefined && breakdown.length > 0;
29
- const meter = (_jsx("div", { "data-slot": "context", "data-status": status, "data-variant": variant, role: "meter", "aria-label": `${label} window`, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, "aria-valuetext": `${percent}%, ${summary}`, tabIndex: hasBreakdown ? 0 : undefined, className: cn("outline-none focus-visible:ring-2 focus-visible:ring-ring/70", statusTone[status], variant === "ring"
30
- ? "inline-flex h-6 items-center gap-1.5 rounded-full px-2 transition-colors duration-150 motion-reduce:transition-none"
31
- : "flex w-full flex-col gap-2", variant === "ring" && hasBreakdown && "cursor-default hover:bg-accent", className), children: variant === "ring" ? (_jsx(RingContent, { percent: percent, status: status })) : (_jsx(BarContent, { label: label, usedTokens: usedTokens, limitTokens: limitTokens, percent: percent, status: status })) }));
32
- if (!hasBreakdown)
33
- return meter;
34
- return (_jsxs(HoverCard, { openDelay: 100, closeDelay: 100, children: [_jsx(HoverCardTrigger, { asChild: true, children: meter }), _jsx(HoverCardContent, { align: "end", sideOffset: 6, className: "w-72 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border", children: _jsx(ContextBreakdown, { label: label, usedTokens: usedTokens, limitTokens: limitTokens, percent: percent, status: status, breakdown: breakdown }) })] }));
57
+ export function Context({
58
+ usedTokens,
59
+ limitTokens,
60
+ breakdown,
61
+ variant = "bar",
62
+ label = "Context",
63
+ className
64
+ }) {
65
+ const percent = quotaPercent({
66
+ used: usedTokens,
67
+ included: limitTokens
68
+ });
69
+ const status = contextStatus(usedTokens, limitTokens);
70
+ const summary = `${formatCount(usedTokens)} of ${formatCount(limitTokens)} tokens`;
71
+ const hasBreakdown = breakdown !== undefined && breakdown.length > 0;
72
+ const meter = /*#__PURE__*/_jsx("div", {
73
+ "data-slot": "context",
74
+ "data-status": status,
75
+ "data-variant": variant,
76
+ role: "meter",
77
+ "aria-label": `${label} window`,
78
+ "aria-valuemin": 0,
79
+ "aria-valuemax": 100,
80
+ "aria-valuenow": percent,
81
+ "aria-valuetext": `${percent}%, ${summary}`,
82
+ tabIndex: hasBreakdown ? 0 : undefined,
83
+ className: cn("outline-none focus-visible:ring-2 focus-visible:ring-ring/70", statusTone[status], variant === "ring" ? "inline-flex h-6 items-center gap-1.5 rounded-full px-2 transition-colors duration-150 motion-reduce:transition-none" : "flex w-full flex-col gap-2", variant === "ring" && hasBreakdown && "cursor-default hover:bg-accent", className),
84
+ children: variant === "ring" ? /*#__PURE__*/_jsx(RingContent, {
85
+ percent: percent,
86
+ status: status
87
+ }) : /*#__PURE__*/_jsx(BarContent, {
88
+ label: label,
89
+ usedTokens: usedTokens,
90
+ limitTokens: limitTokens,
91
+ percent: percent,
92
+ status: status
93
+ })
94
+ });
95
+ if (!hasBreakdown) return meter;
96
+ return /*#__PURE__*/_jsxs(HoverCard, {
97
+ openDelay: 100,
98
+ closeDelay: 100,
99
+ children: [/*#__PURE__*/_jsx(HoverCardTrigger, {
100
+ asChild: true,
101
+ children: meter
102
+ }), /*#__PURE__*/_jsx(HoverCardContent, {
103
+ align: "end",
104
+ sideOffset: 6,
105
+ className: "w-72 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border",
106
+ children: /*#__PURE__*/_jsx(ContextBreakdown, {
107
+ label: label,
108
+ usedTokens: usedTokens,
109
+ limitTokens: limitTokens,
110
+ percent: percent,
111
+ status: status,
112
+ breakdown: breakdown
113
+ })
114
+ })]
115
+ });
35
116
  }
@@ -1,24 +1,77 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { Roadmap as ChartNoAxesGanttIcon } from "@carbon/icons-react";
3
2
  import { formatCount, formatMicroUsd, pluralize } from "@locusgraph/utils";
4
3
  import { ApprovalPanel, PanelHeader } from "../shared/panel.js";
5
4
  import { PanelEmpty } from "../shared/panel-empty.js";
6
5
  import { isWastedStep, StepCostRow } from "./shared/step-cost-row.js";
7
6
  import { formatDuration, sumUsage } from "./shared/usage-totals.js";
7
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
8
8
  export function stepCostTotals(steps) {
9
- const totals = sumUsage(steps.map((step) => step.usage));
10
- const wastedMicroUsd = steps
11
- .filter(isWastedStep)
12
- .reduce((sum, step) => sum + step.usage.costMicroUsd, 0);
13
- const durationMs = steps.reduce((sum, step) => sum + (step.durationMs ?? 0), 0);
14
- return { ...totals, wastedMicroUsd, durationMs };
9
+ const totals = sumUsage(steps.map(step => step.usage));
10
+ const wastedMicroUsd = steps.filter(isWastedStep).reduce((sum, step) => sum + step.usage.costMicroUsd, 0);
11
+ const durationMs = steps.reduce((sum, step) => sum + (step.durationMs ?? 0), 0);
12
+ return {
13
+ ...totals,
14
+ wastedMicroUsd,
15
+ durationMs
16
+ };
15
17
  }
16
- function Totals({ totals }) {
17
- return (_jsxs("div", { "data-slot": "step-cost-totals", className: "flex flex-col gap-1 px-5 pt-2 pb-4", children: [_jsx("span", { className: "text-2xl font-semibold tracking-tight tabular-nums", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums", children: [_jsxs("span", { children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out", totals.durationMs > 0 && ` · ${formatDuration(totals.durationMs)}`] }), totals.wastedMicroUsd > 0 && (_jsxs("span", { className: "text-destructive", children: ["Wasted on failures ", formatMicroUsd(totals.wastedMicroUsd)] }))] })] }));
18
+ function Totals({
19
+ totals
20
+ }) {
21
+ return /*#__PURE__*/_jsxs("div", {
22
+ "data-slot": "step-cost-totals",
23
+ className: "flex flex-col gap-1 px-5 pt-2 pb-4",
24
+ children: [/*#__PURE__*/_jsx("span", {
25
+ className: "text-2xl font-semibold tracking-tight tabular-nums",
26
+ children: formatMicroUsd(totals.costMicroUsd)
27
+ }), /*#__PURE__*/_jsxs("span", {
28
+ className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums",
29
+ children: [/*#__PURE__*/_jsxs("span", {
30
+ children: [formatCount(totals.inputTokens), " in \xB7 ", formatCount(totals.outputTokens), " out", totals.durationMs > 0 && ` · ${formatDuration(totals.durationMs)}`]
31
+ }), totals.wastedMicroUsd > 0 && /*#__PURE__*/_jsxs("span", {
32
+ className: "text-destructive",
33
+ children: ["Wasted on failures ", formatMicroUsd(totals.wastedMicroUsd)]
34
+ })]
35
+ })]
36
+ });
18
37
  }
19
- export function CostSteps({ steps, label = "Cost by step", emptyText = "No steps have run yet.", className, }) {
20
- const totals = stepCostTotals(steps);
21
- const maxCost = Math.max(0, ...steps.map((step) => step.usage.costMicroUsd));
22
- const running = steps.some((step) => step.status === "running");
23
- return (_jsxs(ApprovalPanel, { "data-slot": "cost-steps", "aria-label": label, className: className, children: [_jsx(PanelHeader, { icon: _jsx(ChartNoAxesGanttIcon, { "aria-hidden": true }), eyebrow: label, aside: steps.length > 0 ? pluralize(steps.length, "step") : undefined, status: running ? "Running" : undefined, tone: "running" }), steps.length === 0 ? (_jsx(PanelEmpty, { icon: _jsx(ChartNoAxesGanttIcon, { "aria-hidden": true }), title: emptyText })) : (_jsxs(_Fragment, { children: [_jsx(Totals, { totals: totals }), _jsx("ol", { className: "flex flex-col divide-y divide-border border-t border-border", children: steps.map((step) => (_jsx(StepCostRow, { step: step, maxCost: maxCost, totalCost: totals.costMicroUsd }, step.id))) })] }))] }));
38
+ export function CostSteps({
39
+ steps,
40
+ label = "Cost by step",
41
+ emptyText = "No steps have run yet.",
42
+ className
43
+ }) {
44
+ const totals = stepCostTotals(steps);
45
+ const maxCost = Math.max(0, ...steps.map(step => step.usage.costMicroUsd));
46
+ const running = steps.some(step => step.status === "running");
47
+ return /*#__PURE__*/_jsxs(ApprovalPanel, {
48
+ "data-slot": "cost-steps",
49
+ "aria-label": label,
50
+ className: className,
51
+ children: [/*#__PURE__*/_jsx(PanelHeader, {
52
+ icon: /*#__PURE__*/_jsx(ChartNoAxesGanttIcon, {
53
+ "aria-hidden": true
54
+ }),
55
+ eyebrow: label,
56
+ aside: steps.length > 0 ? pluralize(steps.length, "step") : undefined,
57
+ status: running ? "Running" : undefined,
58
+ tone: "running"
59
+ }), steps.length === 0 ? /*#__PURE__*/_jsx(PanelEmpty, {
60
+ icon: /*#__PURE__*/_jsx(ChartNoAxesGanttIcon, {
61
+ "aria-hidden": true
62
+ }),
63
+ title: emptyText
64
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
65
+ children: [/*#__PURE__*/_jsx(Totals, {
66
+ totals: totals
67
+ }), /*#__PURE__*/_jsx("ol", {
68
+ className: "flex flex-col divide-y divide-border border-t border-border",
69
+ children: steps.map(step => /*#__PURE__*/_jsx(StepCostRow, {
70
+ step: step,
71
+ maxCost: maxCost,
72
+ totalCost: totals.costMicroUsd
73
+ }, step.id))
74
+ })]
75
+ })]
76
+ });
24
77
  }
package/dist/cost/cost.js CHANGED
@@ -1,37 +1,142 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { Money as CoinsIcon } from "@carbon/icons-react";
3
2
  import { cn } from "@locusgraph/components";
4
3
  import { formatCount, formatMicroUsd, pluralize } from "@locusgraph/utils";
5
4
  import { ApprovalPanel, PanelHeader } from "../shared/panel.js";
6
5
  import { sumUsage } from "./shared/usage-totals.js";
6
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
7
7
  function attemptsOf(usage) {
8
- return Array.isArray(usage) ? usage : [usage];
8
+ return Array.isArray(usage) ? usage : [usage];
9
9
  }
10
10
  function modelsOf(attempts) {
11
- const models = [...new Set(attempts.map((attempt) => attempt.model).filter(Boolean))];
12
- return models.length > 0 ? models.join(", ") : undefined;
11
+ const models = [...new Set(attempts.map(attempt => attempt.model).filter(Boolean))];
12
+ return models.length > 0 ? models.join(", ") : undefined;
13
13
  }
14
- function WastedNote({ totals }) {
15
- if (totals.failedAttempts === 0)
16
- return null;
17
- return (_jsxs("span", { "data-slot": "cost-wasted", className: "text-destructive tabular-nums", children: [pluralize(totals.failedAttempts, "failed attempt"), " \u00B7 ", formatMicroUsd(totals.wastedMicroUsd), " ", "wasted"] }));
14
+ function WastedNote({
15
+ totals
16
+ }) {
17
+ if (totals.failedAttempts === 0) return null;
18
+ return /*#__PURE__*/_jsxs("span", {
19
+ "data-slot": "cost-wasted",
20
+ className: "text-destructive tabular-nums",
21
+ children: [pluralize(totals.failedAttempts, "failed attempt"), " \xB7 ", formatMicroUsd(totals.wastedMicroUsd), " ", "wasted"]
22
+ });
18
23
  }
19
- function CompactCost({ attempts, totals, className, }) {
20
- const model = modelsOf(attempts);
21
- return (_jsxs("span", { "data-slot": "cost", "data-variant": "compact", "data-failed": totals.failedAttempts > 0 || undefined, className: cn("inline-flex flex-wrap items-baseline gap-x-3 gap-y-0.5 font-mono text-[11px] text-muted-foreground tabular-nums", className), children: [_jsx("span", { className: "font-medium text-foreground", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "whitespace-nowrap", children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out"] }), model && _jsx("span", { children: model }), _jsx(WastedNote, { totals: totals })] }));
24
+ function CompactCost({
25
+ attempts,
26
+ totals,
27
+ className
28
+ }) {
29
+ const model = modelsOf(attempts);
30
+ return /*#__PURE__*/_jsxs("span", {
31
+ "data-slot": "cost",
32
+ "data-variant": "compact",
33
+ "data-failed": totals.failedAttempts > 0 || undefined,
34
+ className: cn("inline-flex flex-wrap items-baseline gap-x-3 gap-y-0.5 font-mono text-[11px] text-muted-foreground tabular-nums", className),
35
+ children: [/*#__PURE__*/_jsx("span", {
36
+ className: "font-medium text-foreground",
37
+ children: formatMicroUsd(totals.costMicroUsd)
38
+ }), /*#__PURE__*/_jsxs("span", {
39
+ className: "whitespace-nowrap",
40
+ children: [formatCount(totals.inputTokens), " in \xB7 ", formatCount(totals.outputTokens), " out"]
41
+ }), model && /*#__PURE__*/_jsx("span", {
42
+ children: model
43
+ }), /*#__PURE__*/_jsx(WastedNote, {
44
+ totals: totals
45
+ })]
46
+ });
22
47
  }
23
- function AttemptRow({ attempt, position }) {
24
- return (_jsxs("li", { "data-slot": "cost-attempt", "data-failed": attempt.failed || undefined, className: "grid grid-cols-[1fr_auto_4.5rem] items-baseline gap-x-4 px-5 py-2.5 text-sm tabular-nums", children: [_jsxs("span", { className: "flex min-w-0 items-baseline gap-2", children: [_jsxs("span", { className: "eyebrow", children: ["#", position + 1] }), _jsx("span", { className: cn("truncate", attempt.failed && "text-muted-foreground"), children: attempt.model ?? "Attempt" }), attempt.failed && (_jsx("span", { className: "font-mono text-[11px] tracking-wide text-destructive uppercase", children: "Failed" }))] }), _jsxs("span", { className: "font-mono text-[11px] text-muted-foreground max-sm:hidden", children: [formatCount(attempt.inputTokens), " in \u00B7 ", formatCount(attempt.outputTokens), " out"] }), _jsx("span", { className: cn("text-right font-mono text-xs", attempt.failed && "text-muted-foreground line-through"), children: formatMicroUsd(attempt.costMicroUsd) })] }));
48
+ function AttemptRow({
49
+ attempt,
50
+ position
51
+ }) {
52
+ return /*#__PURE__*/_jsxs("li", {
53
+ "data-slot": "cost-attempt",
54
+ "data-failed": attempt.failed || undefined,
55
+ className: "grid grid-cols-[1fr_auto_4.5rem] items-baseline gap-x-4 px-5 py-2.5 text-sm tabular-nums",
56
+ children: [/*#__PURE__*/_jsxs("span", {
57
+ className: "flex min-w-0 items-baseline gap-2",
58
+ children: [/*#__PURE__*/_jsxs("span", {
59
+ className: "eyebrow",
60
+ children: ["#", position + 1]
61
+ }), /*#__PURE__*/_jsx("span", {
62
+ className: cn("truncate", attempt.failed && "text-muted-foreground"),
63
+ children: attempt.model ?? "Attempt"
64
+ }), attempt.failed && /*#__PURE__*/_jsx("span", {
65
+ className: "font-mono text-[11px] tracking-wide text-destructive uppercase",
66
+ children: "Failed"
67
+ })]
68
+ }), /*#__PURE__*/_jsxs("span", {
69
+ className: "font-mono text-[11px] text-muted-foreground max-sm:hidden",
70
+ children: [formatCount(attempt.inputTokens), " in \xB7 ", formatCount(attempt.outputTokens), " out"]
71
+ }), /*#__PURE__*/_jsx("span", {
72
+ className: cn("text-right font-mono text-xs", attempt.failed && "text-muted-foreground line-through"),
73
+ children: formatMicroUsd(attempt.costMicroUsd)
74
+ })]
75
+ });
25
76
  }
26
- function DetailedCost({ attempts, totals, label, className, }) {
27
- const failed = totals.failedAttempts > 0;
28
- return (_jsxs(ApprovalPanel, { "data-slot": "cost", "data-variant": "detailed", "data-failed": failed || undefined, "aria-label": label, className: className, children: [_jsx(PanelHeader, { icon: _jsx(CoinsIcon, { "aria-hidden": true }), eyebrow: label, aside: pluralize(attempts.length, "attempt") }), _jsxs("div", { className: "flex flex-col gap-1 px-5 pt-2 pb-4", children: [_jsx("span", { className: "text-2xl font-semibold tracking-tight tabular-nums", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums", children: [_jsxs("span", { children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out"] }), _jsx(WastedNote, { totals: totals })] })] }), _jsx("ol", { className: "flex flex-col divide-y divide-border border-t border-border", children: attempts.map((attempt, position) => (_jsx(AttemptRow, { attempt: attempt, position: position }, position))) })] }));
77
+ function DetailedCost({
78
+ attempts,
79
+ totals,
80
+ label,
81
+ className
82
+ }) {
83
+ const failed = totals.failedAttempts > 0;
84
+ return /*#__PURE__*/_jsxs(ApprovalPanel, {
85
+ "data-slot": "cost",
86
+ "data-variant": "detailed",
87
+ "data-failed": failed || undefined,
88
+ "aria-label": label,
89
+ className: className,
90
+ children: [/*#__PURE__*/_jsx(PanelHeader, {
91
+ icon: /*#__PURE__*/_jsx(CoinsIcon, {
92
+ "aria-hidden": true
93
+ }),
94
+ eyebrow: label,
95
+ aside: pluralize(attempts.length, "attempt")
96
+ }), /*#__PURE__*/_jsxs("div", {
97
+ className: "flex flex-col gap-1 px-5 pt-2 pb-4",
98
+ children: [/*#__PURE__*/_jsx("span", {
99
+ className: "text-2xl font-semibold tracking-tight tabular-nums",
100
+ children: formatMicroUsd(totals.costMicroUsd)
101
+ }), /*#__PURE__*/_jsxs("span", {
102
+ className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums",
103
+ children: [/*#__PURE__*/_jsxs("span", {
104
+ children: [formatCount(totals.inputTokens), " in \xB7 ", formatCount(totals.outputTokens), " out"]
105
+ }), /*#__PURE__*/_jsx(WastedNote, {
106
+ totals: totals
107
+ })]
108
+ })]
109
+ }), /*#__PURE__*/_jsx("ol", {
110
+ className: "flex flex-col divide-y divide-border border-t border-border",
111
+ children: attempts.map((attempt, position) =>
112
+ /*#__PURE__*/
113
+ // biome-ignore lint/suspicious/noArrayIndexKey: attempts carry no id and keep their order
114
+ _jsx(AttemptRow, {
115
+ attempt: attempt,
116
+ position: position
117
+ }, position))
118
+ })]
119
+ });
29
120
  }
30
- export function Cost({ usage, variant = "compact", label = "Run cost", className }) {
31
- const attempts = attemptsOf(usage);
32
- const totals = sumUsage(attempts);
33
- if (variant === "detailed") {
34
- return _jsx(DetailedCost, { attempts: attempts, totals: totals, label: label, className: className });
35
- }
36
- return _jsx(CompactCost, { attempts: attempts, totals: totals, className: className });
121
+ export function Cost({
122
+ usage,
123
+ variant = "compact",
124
+ label = "Run cost",
125
+ className
126
+ }) {
127
+ const attempts = attemptsOf(usage);
128
+ const totals = sumUsage(attempts);
129
+ if (variant === "detailed") {
130
+ return /*#__PURE__*/_jsx(DetailedCost, {
131
+ attempts: attempts,
132
+ totals: totals,
133
+ label: label,
134
+ className: className
135
+ });
136
+ }
137
+ return /*#__PURE__*/_jsx(CompactCost, {
138
+ attempts: attempts,
139
+ totals: totals,
140
+ className: className
141
+ });
37
142
  }
@@ -1,9 +1,54 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { ChevronDown as ChevronDownIcon } from "@carbon/icons-react";
3
- import { cn, DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuTrigger, } from "@locusgraph/components";
2
+ import { cn, DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuTrigger } from "@locusgraph/components";
4
3
  import { ModelOptionRow } from "./shared/model-option-row.js";
5
- export { modelPriceLabel, } from "./shared/model-option-row.js";
6
- export function ModelPicker({ models, value, onChange, label = "Model", disabled = false, className, }) {
7
- const selected = models.find((model) => model.id === value);
8
- return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "data-slot": "model-picker", "data-value": value, disabled: disabled, "aria-label": `${label}: ${selected?.name ?? "none selected"}`, className: cn("group inline-flex h-7 max-w-full items-center gap-1.5 rounded-full px-2.5 text-xs outline-none transition-colors duration-150 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent motion-reduce:transition-none", className), children: [_jsx("span", { className: "truncate font-medium", children: selected?.name ?? label }), selected && (_jsx("span", { className: "truncate text-muted-foreground max-sm:hidden", children: selected.provider })), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3 shrink-0 text-muted-foreground transition-transform duration-150 group-data-[state=open]:rotate-180 motion-reduce:transition-none" })] }), _jsxs(DropdownMenuContent, { align: "start", sideOffset: 6, className: "w-80 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border", children: [_jsxs(DropdownMenuLabel, { className: "eyebrow flex justify-between gap-3 border-b border-border px-3 py-2 font-normal", children: [_jsx("span", { children: label }), _jsx("span", { className: "pr-7", children: "Per 1M tokens" })] }), _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: onChange, className: "flex flex-col divide-y divide-border", children: models.map((model) => (_jsx(ModelOptionRow, { model: model }, model.id))) })] })] }));
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ export { modelPriceLabel } from "./shared/model-option-row.js";
6
+ export function ModelPicker({
7
+ models,
8
+ value,
9
+ onChange,
10
+ label = "Model",
11
+ disabled = false,
12
+ className
13
+ }) {
14
+ const selected = models.find(model => model.id === value);
15
+ return /*#__PURE__*/_jsxs(DropdownMenu, {
16
+ children: [/*#__PURE__*/_jsxs(DropdownMenuTrigger, {
17
+ "data-slot": "model-picker",
18
+ "data-value": value,
19
+ disabled: disabled,
20
+ "aria-label": `${label}: ${selected?.name ?? "none selected"}`,
21
+ className: cn("group inline-flex h-7 max-w-full items-center gap-1.5 rounded-full px-2.5 text-xs outline-none transition-colors duration-150 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent motion-reduce:transition-none", className),
22
+ children: [/*#__PURE__*/_jsx("span", {
23
+ className: "truncate font-medium",
24
+ children: selected?.name ?? label
25
+ }), selected && /*#__PURE__*/_jsx("span", {
26
+ className: "truncate text-muted-foreground max-sm:hidden",
27
+ children: selected.provider
28
+ }), /*#__PURE__*/_jsx(ChevronDownIcon, {
29
+ "aria-hidden": true,
30
+ className: "size-3 shrink-0 text-muted-foreground transition-transform duration-150 group-data-[state=open]:rotate-180 motion-reduce:transition-none"
31
+ })]
32
+ }), /*#__PURE__*/_jsxs(DropdownMenuContent, {
33
+ align: "start",
34
+ sideOffset: 6,
35
+ className: "w-80 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border",
36
+ children: [/*#__PURE__*/_jsxs(DropdownMenuLabel, {
37
+ className: "eyebrow flex justify-between gap-3 border-b border-border px-3 py-2 font-normal",
38
+ children: [/*#__PURE__*/_jsx("span", {
39
+ children: label
40
+ }), /*#__PURE__*/_jsx("span", {
41
+ className: "pr-7",
42
+ children: "Per 1M tokens"
43
+ })]
44
+ }), /*#__PURE__*/_jsx(DropdownMenuRadioGroup, {
45
+ value: value,
46
+ onValueChange: onChange,
47
+ className: "flex flex-col divide-y divide-border",
48
+ children: models.map(model => /*#__PURE__*/_jsx(ModelOptionRow, {
49
+ model: model
50
+ }, model.id))
51
+ })]
52
+ })]
53
+ });
9
54
  }
@@ -1,17 +1,90 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { cn } from "@locusgraph/components";
3
2
  import { formatCount, quotaPercent } from "@locusgraph/utils";
4
3
  import { MeterBar } from "./meter-marks.js";
5
- const statusWord = { ok: "Room left", near: "Near limit", full: "Full" };
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ const statusWord = {
6
+ ok: "Room left",
7
+ near: "Near limit",
8
+ full: "Full"
9
+ };
6
10
  const statusDot = {
7
- ok: "bg-good",
8
- near: "bg-warn",
9
- full: "bg-destructive",
11
+ ok: "bg-good",
12
+ near: "bg-warn",
13
+ full: "bg-destructive"
10
14
  };
11
- function SegmentRow({ label, tokens, limitTokens, muted = false, }) {
12
- return (_jsxs("li", { className: cn("grid grid-cols-[1fr_auto_3rem] items-baseline gap-x-3 px-4 py-2 text-xs tabular-nums", muted && "text-muted-foreground"), children: [_jsx("span", { className: "truncate", children: label }), _jsx("span", { className: "font-mono", children: formatCount(tokens) }), _jsxs("span", { className: "text-right font-mono text-muted-foreground", children: [quotaPercent({ used: tokens, included: limitTokens }), "%"] })] }));
15
+ function SegmentRow({
16
+ label,
17
+ tokens,
18
+ limitTokens,
19
+ muted = false
20
+ }) {
21
+ return /*#__PURE__*/_jsxs("li", {
22
+ className: cn("grid grid-cols-[1fr_auto_3rem] items-baseline gap-x-3 px-4 py-2 text-xs tabular-nums", muted && "text-muted-foreground"),
23
+ children: [/*#__PURE__*/_jsx("span", {
24
+ className: "truncate",
25
+ children: label
26
+ }), /*#__PURE__*/_jsx("span", {
27
+ className: "font-mono",
28
+ children: formatCount(tokens)
29
+ }), /*#__PURE__*/_jsxs("span", {
30
+ className: "text-right font-mono text-muted-foreground",
31
+ children: [quotaPercent({
32
+ used: tokens,
33
+ included: limitTokens
34
+ }), "%"]
35
+ })]
36
+ });
13
37
  }
14
- export function ContextBreakdown({ label, usedTokens, limitTokens, percent, status, breakdown, }) {
15
- const freeTokens = Math.max(limitTokens - usedTokens, 0);
16
- return (_jsxs("div", { "data-slot": "context-breakdown", className: "flex flex-col", children: [_jsxs("div", { className: "eyebrow flex items-center gap-2 px-4 pt-3", children: [_jsx("span", { children: label }), _jsxs("span", { className: "ml-auto flex items-center gap-1.5", children: [_jsx("span", { "aria-hidden": true, className: cn("size-1.5 rounded-full", statusDot[status]) }), statusWord[status]] })] }), _jsxs("div", { className: "flex flex-col gap-2 px-4 pt-2 pb-3", children: [_jsxs("span", { className: "flex items-baseline gap-1.5 tabular-nums", children: [_jsxs("span", { className: "text-lg font-semibold tracking-tight", children: [percent, "%"] }), _jsxs("span", { className: "text-xs text-muted-foreground", children: [formatCount(usedTokens), " of ", formatCount(limitTokens), " tokens"] })] }), _jsx(MeterBar, { percent: percent, status: status })] }), _jsxs("ul", { className: "flex flex-col divide-y divide-border border-t border-border", children: [breakdown.map((segment) => (_jsx(SegmentRow, { label: segment.label, tokens: segment.tokens, limitTokens: limitTokens }, segment.label))), _jsx(SegmentRow, { label: "Free", tokens: freeTokens, limitTokens: limitTokens, muted: true })] })] }));
38
+ export function ContextBreakdown({
39
+ label,
40
+ usedTokens,
41
+ limitTokens,
42
+ percent,
43
+ status,
44
+ breakdown
45
+ }) {
46
+ const freeTokens = Math.max(limitTokens - usedTokens, 0);
47
+ return /*#__PURE__*/_jsxs("div", {
48
+ "data-slot": "context-breakdown",
49
+ className: "flex flex-col",
50
+ children: [/*#__PURE__*/_jsxs("div", {
51
+ className: "eyebrow flex items-center gap-2 px-4 pt-3",
52
+ children: [/*#__PURE__*/_jsx("span", {
53
+ children: label
54
+ }), /*#__PURE__*/_jsxs("span", {
55
+ className: "ml-auto flex items-center gap-1.5",
56
+ children: [/*#__PURE__*/_jsx("span", {
57
+ "aria-hidden": true,
58
+ className: cn("size-1.5 rounded-full", statusDot[status])
59
+ }), statusWord[status]]
60
+ })]
61
+ }), /*#__PURE__*/_jsxs("div", {
62
+ className: "flex flex-col gap-2 px-4 pt-2 pb-3",
63
+ children: [/*#__PURE__*/_jsxs("span", {
64
+ className: "flex items-baseline gap-1.5 tabular-nums",
65
+ children: [/*#__PURE__*/_jsxs("span", {
66
+ className: "text-lg font-semibold tracking-tight",
67
+ children: [percent, "%"]
68
+ }), /*#__PURE__*/_jsxs("span", {
69
+ className: "text-xs text-muted-foreground",
70
+ children: [formatCount(usedTokens), " of ", formatCount(limitTokens), " tokens"]
71
+ })]
72
+ }), /*#__PURE__*/_jsx(MeterBar, {
73
+ percent: percent,
74
+ status: status
75
+ })]
76
+ }), /*#__PURE__*/_jsxs("ul", {
77
+ className: "flex flex-col divide-y divide-border border-t border-border",
78
+ children: [breakdown.map(segment => /*#__PURE__*/_jsx(SegmentRow, {
79
+ label: segment.label,
80
+ tokens: segment.tokens,
81
+ limitTokens: limitTokens
82
+ }, segment.label)), /*#__PURE__*/_jsx(SegmentRow, {
83
+ label: "Free",
84
+ tokens: freeTokens,
85
+ limitTokens: limitTokens,
86
+ muted: true
87
+ })]
88
+ })]
89
+ });
17
90
  }
@@ -1,16 +1,56 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { cn } from "@locusgraph/components";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  const ringRadius = 7;
4
4
  const ringCircumference = 2 * Math.PI * ringRadius;
5
5
  const ringStroke = {
6
- ok: "stroke-primary",
7
- near: "stroke-warn",
8
- full: "stroke-destructive",
6
+ ok: "stroke-primary",
7
+ near: "stroke-warn",
8
+ full: "stroke-destructive"
9
+ };
10
+ const barFill = {
11
+ ok: "bg-primary",
12
+ near: "bg-warn",
13
+ full: "bg-destructive"
9
14
  };
10
- const barFill = { ok: "bg-primary", near: "bg-warn", full: "bg-destructive" };
11
- export function MeterRing({ percent, status }) {
12
- return (_jsxs("svg", { viewBox: "0 0 18 18", "aria-hidden": true, className: "size-3.5 shrink-0 -rotate-90", children: [_jsx("circle", { cx: "9", cy: "9", r: ringRadius, fill: "none", strokeWidth: "2.5", className: "stroke-muted-foreground/20" }), _jsx("circle", { cx: "9", cy: "9", r: ringRadius, fill: "none", strokeWidth: "2.5", strokeDasharray: ringCircumference, strokeDashoffset: ringCircumference * (1 - percent / 100), className: cn("transition-[stroke-dashoffset] duration-300 motion-reduce:transition-none", ringStroke[status]) })] }));
15
+ export function MeterRing({
16
+ percent,
17
+ status
18
+ }) {
19
+ return /*#__PURE__*/_jsxs("svg", {
20
+ viewBox: "0 0 18 18",
21
+ "aria-hidden": true,
22
+ className: "size-3.5 shrink-0 -rotate-90",
23
+ children: [/*#__PURE__*/_jsx("circle", {
24
+ cx: "9",
25
+ cy: "9",
26
+ r: ringRadius,
27
+ fill: "none",
28
+ strokeWidth: "2.5",
29
+ className: "stroke-muted-foreground/20"
30
+ }), /*#__PURE__*/_jsx("circle", {
31
+ cx: "9",
32
+ cy: "9",
33
+ r: ringRadius,
34
+ fill: "none",
35
+ strokeWidth: "2.5",
36
+ strokeDasharray: ringCircumference,
37
+ strokeDashoffset: ringCircumference * (1 - percent / 100),
38
+ className: cn("transition-[stroke-dashoffset] duration-300 motion-reduce:transition-none", ringStroke[status])
39
+ })]
40
+ });
13
41
  }
14
- export function MeterBar({ percent, status }) {
15
- return (_jsx("span", { "aria-hidden": true, className: "relative block h-1 w-full overflow-hidden bg-muted-foreground/20", children: _jsx("span", { className: cn("absolute inset-y-0 left-0 transition-[width] duration-300 motion-reduce:transition-none", barFill[status]), style: { width: `${percent}%` } }) }));
42
+ export function MeterBar({
43
+ percent,
44
+ status
45
+ }) {
46
+ return /*#__PURE__*/_jsx("span", {
47
+ "aria-hidden": true,
48
+ className: "relative block h-1 w-full overflow-hidden bg-muted-foreground/20",
49
+ children: /*#__PURE__*/_jsx("span", {
50
+ className: cn("absolute inset-y-0 left-0 transition-[width] duration-300 motion-reduce:transition-none", barFill[status]),
51
+ style: {
52
+ width: `${percent}%`
53
+ }
54
+ })
55
+ });
16
56
  }