@locusgraph/loop 0.1.0 → 0.2.0

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 +86 -15
  3. package/dist/agent/pulse/marks/bars-mark.js +46 -10
  4. package/dist/agent/pulse/marks/glyph-mark.js +56 -11
  5. package/dist/agent/pulse/marks/locus-mark.js +63 -28
  6. package/dist/agent/pulse/marks/orb-mark.js +31 -8
  7. package/dist/agent/pulse/marks/spinner-mark.js +29 -1
  8. package/dist/agent/pulse/pulse.js +150 -35
  9. package/dist/agent/pulse/use-loop-animation.js +36 -17
  10. package/dist/agent/steps/step-icon.js +110 -24
  11. package/dist/agent/steps/steps.js +235 -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 +38 -11
  15. package/dist/agent/tool/tool-status.js +51 -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 +321 -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 +250 -18
  22. package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
  23. package/dist/approval/inbox/virtual-inbox-list.js +129 -0
  24. package/dist/approval/memory/memory-choices.js +27 -22
  25. package/dist/approval/memory/memory-review.js +242 -17
  26. package/dist/approval/memory/memory-row.js +215 -19
  27. package/dist/approval/plan/plan-review.js +279 -28
  28. package/dist/approval/plan/plan-step-row.js +194 -43
  29. package/dist/approval/plan/plan-steps.js +24 -23
  30. package/dist/approval/plan/question-choices.js +158 -39
  31. package/dist/approval/plan/question.d.ts +1 -1
  32. package/dist/approval/plan/question.js +223 -26
  33. package/dist/approval/run/run-bar.js +178 -22
  34. package/dist/approval/shared/decision-line.js +1 -1
  35. package/dist/approval/shared/risk-badge.js +47 -16
  36. package/dist/approval/shared/time.js +5 -8
  37. package/dist/approval/shared/use-focus-on-mount.js +23 -6
  38. package/dist/approval/spend/raise-cap-form.js +235 -17
  39. package/dist/approval/spend/spend-gate.js +239 -21
  40. package/dist/approval/spend/spend-math.js +7 -8
  41. package/dist/approval/spend/spend-meter.js +362 -34
  42. package/dist/approval/tool/approval.js +272 -27
  43. package/dist/approval/tool/args/args-editor.js +262 -26
  44. package/dist/approval/tool/args/args-field.js +259 -19
  45. package/dist/approval/tool/args/args-validation.js +38 -47
  46. package/dist/approval/tool/deny-form.js +130 -10
  47. package/dist/approval/tool/tool-inputs.js +127 -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 +123 -47
  53. package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
  54. package/dist/chat/chat/virtual-chat-items.js +153 -0
  55. package/dist/chat/composer/composer-actions.js +151 -16
  56. package/dist/chat/composer/composer.js +330 -32
  57. package/dist/chat/composer/use-auto-grow.js +24 -9
  58. package/dist/chat/files/file-meta.js +19 -19
  59. package/dist/chat/files/files.js +316 -28
  60. package/dist/chat/reply/fenced-code.js +45 -21
  61. package/dist/chat/reply/markdown-components.js +137 -17
  62. package/dist/chat/reply/reply.js +105 -10
  63. package/dist/chat/turn/group-parts.js +43 -29
  64. package/dist/chat/turn/turn.js +238 -30
  65. package/dist/cost/context.js +321 -23
  66. package/dist/cost/cost-steps.js +220 -14
  67. package/dist/cost/cost.js +521 -27
  68. package/dist/cost/model-picker.js +181 -6
  69. package/dist/cost/shared/context-breakdown.js +299 -10
  70. package/dist/cost/shared/meter-marks.js +107 -9
  71. package/dist/cost/shared/model-option-row.js +178 -21
  72. package/dist/cost/shared/step-cost-row.js +248 -20
  73. package/dist/cost/shared/usage-totals.js +22 -18
  74. package/dist/memory/cite.js +182 -11
  75. package/dist/memory/memorized.js +217 -11
  76. package/dist/memory/recall.js +296 -17
  77. package/dist/memory/shared/host-label.js +19 -22
  78. package/dist/memory/shared/source-mark.js +39 -3
  79. package/dist/memory/sources.js +255 -13
  80. package/dist/shared/decision-summary.js +133 -14
  81. package/dist/shared/panel-empty.js +78 -3
  82. package/dist/shared/panel.js +243 -13
  83. package/dist/shared/status-dot.js +38 -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 +65 -3
  87. package/dist/thread/actions/actions.js +184 -13
  88. package/dist/thread/actions/branch-switcher.js +102 -5
  89. package/dist/thread/canvas/canvas.js +205 -5
  90. package/dist/thread/canvas/version-switcher.js +149 -8
  91. package/dist/thread/code/code.js +186 -24
  92. package/dist/thread/code/copy-code-button.js +61 -13
  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 +137 -0
  100. package/dist/thread/history/row/thread-item-menu.js +84 -0
  101. package/dist/thread/history/row/thread-title-editor.js +81 -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 +107 -0
  106. package/dist/thread/index.d.ts +1 -1
  107. package/dist/thread/starters/starters.js +92 -7
  108. package/dist/thread/use-copied.js +45 -15
  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,26 +1,244 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { c as _c } from "react/compiler-runtime";
2
2
  import { Button, Input, Label } from "@locusgraph/components";
3
3
  import { formatMicroUsd } from "@locusgraph/utils";
4
4
  import { useId, useState } from "react";
5
5
  import { dollarsToMicroUsd, microUsdToDollarsInput } from "./spend-math.js";
6
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
7
  function capError(next, capMicroUsd) {
7
- if (next === null)
8
- return "Enter an amount in dollars.";
9
- if (next <= capMicroUsd)
10
- return `The new cap must be above ${formatMicroUsd(capMicroUsd)}.`;
11
- return undefined;
8
+ if (next === null) return "Enter an amount in dollars.";
9
+ if (next <= capMicroUsd) return `The new cap must be above ${formatMicroUsd(capMicroUsd)}.`;
10
+ return undefined;
12
11
  }
13
- export function RaiseCapForm({ capMicroUsd, suggestedMicroUsd, disabled = false, onRaiseCap, }) {
14
- const inputId = useId();
15
- const [dollars, setDollars] = useState(() => microUsdToDollarsInput(suggestedMicroUsd));
16
- const [touched, setTouched] = useState(false);
12
+ export function RaiseCapForm(t0) {
13
+ const $ = _c(59);
14
+ const {
15
+ capMicroUsd,
16
+ suggestedMicroUsd,
17
+ disabled: t1,
18
+ onRaiseCap
19
+ } = t0;
20
+ const disabled = t1 === undefined ? false : t1;
21
+ const inputId = useId();
22
+ let t2;
23
+ if ($[0] !== suggestedMicroUsd) {
24
+ t2 = () => microUsdToDollarsInput(suggestedMicroUsd);
25
+ $[0] = suggestedMicroUsd;
26
+ $[1] = t2;
27
+ } else {
28
+ t2 = $[1];
29
+ }
30
+ const [dollars, setDollars] = useState(t2);
31
+ const [touched, setTouched] = useState(false);
32
+ let T0;
33
+ let t10;
34
+ let t11;
35
+ let t12;
36
+ let t13;
37
+ let t14;
38
+ let t15;
39
+ let t3;
40
+ let t4;
41
+ let t5;
42
+ let t6;
43
+ let t7;
44
+ let t8;
45
+ let t9;
46
+ let visibleError;
47
+ if ($[2] !== capMicroUsd || $[3] !== disabled || $[4] !== dollars || $[5] !== inputId || $[6] !== onRaiseCap || $[7] !== touched) {
17
48
  const next = dollarsToMicroUsd(dollars);
18
49
  const error = capError(next, capMicroUsd);
19
- const visibleError = touched ? error : undefined;
20
- return (_jsxs("form", { "data-slot": "raise-cap-form", noValidate: true, className: "flex flex-col gap-1.5 border-t pt-4", onSubmit: (event) => {
21
- event.preventDefault();
22
- setTouched(true);
23
- if (next !== null && !error)
24
- onRaiseCap(next);
25
- }, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsx(Label, { htmlFor: inputId, className: "text-xs font-normal text-muted-foreground", children: "Or raise the cap for this run" }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsxs("div", { className: "relative w-32", children: [_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-sm text-muted-foreground", children: "$" }), _jsx(Input, { id: inputId, inputMode: "decimal", className: "pl-6 tabular-nums", value: dollars, disabled: disabled, "aria-invalid": visibleError ? true : undefined, "aria-describedby": visibleError ? `${inputId}-error` : undefined, onChange: (event) => setDollars(event.target.value), onBlur: () => setTouched(true) })] }), _jsx(Button, { type: "submit", size: "sm", variant: "outline", disabled: disabled, children: next !== null && !error ? `Raise cap to ${formatMicroUsd(next)}` : "Raise cap" })] })] }), visibleError && (_jsx("p", { id: `${inputId}-error`, className: "text-right text-xs text-destructive", children: visibleError }))] }));
50
+ visibleError = touched ? error : undefined;
51
+ t12 = "raise-cap-form";
52
+ t13 = true;
53
+ t14 = "flex flex-col gap-1.5 border-t pt-4";
54
+ t15 = event => {
55
+ event.preventDefault();
56
+ setTouched(true);
57
+ if (next !== null && !error) {
58
+ onRaiseCap(next);
59
+ }
60
+ };
61
+ t10 = "flex flex-wrap items-center justify-between gap-x-4 gap-y-2";
62
+ if ($[23] !== inputId) {
63
+ t11 = /*#__PURE__*/_jsx(Label, {
64
+ htmlFor: inputId,
65
+ className: "text-xs font-normal text-muted-foreground",
66
+ children: "Or raise the cap for this run"
67
+ });
68
+ $[23] = inputId;
69
+ $[24] = t11;
70
+ } else {
71
+ t11 = $[24];
72
+ }
73
+ t8 = "flex flex-wrap items-center gap-2";
74
+ let t16;
75
+ if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
76
+ t16 = /*#__PURE__*/_jsx("span", {
77
+ "aria-hidden": true,
78
+ className: "pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-sm text-muted-foreground",
79
+ children: "$"
80
+ });
81
+ $[25] = t16;
82
+ } else {
83
+ t16 = $[25];
84
+ }
85
+ const t17 = visibleError ? true : undefined;
86
+ const t18 = visibleError ? `${inputId}-error` : undefined;
87
+ let t19;
88
+ let t20;
89
+ if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
90
+ t19 = event_0 => setDollars(event_0.target.value);
91
+ t20 = () => setTouched(true);
92
+ $[26] = t19;
93
+ $[27] = t20;
94
+ } else {
95
+ t19 = $[26];
96
+ t20 = $[27];
97
+ }
98
+ if ($[28] !== disabled || $[29] !== dollars || $[30] !== inputId || $[31] !== t17 || $[32] !== t18) {
99
+ t9 = /*#__PURE__*/_jsxs("div", {
100
+ className: "relative w-32",
101
+ children: [t16, /*#__PURE__*/_jsx(Input, {
102
+ id: inputId,
103
+ inputMode: "decimal",
104
+ className: "pl-6 tabular-nums",
105
+ value: dollars,
106
+ disabled: disabled,
107
+ "aria-invalid": t17,
108
+ "aria-describedby": t18,
109
+ onChange: t19,
110
+ onBlur: t20
111
+ })]
112
+ });
113
+ $[28] = disabled;
114
+ $[29] = dollars;
115
+ $[30] = inputId;
116
+ $[31] = t17;
117
+ $[32] = t18;
118
+ $[33] = t9;
119
+ } else {
120
+ t9 = $[33];
121
+ }
122
+ T0 = Button;
123
+ t3 = "submit";
124
+ t4 = "sm";
125
+ t5 = "outline";
126
+ t6 = disabled;
127
+ t7 = next !== null && !error ? `Raise cap to ${formatMicroUsd(next)}` : "Raise cap";
128
+ $[2] = capMicroUsd;
129
+ $[3] = disabled;
130
+ $[4] = dollars;
131
+ $[5] = inputId;
132
+ $[6] = onRaiseCap;
133
+ $[7] = touched;
134
+ $[8] = T0;
135
+ $[9] = t10;
136
+ $[10] = t11;
137
+ $[11] = t12;
138
+ $[12] = t13;
139
+ $[13] = t14;
140
+ $[14] = t15;
141
+ $[15] = t3;
142
+ $[16] = t4;
143
+ $[17] = t5;
144
+ $[18] = t6;
145
+ $[19] = t7;
146
+ $[20] = t8;
147
+ $[21] = t9;
148
+ $[22] = visibleError;
149
+ } else {
150
+ T0 = $[8];
151
+ t10 = $[9];
152
+ t11 = $[10];
153
+ t12 = $[11];
154
+ t13 = $[12];
155
+ t14 = $[13];
156
+ t15 = $[14];
157
+ t3 = $[15];
158
+ t4 = $[16];
159
+ t5 = $[17];
160
+ t6 = $[18];
161
+ t7 = $[19];
162
+ t8 = $[20];
163
+ t9 = $[21];
164
+ visibleError = $[22];
165
+ }
166
+ let t16;
167
+ if ($[34] !== T0 || $[35] !== t3 || $[36] !== t4 || $[37] !== t5 || $[38] !== t6 || $[39] !== t7) {
168
+ t16 = /*#__PURE__*/_jsx(T0, {
169
+ type: t3,
170
+ size: t4,
171
+ variant: t5,
172
+ disabled: t6,
173
+ children: t7
174
+ });
175
+ $[34] = T0;
176
+ $[35] = t3;
177
+ $[36] = t4;
178
+ $[37] = t5;
179
+ $[38] = t6;
180
+ $[39] = t7;
181
+ $[40] = t16;
182
+ } else {
183
+ t16 = $[40];
184
+ }
185
+ let t17;
186
+ if ($[41] !== t16 || $[42] !== t8 || $[43] !== t9) {
187
+ t17 = /*#__PURE__*/_jsxs("div", {
188
+ className: t8,
189
+ children: [t9, t16]
190
+ });
191
+ $[41] = t16;
192
+ $[42] = t8;
193
+ $[43] = t9;
194
+ $[44] = t17;
195
+ } else {
196
+ t17 = $[44];
197
+ }
198
+ let t18;
199
+ if ($[45] !== t10 || $[46] !== t11 || $[47] !== t17) {
200
+ t18 = /*#__PURE__*/_jsxs("div", {
201
+ className: t10,
202
+ children: [t11, t17]
203
+ });
204
+ $[45] = t10;
205
+ $[46] = t11;
206
+ $[47] = t17;
207
+ $[48] = t18;
208
+ } else {
209
+ t18 = $[48];
210
+ }
211
+ let t19;
212
+ if ($[49] !== inputId || $[50] !== visibleError) {
213
+ t19 = visibleError && /*#__PURE__*/_jsx("p", {
214
+ id: `${inputId}-error`,
215
+ className: "text-right text-xs text-destructive",
216
+ children: visibleError
217
+ });
218
+ $[49] = inputId;
219
+ $[50] = visibleError;
220
+ $[51] = t19;
221
+ } else {
222
+ t19 = $[51];
223
+ }
224
+ let t20;
225
+ if ($[52] !== t12 || $[53] !== t13 || $[54] !== t14 || $[55] !== t15 || $[56] !== t18 || $[57] !== t19) {
226
+ t20 = /*#__PURE__*/_jsxs("form", {
227
+ "data-slot": t12,
228
+ noValidate: t13,
229
+ className: t14,
230
+ onSubmit: t15,
231
+ children: [t18, t19]
232
+ });
233
+ $[52] = t12;
234
+ $[53] = t13;
235
+ $[54] = t14;
236
+ $[55] = t15;
237
+ $[56] = t18;
238
+ $[57] = t19;
239
+ $[58] = t20;
240
+ } else {
241
+ t20 = $[58];
242
+ }
243
+ return t20;
26
244
  }
@@ -1,32 +1,250 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { c as _c } from "react/compiler-runtime";
2
2
  import { CurrencyDollar as CircleDollarSignIcon } from "@carbon/icons-react";
3
3
  import { Button, cn } from "@locusgraph/components";
4
4
  import { formatMicroUsd } from "@locusgraph/utils";
5
- import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle, } from "../../shared/panel.js";
5
+ import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
6
6
  import { DecisionSummary } from "../shared/decision-line.js";
7
7
  import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
8
8
  import { RaiseCapForm } from "./raise-cap-form.js";
9
9
  import { spendSituation, suggestedCapMicroUsd } from "./spend-math.js";
10
10
  import { SpendMeter } from "./spend-meter.js";
11
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
12
  const situationCopy = {
12
- "over-cap": {
13
- title: "This run would pass its cost cap",
14
- body: (run) => `${run} paused before the next step. Allow it once, raise the cap, or stop the run.`,
15
- },
16
- "out-of-credits": {
17
- title: "Not enough credits to continue",
18
- body: (run) => `${run} paused: the next step costs more than your prepaid balance. Add credits or stop the run.`,
19
- },
13
+ "over-cap": {
14
+ title: "This run would pass its cost cap",
15
+ body: run => `${run} paused before the next step. Allow it once, raise the cap, or stop the run.`
16
+ },
17
+ "out-of-credits": {
18
+ title: "Not enough credits to continue",
19
+ body: run => `${run} paused: the next step costs more than your prepaid balance. Add credits or stop the run.`
20
+ }
20
21
  };
21
- const situationStatus = { "over-cap": "Over cap", "out-of-credits": "Out of credits" };
22
- export function SpendGate({ spentMicroUsd, estimateMicroUsd, capMicroUsd, balanceMicroUsd, runName, decision, onAllowOnce, onRaiseCap, onStop, onBuyCredits, autoFocus = true, className, }) {
23
- const situation = spendSituation(balanceMicroUsd, estimateMicroUsd);
24
- const outOfCredits = situation === "out-of-credits";
25
- const projected = spentMicroUsd + estimateMicroUsd;
26
- const copy = situationCopy[situation];
27
- const primaryRef = useFocusOnMount(autoFocus && !decision);
28
- const meter = { spentMicroUsd, estimateMicroUsd, capMicroUsd, balanceMicroUsd, outOfCredits };
29
- return (_jsxs(ApprovalPanel, { "data-slot": "spend-gate", "data-situation": situation, "aria-label": copy.title, className: cn(!decision && outOfCredits && "ring-destructive/60", className), children: [_jsx(PanelHeader, { icon: _jsx(CircleDollarSignIcon, { "aria-hidden": true }), eyebrow: "Spend approval", status: decision ? (decision.approved ? "Allowed" : "Stopped") : situationStatus[situation], tone: decision ? (decision.approved ? "done" : "danger") : outOfCredits ? "danger" : "waiting" }), _jsx(PanelTitle, { className: cn(decision && "text-muted-foreground"), children: copy.title }), decision ? (_jsxs(PanelBody, { className: "pt-3", children: [_jsx(DecisionSummary, { decision: decision, approvedVerb: "Allowed", deniedVerb: "Stopped", result: decision.approved
30
- ? `Allowed ${formatMicroUsd(estimateMicroUsd)} once`
31
- : `${runName ?? "The run"} stopped` }), _jsx(SpendMeter, { ...meter, muted: true })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "px-5 pt-1 text-sm text-muted-foreground", children: copy.body(runName ?? "The agent") }), _jsxs(PanelBody, { className: "gap-5", children: [_jsxs("div", { className: "flex flex-col gap-0.5", children: [_jsx("p", { className: "text-2xl font-semibold tracking-tight tabular-nums", children: formatMicroUsd(estimateMicroUsd) }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["Next step, estimated. The run would reach", " ", _jsx("span", { className: "tabular-nums", children: formatMicroUsd(projected) }), "."] })] }), _jsx(SpendMeter, { ...meter }), !outOfCredits && (_jsx(RaiseCapForm, { capMicroUsd: capMicroUsd, suggestedMicroUsd: suggestedCapMicroUsd(projected, capMicroUsd), onRaiseCap: onRaiseCap }))] }), _jsxs(PanelFooter, { className: "justify-between", children: [_jsx("span", { className: "hidden font-mono text-[11px] text-muted-foreground sm:inline", children: "The run is paused" }), _jsxs("span", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { ref: outOfCredits && !onBuyCredits ? primaryRef : undefined, type: "button", size: "sm", variant: outOfCredits && !onBuyCredits ? "destructive" : "ghost", onClick: onStop, children: "Stop the run" }), outOfCredits ? (onBuyCredits && (_jsx(Button, { ref: primaryRef, type: "button", size: "sm", onClick: onBuyCredits, children: "Buy credits" }))) : (_jsxs(Button, { ref: primaryRef, type: "button", size: "sm", onClick: onAllowOnce, children: ["Allow ", formatMicroUsd(estimateMicroUsd), " once"] }))] })] })] })), _jsx(LiveStatus, { message: decision ? (decision.approved ? "Spend allowed" : "Run stopped") : copy.title })] }));
22
+ const situationStatus = {
23
+ "over-cap": "Over cap",
24
+ "out-of-credits": "Out of credits"
25
+ };
26
+ export function SpendGate(t0) {
27
+ const $ = _c(45);
28
+ const {
29
+ spentMicroUsd,
30
+ estimateMicroUsd,
31
+ capMicroUsd,
32
+ balanceMicroUsd,
33
+ runName,
34
+ decision,
35
+ onAllowOnce,
36
+ onRaiseCap,
37
+ onStop,
38
+ onBuyCredits,
39
+ autoFocus: t1,
40
+ className
41
+ } = t0;
42
+ const autoFocus = t1 === undefined ? true : t1;
43
+ let t2;
44
+ if ($[0] !== balanceMicroUsd || $[1] !== estimateMicroUsd) {
45
+ t2 = spendSituation(balanceMicroUsd, estimateMicroUsd);
46
+ $[0] = balanceMicroUsd;
47
+ $[1] = estimateMicroUsd;
48
+ $[2] = t2;
49
+ } else {
50
+ t2 = $[2];
51
+ }
52
+ const situation = t2;
53
+ const outOfCredits = situation === "out-of-credits";
54
+ const projected = spentMicroUsd + estimateMicroUsd;
55
+ const copy = situationCopy[situation];
56
+ const primaryRef = useFocusOnMount(autoFocus && !decision);
57
+ let t3;
58
+ if ($[3] !== balanceMicroUsd || $[4] !== capMicroUsd || $[5] !== estimateMicroUsd || $[6] !== outOfCredits || $[7] !== spentMicroUsd) {
59
+ t3 = {
60
+ spentMicroUsd,
61
+ estimateMicroUsd,
62
+ capMicroUsd,
63
+ balanceMicroUsd,
64
+ outOfCredits
65
+ };
66
+ $[3] = balanceMicroUsd;
67
+ $[4] = capMicroUsd;
68
+ $[5] = estimateMicroUsd;
69
+ $[6] = outOfCredits;
70
+ $[7] = spentMicroUsd;
71
+ $[8] = t3;
72
+ } else {
73
+ t3 = $[8];
74
+ }
75
+ const meter = t3;
76
+ const t4 = copy.title;
77
+ const t5 = !decision && outOfCredits && "ring-destructive/60";
78
+ let t6;
79
+ if ($[9] !== className || $[10] !== t5) {
80
+ t6 = cn(t5, className);
81
+ $[9] = className;
82
+ $[10] = t5;
83
+ $[11] = t6;
84
+ } else {
85
+ t6 = $[11];
86
+ }
87
+ let t7;
88
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
89
+ t7 = /*#__PURE__*/_jsx(CircleDollarSignIcon, {
90
+ "aria-hidden": true
91
+ });
92
+ $[12] = t7;
93
+ } else {
94
+ t7 = $[12];
95
+ }
96
+ const t8 = decision ? decision.approved ? "Allowed" : "Stopped" : situationStatus[situation];
97
+ const t9 = decision ? decision.approved ? "done" : "danger" : outOfCredits ? "danger" : "waiting";
98
+ let t10;
99
+ if ($[13] !== t8 || $[14] !== t9) {
100
+ t10 = /*#__PURE__*/_jsx(PanelHeader, {
101
+ icon: t7,
102
+ eyebrow: "Spend approval",
103
+ status: t8,
104
+ tone: t9
105
+ });
106
+ $[13] = t8;
107
+ $[14] = t9;
108
+ $[15] = t10;
109
+ } else {
110
+ t10 = $[15];
111
+ }
112
+ const t11 = decision && "text-muted-foreground";
113
+ let t12;
114
+ if ($[16] !== t11) {
115
+ t12 = cn(t11);
116
+ $[16] = t11;
117
+ $[17] = t12;
118
+ } else {
119
+ t12 = $[17];
120
+ }
121
+ let t13;
122
+ if ($[18] !== copy.title || $[19] !== t12) {
123
+ t13 = /*#__PURE__*/_jsx(PanelTitle, {
124
+ className: t12,
125
+ children: copy.title
126
+ });
127
+ $[18] = copy.title;
128
+ $[19] = t12;
129
+ $[20] = t13;
130
+ } else {
131
+ t13 = $[20];
132
+ }
133
+ let t14;
134
+ if ($[21] !== capMicroUsd || $[22] !== copy || $[23] !== decision || $[24] !== estimateMicroUsd || $[25] !== meter || $[26] !== onAllowOnce || $[27] !== onBuyCredits || $[28] !== onRaiseCap || $[29] !== onStop || $[30] !== outOfCredits || $[31] !== primaryRef || $[32] !== projected || $[33] !== runName) {
135
+ t14 = decision ? /*#__PURE__*/_jsxs(PanelBody, {
136
+ className: "pt-3",
137
+ children: [/*#__PURE__*/_jsx(DecisionSummary, {
138
+ decision: decision,
139
+ approvedVerb: "Allowed",
140
+ deniedVerb: "Stopped",
141
+ result: decision.approved ? `Allowed ${formatMicroUsd(estimateMicroUsd)} once` : `${runName ?? "The run"} stopped`
142
+ }), /*#__PURE__*/_jsx(SpendMeter, {
143
+ ...meter,
144
+ muted: true
145
+ })]
146
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
147
+ children: [/*#__PURE__*/_jsx("p", {
148
+ className: "px-5 pt-1 text-sm text-muted-foreground",
149
+ children: copy.body(runName ?? "The agent")
150
+ }), /*#__PURE__*/_jsxs(PanelBody, {
151
+ className: "gap-5",
152
+ children: [/*#__PURE__*/_jsxs("div", {
153
+ className: "flex flex-col gap-0.5",
154
+ children: [/*#__PURE__*/_jsx("p", {
155
+ className: "text-2xl font-semibold tracking-tight tabular-nums",
156
+ children: formatMicroUsd(estimateMicroUsd)
157
+ }), /*#__PURE__*/_jsxs("p", {
158
+ className: "text-xs text-muted-foreground",
159
+ children: ["Next step, estimated. The run would reach", " ", /*#__PURE__*/_jsx("span", {
160
+ className: "tabular-nums",
161
+ children: formatMicroUsd(projected)
162
+ }), "."]
163
+ })]
164
+ }), /*#__PURE__*/_jsx(SpendMeter, {
165
+ ...meter
166
+ }), !outOfCredits && /*#__PURE__*/_jsx(RaiseCapForm, {
167
+ capMicroUsd: capMicroUsd,
168
+ suggestedMicroUsd: suggestedCapMicroUsd(projected, capMicroUsd),
169
+ onRaiseCap: onRaiseCap
170
+ })]
171
+ }), /*#__PURE__*/_jsxs(PanelFooter, {
172
+ className: "justify-between",
173
+ children: [/*#__PURE__*/_jsx("span", {
174
+ className: "hidden font-mono text-[11px] text-muted-foreground sm:inline",
175
+ children: "The run is paused"
176
+ }), /*#__PURE__*/_jsxs("span", {
177
+ className: "flex flex-wrap gap-2",
178
+ children: [/*#__PURE__*/_jsx(Button, {
179
+ ref: outOfCredits && !onBuyCredits ? primaryRef : undefined,
180
+ type: "button",
181
+ size: "sm",
182
+ variant: outOfCredits && !onBuyCredits ? "destructive" : "ghost",
183
+ onClick: onStop,
184
+ children: "Stop the run"
185
+ }), outOfCredits ? onBuyCredits && /*#__PURE__*/_jsx(Button, {
186
+ ref: primaryRef,
187
+ type: "button",
188
+ size: "sm",
189
+ onClick: onBuyCredits,
190
+ children: "Buy credits"
191
+ }) : /*#__PURE__*/_jsxs(Button, {
192
+ ref: primaryRef,
193
+ type: "button",
194
+ size: "sm",
195
+ onClick: onAllowOnce,
196
+ children: ["Allow ", formatMicroUsd(estimateMicroUsd), " once"]
197
+ })]
198
+ })]
199
+ })]
200
+ });
201
+ $[21] = capMicroUsd;
202
+ $[22] = copy;
203
+ $[23] = decision;
204
+ $[24] = estimateMicroUsd;
205
+ $[25] = meter;
206
+ $[26] = onAllowOnce;
207
+ $[27] = onBuyCredits;
208
+ $[28] = onRaiseCap;
209
+ $[29] = onStop;
210
+ $[30] = outOfCredits;
211
+ $[31] = primaryRef;
212
+ $[32] = projected;
213
+ $[33] = runName;
214
+ $[34] = t14;
215
+ } else {
216
+ t14 = $[34];
217
+ }
218
+ const t15 = decision ? decision.approved ? "Spend allowed" : "Run stopped" : copy.title;
219
+ let t16;
220
+ if ($[35] !== t15) {
221
+ t16 = /*#__PURE__*/_jsx(LiveStatus, {
222
+ message: t15
223
+ });
224
+ $[35] = t15;
225
+ $[36] = t16;
226
+ } else {
227
+ t16 = $[36];
228
+ }
229
+ let t17;
230
+ if ($[37] !== copy.title || $[38] !== situation || $[39] !== t10 || $[40] !== t13 || $[41] !== t14 || $[42] !== t16 || $[43] !== t6) {
231
+ t17 = /*#__PURE__*/_jsxs(ApprovalPanel, {
232
+ "data-slot": "spend-gate",
233
+ "data-situation": situation,
234
+ "aria-label": t4,
235
+ className: t6,
236
+ children: [t10, t13, t14, t16]
237
+ });
238
+ $[37] = copy.title;
239
+ $[38] = situation;
240
+ $[39] = t10;
241
+ $[40] = t13;
242
+ $[41] = t14;
243
+ $[42] = t16;
244
+ $[43] = t6;
245
+ $[44] = t17;
246
+ } else {
247
+ t17 = $[44];
248
+ }
249
+ return t17;
32
250
  }
@@ -1,18 +1,17 @@
1
1
  const microUsdPerDollar = 1_000_000;
2
2
  const microUsdPerCent = 10_000;
3
3
  export function spendSituation(balanceMicroUsd, estimateMicroUsd) {
4
- return balanceMicroUsd <= 0 || balanceMicroUsd < estimateMicroUsd ? "out-of-credits" : "over-cap";
4
+ return balanceMicroUsd <= 0 || balanceMicroUsd < estimateMicroUsd ? "out-of-credits" : "over-cap";
5
5
  }
6
6
  export function suggestedCapMicroUsd(projectedMicroUsd, capMicroUsd) {
7
- const target = Math.max(projectedMicroUsd, capMicroUsd + microUsdPerCent);
8
- return Math.ceil(target / microUsdPerDollar) * microUsdPerDollar;
7
+ const target = Math.max(projectedMicroUsd, capMicroUsd + microUsdPerCent);
8
+ return Math.ceil(target / microUsdPerDollar) * microUsdPerDollar;
9
9
  }
10
10
  export function dollarsToMicroUsd(dollars) {
11
- const value = Number(dollars.trim());
12
- if (dollars.trim() === "" || !Number.isFinite(value))
13
- return null;
14
- return Math.round(value * microUsdPerDollar);
11
+ const value = Number(dollars.trim());
12
+ if (dollars.trim() === "" || !Number.isFinite(value)) return null;
13
+ return Math.round(value * microUsdPerDollar);
15
14
  }
16
15
  export function microUsdToDollarsInput(microUsd) {
17
- return (microUsd / microUsdPerDollar).toFixed(2);
16
+ return (microUsd / microUsdPerDollar).toFixed(2);
18
17
  }