@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.
- package/README.md +2 -0
- package/dist/agent/pulse/gradient-label.js +36 -15
- package/dist/agent/pulse/marks/bars-mark.js +24 -10
- package/dist/agent/pulse/marks/glyph-mark.js +17 -11
- package/dist/agent/pulse/marks/locus-mark.js +39 -28
- package/dist/agent/pulse/marks/orb-mark.js +21 -8
- package/dist/agent/pulse/marks/spinner-mark.js +20 -1
- package/dist/agent/pulse/pulse.js +63 -35
- package/dist/agent/pulse/use-loop-animation.js +14 -16
- package/dist/agent/steps/step-icon.js +40 -24
- package/dist/agent/steps/steps.js +72 -25
- package/dist/agent/thinking/thinking.js +203 -23
- package/dist/agent/thinking/thought-duration.js +7 -9
- package/dist/agent/tool/json-block.js +18 -11
- package/dist/agent/tool/tool-status.js +28 -18
- package/dist/agent/tool/tool.js +184 -6
- package/dist/approval/inbox/inbox-row.d.ts +3 -2
- package/dist/approval/inbox/inbox-row.js +96 -7
- package/dist/approval/inbox/inbox-selection.js +7 -13
- package/dist/approval/inbox/inbox.d.ts +2 -1
- package/dist/approval/inbox/inbox.js +99 -18
- package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
- package/dist/approval/inbox/virtual-inbox-list.js +53 -0
- package/dist/approval/memory/memory-choices.js +27 -22
- package/dist/approval/memory/memory-review.js +108 -17
- package/dist/approval/memory/memory-row.js +80 -19
- package/dist/approval/plan/plan-review.js +129 -28
- package/dist/approval/plan/plan-step-row.js +91 -44
- package/dist/approval/plan/plan-steps.js +24 -23
- package/dist/approval/plan/question-choices.js +73 -40
- package/dist/approval/plan/question.d.ts +1 -1
- package/dist/approval/plan/question.js +108 -27
- package/dist/approval/run/run-bar.js +94 -22
- package/dist/approval/shared/decision-line.js +1 -1
- package/dist/approval/shared/risk-badge.js +32 -16
- package/dist/approval/shared/time.js +5 -8
- package/dist/approval/shared/use-focus-on-mount.js +7 -6
- package/dist/approval/spend/raise-cap-form.js +64 -19
- package/dist/approval/spend/spend-gate.js +124 -21
- package/dist/approval/spend/spend-math.js +7 -8
- package/dist/approval/spend/spend-meter.js +136 -35
- package/dist/approval/tool/approval.js +113 -27
- package/dist/approval/tool/args/args-editor.js +104 -26
- package/dist/approval/tool/args/args-field.js +79 -22
- package/dist/approval/tool/args/args-validation.js +38 -47
- package/dist/approval/tool/deny-form.js +43 -10
- package/dist/approval/tool/tool-inputs.js +62 -38
- package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
- package/dist/chat/chat/chat-item-spacing.js +19 -0
- package/dist/chat/chat/chat.d.ts +2 -1
- package/dist/chat/chat/chat.js +181 -5
- package/dist/chat/chat/use-stick-to-bottom.js +71 -48
- package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
- package/dist/chat/chat/virtual-chat-items.js +60 -0
- package/dist/chat/composer/composer-actions.js +69 -17
- package/dist/chat/composer/composer.js +330 -32
- package/dist/chat/composer/use-auto-grow.js +9 -9
- package/dist/chat/files/file-meta.js +19 -19
- package/dist/chat/files/files.js +92 -29
- package/dist/chat/reply/fenced-code.js +23 -21
- package/dist/chat/reply/markdown-components.js +137 -17
- package/dist/chat/reply/reply.js +30 -10
- package/dist/chat/turn/group-parts.js +43 -29
- package/dist/chat/turn/turn.js +87 -30
- package/dist/cost/context.js +104 -23
- package/dist/cost/cost-steps.js +67 -14
- package/dist/cost/cost.js +128 -23
- package/dist/cost/model-picker.js +51 -6
- package/dist/cost/shared/context-breakdown.js +83 -10
- package/dist/cost/shared/meter-marks.js +49 -9
- package/dist/cost/shared/model-option-row.js +56 -22
- package/dist/cost/shared/step-cost-row.js +65 -22
- package/dist/cost/shared/usage-totals.js +22 -18
- package/dist/memory/cite.js +62 -12
- package/dist/memory/memorized.js +65 -11
- package/dist/memory/recall.js +101 -17
- package/dist/memory/shared/host-label.js +19 -22
- package/dist/memory/shared/source-mark.js +11 -3
- package/dist/memory/sources.js +78 -14
- package/dist/shared/decision-summary.js +51 -14
- package/dist/shared/panel-empty.js +20 -3
- package/dist/shared/panel.js +69 -13
- package/dist/shared/status-dot.js +16 -8
- package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
- package/dist/shared/virtual/use-list-virtualizer.js +68 -0
- package/dist/thread/actions/action-button.js +22 -3
- package/dist/thread/actions/actions.js +184 -13
- package/dist/thread/actions/branch-switcher.js +28 -5
- package/dist/thread/canvas/canvas.js +205 -5
- package/dist/thread/canvas/version-switcher.js +54 -8
- package/dist/thread/code/code.js +186 -24
- package/dist/thread/code/copy-code-button.js +30 -14
- package/dist/thread/code/highlight.js +30 -29
- package/dist/thread/history/history-rows.d.ts +16 -0
- package/dist/thread/history/history-rows.js +23 -0
- package/dist/thread/history/history.d.ts +3 -2
- package/dist/thread/history/history.js +174 -5
- package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
- package/dist/thread/history/row/history-row.js +58 -0
- package/dist/thread/history/row/thread-item-menu.js +31 -0
- package/dist/thread/history/row/thread-title-editor.js +38 -0
- package/dist/thread/history/thread-groups.d.ts +1 -1
- package/dist/thread/history/thread-groups.js +40 -34
- package/dist/thread/history/virtual-history-list.d.ts +11 -0
- package/dist/thread/history/virtual-history-list.js +71 -0
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/starters/starters.js +33 -8
- package/dist/thread/use-copied.js +18 -16
- package/dist/types.js +1 -1
- package/package.json +6 -4
- package/dist/thread/history/history-row.js +0 -17
- package/dist/thread/history/thread-item-menu.js +0 -6
- package/dist/thread/history/thread-title-editor.js +0 -25
- /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
- /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
|
@@ -1,35 +1,116 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArrowRight as ArrowRightIcon, Help as MessageCircleQuestionIcon, } from "@carbon/icons-react";
|
|
1
|
+
import { ArrowRight as ArrowRightIcon, Help as MessageCircleQuestionIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, Input, Textarea } from "@locusgraph/components";
|
|
4
3
|
import { useId, useState } from "react";
|
|
5
|
-
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle
|
|
4
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
|
|
6
5
|
import { DecisionSummary } from "../shared/decision-line.js";
|
|
7
6
|
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
8
7
|
import { QuestionChoices } from "./question-choices.js";
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
9
|
function answerText(answer, options) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const option = options.find(item => item.id === answer.optionId);
|
|
11
|
+
return [option?.label, answer.text].filter(Boolean).join(" · ");
|
|
12
12
|
}
|
|
13
|
-
export function Question({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
export function Question({
|
|
14
|
+
question,
|
|
15
|
+
options = [],
|
|
16
|
+
allowText: allowTextProp,
|
|
17
|
+
textLabel: textLabelProp,
|
|
18
|
+
textPlaceholder: textPlaceholderProp,
|
|
19
|
+
submitLabel = "Send answer",
|
|
20
|
+
answer,
|
|
21
|
+
onAnswer,
|
|
22
|
+
autoFocus = true,
|
|
23
|
+
className
|
|
24
|
+
}) {
|
|
25
|
+
const hasOptions = options.length > 0;
|
|
26
|
+
const allowText = allowTextProp ?? !hasOptions;
|
|
27
|
+
const textLabel = textLabelProp ?? (hasOptions ? "Something else" : "Your answer");
|
|
28
|
+
const textPlaceholder = textPlaceholderProp ?? (hasOptions ? "Something else…" : "Type an answer for the agent");
|
|
29
|
+
const textId = useId();
|
|
30
|
+
const [optionId, setOptionId] = useState();
|
|
31
|
+
const [text, setText] = useState("");
|
|
32
|
+
const trimmed = text.trim();
|
|
33
|
+
const canSubmit = optionId !== undefined || trimmed !== "";
|
|
34
|
+
const textOnly = options.length === 0;
|
|
35
|
+
const textRef = useFocusOnMount(autoFocus && !answer && textOnly);
|
|
36
|
+
const changeText = value => {
|
|
37
|
+
setText(value);
|
|
38
|
+
if (value.trim() !== "") setOptionId(undefined);
|
|
39
|
+
};
|
|
40
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
41
|
+
"data-slot": "question",
|
|
42
|
+
"data-answered": answer ? true : undefined,
|
|
43
|
+
className: className,
|
|
44
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
45
|
+
icon: /*#__PURE__*/_jsx(MessageCircleQuestionIcon, {
|
|
46
|
+
"aria-hidden": true
|
|
47
|
+
}),
|
|
48
|
+
eyebrow: "Agent question",
|
|
49
|
+
status: answer ? "Answered" : "Waiting for you",
|
|
50
|
+
tone: answer ? "done" : "waiting"
|
|
51
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
52
|
+
className: answer ? "text-muted-foreground" : undefined,
|
|
53
|
+
children: question
|
|
54
|
+
}), answer ? /*#__PURE__*/_jsx(PanelBody, {
|
|
55
|
+
children: /*#__PURE__*/_jsx(DecisionSummary, {
|
|
56
|
+
decision: {
|
|
57
|
+
approved: true,
|
|
58
|
+
by: answer.by,
|
|
59
|
+
at: answer.at
|
|
60
|
+
},
|
|
61
|
+
approvedVerb: "Answered",
|
|
62
|
+
result: answerText(answer, options) || "No answer"
|
|
63
|
+
})
|
|
64
|
+
}) : /*#__PURE__*/_jsxs("form", {
|
|
65
|
+
onSubmit: event => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
if (!canSubmit) return;
|
|
68
|
+
onAnswer({
|
|
69
|
+
optionId,
|
|
70
|
+
text: trimmed === "" ? undefined : trimmed
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
children: [/*#__PURE__*/_jsxs(PanelBody, {
|
|
74
|
+
className: "gap-3",
|
|
75
|
+
children: [!textOnly && /*#__PURE__*/_jsx(QuestionChoices, {
|
|
76
|
+
label: question,
|
|
77
|
+
options: options,
|
|
78
|
+
selectedId: optionId,
|
|
79
|
+
onSelect: id => {
|
|
80
|
+
setOptionId(id);
|
|
81
|
+
setText("");
|
|
82
|
+
},
|
|
83
|
+
autoFocus: autoFocus
|
|
84
|
+
}), allowText && !textOnly && /*#__PURE__*/_jsx(Input, {
|
|
85
|
+
id: textId,
|
|
86
|
+
"aria-label": textLabel,
|
|
87
|
+
value: text,
|
|
88
|
+
placeholder: textPlaceholder,
|
|
89
|
+
onChange: event => changeText(event.target.value)
|
|
90
|
+
}), textOnly && /*#__PURE__*/_jsx(Textarea, {
|
|
91
|
+
id: textId,
|
|
92
|
+
ref: textRef,
|
|
93
|
+
"aria-label": textLabel,
|
|
94
|
+
value: text,
|
|
95
|
+
placeholder: textPlaceholder,
|
|
96
|
+
onChange: event => changeText(event.target.value)
|
|
97
|
+
})]
|
|
98
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
99
|
+
className: "justify-between",
|
|
100
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
101
|
+
className: "hidden font-mono text-[11px] text-muted-foreground sm:inline",
|
|
102
|
+
children: textOnly ? "The run is paused" : `Press 1–${options.length} to pick`
|
|
103
|
+
}), /*#__PURE__*/_jsxs(Button, {
|
|
104
|
+
type: "submit",
|
|
105
|
+
size: "sm",
|
|
106
|
+
disabled: !canSubmit,
|
|
107
|
+
children: [submitLabel, /*#__PURE__*/_jsx(ArrowRightIcon, {
|
|
108
|
+
"aria-hidden": true
|
|
109
|
+
})]
|
|
110
|
+
})]
|
|
111
|
+
})]
|
|
112
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
113
|
+
message: answer ? `Answered: ${answerText(answer, options)}` : `The agent asks: ${question}`
|
|
114
|
+
})]
|
|
115
|
+
});
|
|
35
116
|
}
|
|
@@ -1,33 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Pause as PauseIcon, Play as PlayIcon, SkipForward as SkipForwardIcon, StopFilledAlt as SquareIcon, } from "@carbon/icons-react";
|
|
1
|
+
import { Pause as PauseIcon, Play as PlayIcon, SkipForward as SkipForwardIcon, StopFilledAlt as SquareIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, cn } from "@locusgraph/components";
|
|
4
3
|
import { StatusDot } from "../../shared/status-dot.js";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
const statusLabels = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
running: "Running",
|
|
7
|
+
paused: "Paused",
|
|
8
|
+
stopped: "Stopped",
|
|
9
|
+
done: "Done"
|
|
10
10
|
};
|
|
11
11
|
const statusTone = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
running: "running",
|
|
13
|
+
paused: "waiting",
|
|
14
|
+
stopped: "danger",
|
|
15
|
+
done: "done"
|
|
16
16
|
};
|
|
17
17
|
function twoDigits(value) {
|
|
18
|
-
|
|
18
|
+
return String(value).padStart(2, "0");
|
|
19
19
|
}
|
|
20
20
|
function formatElapsed(elapsedMs) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return `${minutes}:${twoDigits(seconds)}`;
|
|
21
|
+
const totalSeconds = Math.max(0, Math.floor(elapsedMs / 1000));
|
|
22
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
23
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
24
|
+
const seconds = totalSeconds % 60;
|
|
25
|
+
if (hours > 0) return `${hours}:${twoDigits(minutes)}:${twoDigits(seconds)}`;
|
|
26
|
+
return `${minutes}:${twoDigits(seconds)}`;
|
|
28
27
|
}
|
|
29
|
-
export function RunBar({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export function RunBar({
|
|
29
|
+
status,
|
|
30
|
+
runName,
|
|
31
|
+
elapsedMs,
|
|
32
|
+
onPause,
|
|
33
|
+
onResume,
|
|
34
|
+
onStop,
|
|
35
|
+
onStep,
|
|
36
|
+
pending = false,
|
|
37
|
+
className
|
|
38
|
+
}) {
|
|
39
|
+
const live = status === "running" || status === "paused";
|
|
40
|
+
const paused = status === "paused";
|
|
41
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
42
|
+
role: "toolbar",
|
|
43
|
+
"aria-label": runName ? `Controls for ${runName}` : "Run controls",
|
|
44
|
+
"data-slot": "run-bar",
|
|
45
|
+
"data-status": status,
|
|
46
|
+
className: cn("flex min-h-10 min-w-0 flex-wrap items-center gap-x-3 gap-y-2 bg-card py-2 pr-2 pl-3 text-card-foreground ring-1 ring-border", className),
|
|
47
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
48
|
+
className: "flex min-w-0 flex-1 items-center gap-2.5 text-sm",
|
|
49
|
+
children: [/*#__PURE__*/_jsx(StatusDot, {
|
|
50
|
+
tone: statusTone[status],
|
|
51
|
+
className: "size-2"
|
|
52
|
+
}), runName && /*#__PURE__*/_jsx("span", {
|
|
53
|
+
className: "truncate font-medium",
|
|
54
|
+
children: runName
|
|
55
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
56
|
+
role: "status",
|
|
57
|
+
"aria-live": "polite",
|
|
58
|
+
className: "eyebrow shrink-0",
|
|
59
|
+
children: statusLabels[status]
|
|
60
|
+
}), elapsedMs !== undefined && /*#__PURE__*/_jsxs("span", {
|
|
61
|
+
className: "shrink-0 font-mono text-xs text-muted-foreground tabular-nums",
|
|
62
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
63
|
+
className: "sr-only",
|
|
64
|
+
children: "Elapsed "
|
|
65
|
+
}), formatElapsed(elapsedMs)]
|
|
66
|
+
})]
|
|
67
|
+
}), live && /*#__PURE__*/_jsxs("span", {
|
|
68
|
+
className: "ml-auto flex shrink-0 items-center gap-1",
|
|
69
|
+
children: [/*#__PURE__*/_jsxs(Button, {
|
|
70
|
+
type: "button",
|
|
71
|
+
size: "xs",
|
|
72
|
+
variant: paused ? "default" : "outline",
|
|
73
|
+
disabled: pending,
|
|
74
|
+
onClick: paused ? onResume : onPause,
|
|
75
|
+
children: [paused ? /*#__PURE__*/_jsx(PlayIcon, {
|
|
76
|
+
"aria-hidden": true
|
|
77
|
+
}) : /*#__PURE__*/_jsx(PauseIcon, {
|
|
78
|
+
"aria-hidden": true
|
|
79
|
+
}), paused ? "Resume" : "Pause"]
|
|
80
|
+
}), onStep && /*#__PURE__*/_jsxs(Button, {
|
|
81
|
+
type: "button",
|
|
82
|
+
size: "xs",
|
|
83
|
+
variant: "ghost",
|
|
84
|
+
"aria-label": "Run one step",
|
|
85
|
+
title: "Run one step",
|
|
86
|
+
disabled: !paused || pending,
|
|
87
|
+
onClick: onStep,
|
|
88
|
+
children: [/*#__PURE__*/_jsx(SkipForwardIcon, {
|
|
89
|
+
"aria-hidden": true
|
|
90
|
+
}), "Step"]
|
|
91
|
+
}), /*#__PURE__*/_jsxs(Button, {
|
|
92
|
+
type: "button",
|
|
93
|
+
size: "xs",
|
|
94
|
+
variant: "ghost",
|
|
95
|
+
className: "text-muted-foreground hover:bg-destructive/10 hover:text-destructive dark:hover:bg-destructive/15",
|
|
96
|
+
disabled: pending,
|
|
97
|
+
onClick: onStop,
|
|
98
|
+
children: [/*#__PURE__*/_jsx(SquareIcon, {
|
|
99
|
+
"aria-hidden": true,
|
|
100
|
+
className: "size-2.5 fill-current"
|
|
101
|
+
}), "Stop"]
|
|
102
|
+
})]
|
|
103
|
+
})]
|
|
104
|
+
});
|
|
33
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DecisionSummary
|
|
1
|
+
export { DecisionSummary } from "../../shared/decision-summary.js";
|
|
@@ -1,26 +1,42 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Badge } from "@locusgraph/components";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
export const riskLabels = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
read: "Read only",
|
|
5
|
+
write: "Writes data",
|
|
6
|
+
destructive: "Destructive"
|
|
7
7
|
};
|
|
8
8
|
export const riskRing = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
read: "ring-border",
|
|
10
|
+
write: "ring-border",
|
|
11
|
+
destructive: "ring-destructive/60"
|
|
12
12
|
};
|
|
13
13
|
export const riskTone = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
read: "idle",
|
|
15
|
+
write: "waiting",
|
|
16
|
+
destructive: "danger"
|
|
17
17
|
};
|
|
18
18
|
export const riskCopy = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
read: tool => `${tool} only reads data. Nothing changes if you approve.`,
|
|
20
|
+
write: tool => `${tool} wants to make a change. Check the inputs before you approve.`,
|
|
21
|
+
destructive: tool => /*#__PURE__*/_jsxs(_Fragment, {
|
|
22
|
+
children: [tool, " will permanently delete or overwrite data.", " ", /*#__PURE__*/_jsx("span", {
|
|
23
|
+
className: "font-medium text-destructive",
|
|
24
|
+
children: "This can't be undone."
|
|
25
|
+
})]
|
|
26
|
+
})
|
|
22
27
|
};
|
|
23
|
-
const riskVariant = {
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
const riskVariant = {
|
|
29
|
+
read: "outline",
|
|
30
|
+
write: "secondary",
|
|
31
|
+
destructive: "destructive"
|
|
32
|
+
};
|
|
33
|
+
export function RiskBadge({
|
|
34
|
+
risk
|
|
35
|
+
}) {
|
|
36
|
+
return /*#__PURE__*/_jsx(Badge, {
|
|
37
|
+
"data-slot": "risk-badge",
|
|
38
|
+
"data-risk": risk,
|
|
39
|
+
variant: riskVariant[risk],
|
|
40
|
+
children: riskLabels[risk]
|
|
41
|
+
});
|
|
26
42
|
}
|
|
@@ -4,12 +4,9 @@ const minuteMs = 60_000;
|
|
|
4
4
|
const hourMs = 60 * minuteMs;
|
|
5
5
|
const dayMs = 24 * hourMs;
|
|
6
6
|
export function formatWaiting(since, now) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (waitedMs < dayMs)
|
|
13
|
-
return `${Math.floor(waitedMs / hourMs)} h`;
|
|
14
|
-
return `${Math.floor(waitedMs / dayMs)} d`;
|
|
7
|
+
const waitedMs = Math.max(0, now - toDate(since).getTime());
|
|
8
|
+
if (waitedMs < minuteMs) return "just now";
|
|
9
|
+
if (waitedMs < hourMs) return `${Math.floor(waitedMs / minuteMs)} min`;
|
|
10
|
+
if (waitedMs < dayMs) return `${Math.floor(waitedMs / hourMs)} h`;
|
|
11
|
+
return `${Math.floor(waitedMs / dayMs)} d`;
|
|
15
12
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
export function useFocusOnMount(enabled) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
3
|
+
const ref = useRef(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (enabled) ref.current?.focus({
|
|
6
|
+
preventScroll: true
|
|
7
|
+
});
|
|
8
|
+
}, [enabled]);
|
|
9
|
+
return ref;
|
|
9
10
|
}
|
|
@@ -1,26 +1,71 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Button, Input, Label } from "@locusgraph/components";
|
|
3
2
|
import { formatMicroUsd } from "@locusgraph/utils";
|
|
4
3
|
import { useId, useState } from "react";
|
|
5
4
|
import { dollarsToMicroUsd, microUsdToDollarsInput } from "./spend-math.js";
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
function capError(next, capMicroUsd) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return `The new cap must be above ${formatMicroUsd(capMicroUsd)}.`;
|
|
11
|
-
return undefined;
|
|
7
|
+
if (next === null) return "Enter an amount in dollars.";
|
|
8
|
+
if (next <= capMicroUsd) return `The new cap must be above ${formatMicroUsd(capMicroUsd)}.`;
|
|
9
|
+
return undefined;
|
|
12
10
|
}
|
|
13
|
-
export function RaiseCapForm({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
export function RaiseCapForm({
|
|
12
|
+
capMicroUsd,
|
|
13
|
+
suggestedMicroUsd,
|
|
14
|
+
disabled = false,
|
|
15
|
+
onRaiseCap
|
|
16
|
+
}) {
|
|
17
|
+
const inputId = useId();
|
|
18
|
+
const [dollars, setDollars] = useState(() => microUsdToDollarsInput(suggestedMicroUsd));
|
|
19
|
+
const [touched, setTouched] = useState(false);
|
|
20
|
+
const next = dollarsToMicroUsd(dollars);
|
|
21
|
+
const error = capError(next, capMicroUsd);
|
|
22
|
+
const visibleError = touched ? error : undefined;
|
|
23
|
+
return /*#__PURE__*/_jsxs("form", {
|
|
24
|
+
"data-slot": "raise-cap-form",
|
|
25
|
+
noValidate: true,
|
|
26
|
+
className: "flex flex-col gap-1.5 border-t pt-4",
|
|
27
|
+
onSubmit: event => {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
setTouched(true);
|
|
30
|
+
if (next !== null && !error) onRaiseCap(next);
|
|
31
|
+
},
|
|
32
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
33
|
+
className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2",
|
|
34
|
+
children: [/*#__PURE__*/_jsx(Label, {
|
|
35
|
+
htmlFor: inputId,
|
|
36
|
+
className: "text-xs font-normal text-muted-foreground",
|
|
37
|
+
children: "Or raise the cap for this run"
|
|
38
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
39
|
+
className: "flex flex-wrap items-center gap-2",
|
|
40
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
41
|
+
className: "relative w-32",
|
|
42
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
43
|
+
"aria-hidden": true,
|
|
44
|
+
className: "pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-sm text-muted-foreground",
|
|
45
|
+
children: "$"
|
|
46
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
47
|
+
id: inputId,
|
|
48
|
+
inputMode: "decimal",
|
|
49
|
+
className: "pl-6 tabular-nums",
|
|
50
|
+
value: dollars,
|
|
51
|
+
disabled: disabled,
|
|
52
|
+
"aria-invalid": visibleError ? true : undefined,
|
|
53
|
+
"aria-describedby": visibleError ? `${inputId}-error` : undefined,
|
|
54
|
+
onChange: event => setDollars(event.target.value),
|
|
55
|
+
onBlur: () => setTouched(true)
|
|
56
|
+
})]
|
|
57
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
58
|
+
type: "submit",
|
|
59
|
+
size: "sm",
|
|
60
|
+
variant: "outline",
|
|
61
|
+
disabled: disabled,
|
|
62
|
+
children: next !== null && !error ? `Raise cap to ${formatMicroUsd(next)}` : "Raise cap"
|
|
63
|
+
})]
|
|
64
|
+
})]
|
|
65
|
+
}), visibleError && /*#__PURE__*/_jsx("p", {
|
|
66
|
+
id: `${inputId}-error`,
|
|
67
|
+
className: "text-right text-xs text-destructive",
|
|
68
|
+
children: visibleError
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
26
71
|
}
|
|
@@ -1,32 +1,135 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { CurrencyDollar as CircleDollarSignIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, cn } from "@locusgraph/components";
|
|
4
3
|
import { formatMicroUsd } from "@locusgraph/utils";
|
|
5
|
-
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle
|
|
4
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
|
|
6
5
|
import { DecisionSummary } from "../shared/decision-line.js";
|
|
7
6
|
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
8
7
|
import { RaiseCapForm } from "./raise-cap-form.js";
|
|
9
8
|
import { spendSituation, suggestedCapMicroUsd } from "./spend-math.js";
|
|
10
9
|
import { SpendMeter } from "./spend-meter.js";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
11
|
const situationCopy = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}
|
|
20
20
|
};
|
|
21
|
-
const situationStatus = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
const situationStatus = {
|
|
22
|
+
"over-cap": "Over cap",
|
|
23
|
+
"out-of-credits": "Out of credits"
|
|
24
|
+
};
|
|
25
|
+
export function SpendGate({
|
|
26
|
+
spentMicroUsd,
|
|
27
|
+
estimateMicroUsd,
|
|
28
|
+
capMicroUsd,
|
|
29
|
+
balanceMicroUsd,
|
|
30
|
+
runName,
|
|
31
|
+
decision,
|
|
32
|
+
onAllowOnce,
|
|
33
|
+
onRaiseCap,
|
|
34
|
+
onStop,
|
|
35
|
+
onBuyCredits,
|
|
36
|
+
autoFocus = true,
|
|
37
|
+
className
|
|
38
|
+
}) {
|
|
39
|
+
const situation = spendSituation(balanceMicroUsd, estimateMicroUsd);
|
|
40
|
+
const outOfCredits = situation === "out-of-credits";
|
|
41
|
+
const projected = spentMicroUsd + estimateMicroUsd;
|
|
42
|
+
const copy = situationCopy[situation];
|
|
43
|
+
const primaryRef = useFocusOnMount(autoFocus && !decision);
|
|
44
|
+
const meter = {
|
|
45
|
+
spentMicroUsd,
|
|
46
|
+
estimateMicroUsd,
|
|
47
|
+
capMicroUsd,
|
|
48
|
+
balanceMicroUsd,
|
|
49
|
+
outOfCredits
|
|
50
|
+
};
|
|
51
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
52
|
+
"data-slot": "spend-gate",
|
|
53
|
+
"data-situation": situation,
|
|
54
|
+
"aria-label": copy.title,
|
|
55
|
+
className: cn(!decision && outOfCredits && "ring-destructive/60", className),
|
|
56
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
57
|
+
icon: /*#__PURE__*/_jsx(CircleDollarSignIcon, {
|
|
58
|
+
"aria-hidden": true
|
|
59
|
+
}),
|
|
60
|
+
eyebrow: "Spend approval",
|
|
61
|
+
status: decision ? decision.approved ? "Allowed" : "Stopped" : situationStatus[situation],
|
|
62
|
+
tone: decision ? decision.approved ? "done" : "danger" : outOfCredits ? "danger" : "waiting"
|
|
63
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
64
|
+
className: cn(decision && "text-muted-foreground"),
|
|
65
|
+
children: copy.title
|
|
66
|
+
}), decision ? /*#__PURE__*/_jsxs(PanelBody, {
|
|
67
|
+
className: "pt-3",
|
|
68
|
+
children: [/*#__PURE__*/_jsx(DecisionSummary, {
|
|
69
|
+
decision: decision,
|
|
70
|
+
approvedVerb: "Allowed",
|
|
71
|
+
deniedVerb: "Stopped",
|
|
72
|
+
result: decision.approved ? `Allowed ${formatMicroUsd(estimateMicroUsd)} once` : `${runName ?? "The run"} stopped`
|
|
73
|
+
}), /*#__PURE__*/_jsx(SpendMeter, {
|
|
74
|
+
...meter,
|
|
75
|
+
muted: true
|
|
76
|
+
})]
|
|
77
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
78
|
+
children: [/*#__PURE__*/_jsx("p", {
|
|
79
|
+
className: "px-5 pt-1 text-sm text-muted-foreground",
|
|
80
|
+
children: copy.body(runName ?? "The agent")
|
|
81
|
+
}), /*#__PURE__*/_jsxs(PanelBody, {
|
|
82
|
+
className: "gap-5",
|
|
83
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
84
|
+
className: "flex flex-col gap-0.5",
|
|
85
|
+
children: [/*#__PURE__*/_jsx("p", {
|
|
86
|
+
className: "text-2xl font-semibold tracking-tight tabular-nums",
|
|
87
|
+
children: formatMicroUsd(estimateMicroUsd)
|
|
88
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
89
|
+
className: "text-xs text-muted-foreground",
|
|
90
|
+
children: ["Next step, estimated. The run would reach", " ", /*#__PURE__*/_jsx("span", {
|
|
91
|
+
className: "tabular-nums",
|
|
92
|
+
children: formatMicroUsd(projected)
|
|
93
|
+
}), "."]
|
|
94
|
+
})]
|
|
95
|
+
}), /*#__PURE__*/_jsx(SpendMeter, {
|
|
96
|
+
...meter
|
|
97
|
+
}), !outOfCredits && /*#__PURE__*/_jsx(RaiseCapForm, {
|
|
98
|
+
capMicroUsd: capMicroUsd,
|
|
99
|
+
suggestedMicroUsd: suggestedCapMicroUsd(projected, capMicroUsd),
|
|
100
|
+
onRaiseCap: onRaiseCap
|
|
101
|
+
})]
|
|
102
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
103
|
+
className: "justify-between",
|
|
104
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
105
|
+
className: "hidden font-mono text-[11px] text-muted-foreground sm:inline",
|
|
106
|
+
children: "The run is paused"
|
|
107
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
108
|
+
className: "flex flex-wrap gap-2",
|
|
109
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
110
|
+
ref: outOfCredits && !onBuyCredits ? primaryRef : undefined,
|
|
111
|
+
type: "button",
|
|
112
|
+
size: "sm",
|
|
113
|
+
variant: outOfCredits && !onBuyCredits ? "destructive" : "ghost",
|
|
114
|
+
onClick: onStop,
|
|
115
|
+
children: "Stop the run"
|
|
116
|
+
}), outOfCredits ? onBuyCredits && /*#__PURE__*/_jsx(Button, {
|
|
117
|
+
ref: primaryRef,
|
|
118
|
+
type: "button",
|
|
119
|
+
size: "sm",
|
|
120
|
+
onClick: onBuyCredits,
|
|
121
|
+
children: "Buy credits"
|
|
122
|
+
}) : /*#__PURE__*/_jsxs(Button, {
|
|
123
|
+
ref: primaryRef,
|
|
124
|
+
type: "button",
|
|
125
|
+
size: "sm",
|
|
126
|
+
onClick: onAllowOnce,
|
|
127
|
+
children: ["Allow ", formatMicroUsd(estimateMicroUsd), " once"]
|
|
128
|
+
})]
|
|
129
|
+
})]
|
|
130
|
+
})]
|
|
131
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
132
|
+
message: decision ? decision.approved ? "Spend allowed" : "Run stopped" : copy.title
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
32
135
|
}
|