@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,18 +1,17 @@
|
|
|
1
1
|
const microUsdPerDollar = 1_000_000;
|
|
2
2
|
const microUsdPerCent = 10_000;
|
|
3
3
|
export function spendSituation(balanceMicroUsd, estimateMicroUsd) {
|
|
4
|
-
|
|
4
|
+
return balanceMicroUsd <= 0 || balanceMicroUsd < estimateMicroUsd ? "out-of-credits" : "over-cap";
|
|
5
5
|
}
|
|
6
6
|
export function suggestedCapMicroUsd(projectedMicroUsd, capMicroUsd) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const target = Math.max(projectedMicroUsd, capMicroUsd + microUsdPerCent);
|
|
8
|
+
return Math.ceil(target / microUsdPerDollar) * microUsdPerDollar;
|
|
9
9
|
}
|
|
10
10
|
export function dollarsToMicroUsd(dollars) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
+
return (microUsd / microUsdPerDollar).toFixed(2);
|
|
18
17
|
}
|
|
@@ -1,49 +1,150 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { cn } from "@locusgraph/components";
|
|
3
2
|
import { formatMicroUsd } from "@locusgraph/utils";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
4
|
function percentOf(value, scale) {
|
|
5
|
-
|
|
5
|
+
return scale <= 0 ? 0 : Math.min(100, Math.max(0, value / scale * 100));
|
|
6
6
|
}
|
|
7
|
-
function meterFrame({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const scale = Math.max(capMicroUsd, spentMicroUsd + estimateMicroUsd);
|
|
7
|
+
function meterFrame({
|
|
8
|
+
spentMicroUsd,
|
|
9
|
+
estimateMicroUsd,
|
|
10
|
+
capMicroUsd,
|
|
11
|
+
balanceMicroUsd,
|
|
12
|
+
outOfCredits
|
|
13
|
+
}) {
|
|
14
|
+
if (outOfCredits) {
|
|
15
|
+
const limit = Math.max(balanceMicroUsd, 0);
|
|
19
16
|
return {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
base: limit,
|
|
18
|
+
extra: Math.max(estimateMicroUsd - limit, 0),
|
|
19
|
+
scale: Math.max(limit, estimateMicroUsd),
|
|
20
|
+
limit,
|
|
21
|
+
limitLabel: "Credits"
|
|
25
22
|
};
|
|
23
|
+
}
|
|
24
|
+
const scale = Math.max(capMicroUsd, spentMicroUsd + estimateMicroUsd);
|
|
25
|
+
return {
|
|
26
|
+
base: spentMicroUsd,
|
|
27
|
+
extra: estimateMicroUsd,
|
|
28
|
+
scale,
|
|
29
|
+
limit: capMicroUsd,
|
|
30
|
+
limitLabel: "Cap"
|
|
31
|
+
};
|
|
26
32
|
}
|
|
27
33
|
function labelAlignment(position) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return "";
|
|
32
|
-
return "-translate-x-1/2";
|
|
34
|
+
if (position > 80) return "-translate-x-full";
|
|
35
|
+
if (position < 20) return "";
|
|
36
|
+
return "-translate-x-1/2";
|
|
33
37
|
}
|
|
34
|
-
function Amount({
|
|
35
|
-
|
|
38
|
+
function Amount({
|
|
39
|
+
value,
|
|
40
|
+
muted
|
|
41
|
+
}) {
|
|
42
|
+
return /*#__PURE__*/_jsx("span", {
|
|
43
|
+
className: cn("font-medium", !muted && "text-foreground"),
|
|
44
|
+
children: formatMicroUsd(value)
|
|
45
|
+
});
|
|
36
46
|
}
|
|
37
47
|
function MeterLegend(props) {
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const {
|
|
49
|
+
spentMicroUsd,
|
|
50
|
+
estimateMicroUsd,
|
|
51
|
+
capMicroUsd,
|
|
52
|
+
balanceMicroUsd,
|
|
53
|
+
outOfCredits,
|
|
54
|
+
muted
|
|
55
|
+
} = props;
|
|
56
|
+
return /*#__PURE__*/_jsx("div", {
|
|
57
|
+
className: "flex flex-wrap justify-between gap-x-4 gap-y-1 text-xs text-muted-foreground tabular-nums",
|
|
58
|
+
children: outOfCredits ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
59
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
60
|
+
children: ["Next step needs ", /*#__PURE__*/_jsx(Amount, {
|
|
61
|
+
value: estimateMicroUsd,
|
|
62
|
+
muted: muted
|
|
63
|
+
}), ", you have", " ", /*#__PURE__*/_jsx("span", {
|
|
64
|
+
className: cn("font-medium", !muted && "text-destructive"),
|
|
65
|
+
children: formatMicroUsd(balanceMicroUsd)
|
|
66
|
+
}), " ", "in credits"]
|
|
67
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
68
|
+
children: [formatMicroUsd(spentMicroUsd), " spent this run"]
|
|
69
|
+
})]
|
|
70
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
71
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
72
|
+
children: [/*#__PURE__*/_jsx(Amount, {
|
|
73
|
+
value: spentMicroUsd,
|
|
74
|
+
muted: muted
|
|
75
|
+
}), " spent of a", " ", /*#__PURE__*/_jsx(Amount, {
|
|
76
|
+
value: capMicroUsd,
|
|
77
|
+
muted: muted
|
|
78
|
+
}), " cap"]
|
|
79
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
80
|
+
children: [formatMicroUsd(balanceMicroUsd), " credits left"]
|
|
81
|
+
})]
|
|
82
|
+
})
|
|
83
|
+
});
|
|
40
84
|
}
|
|
41
85
|
export function SpendMeter(props) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
86
|
+
const {
|
|
87
|
+
outOfCredits,
|
|
88
|
+
muted = false
|
|
89
|
+
} = props;
|
|
90
|
+
const {
|
|
91
|
+
base,
|
|
92
|
+
extra,
|
|
93
|
+
scale,
|
|
94
|
+
limit,
|
|
95
|
+
limitLabel
|
|
96
|
+
} = meterFrame(props);
|
|
97
|
+
const baseWidth = percentOf(base, scale);
|
|
98
|
+
const estimateWidth = percentOf(extra, scale);
|
|
99
|
+
const limitPosition = percentOf(limit, scale);
|
|
100
|
+
const projected = base + extra;
|
|
101
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
102
|
+
"data-slot": "spend-meter",
|
|
103
|
+
className: "flex flex-col gap-1.5",
|
|
104
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
105
|
+
"aria-hidden": true,
|
|
106
|
+
className: "relative h-4",
|
|
107
|
+
children: /*#__PURE__*/_jsxs("span", {
|
|
108
|
+
className: cn("eyebrow absolute bottom-0 whitespace-nowrap", labelAlignment(limitPosition)),
|
|
109
|
+
style: {
|
|
110
|
+
left: `${limitPosition}%`
|
|
111
|
+
},
|
|
112
|
+
children: [limitLabel, " ", formatMicroUsd(limit)]
|
|
113
|
+
})
|
|
114
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
115
|
+
role: "meter",
|
|
116
|
+
"aria-label": outOfCredits ? "Next step against your credits" : "Run spend against its cap",
|
|
117
|
+
"aria-valuemin": 0,
|
|
118
|
+
"aria-valuemax": scale,
|
|
119
|
+
"aria-valuenow": projected,
|
|
120
|
+
"aria-valuetext": `${formatMicroUsd(projected)} after the next step, ${limitLabel.toLowerCase()} ${formatMicroUsd(limit)}`,
|
|
121
|
+
className: "relative h-1.5 bg-muted-foreground/20",
|
|
122
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
123
|
+
"aria-hidden": true,
|
|
124
|
+
className: cn("absolute inset-y-0 left-0", muted ? "bg-muted-foreground/40" : "bg-foreground/70"),
|
|
125
|
+
style: {
|
|
126
|
+
width: `${baseWidth}%`
|
|
127
|
+
}
|
|
128
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
129
|
+
"aria-hidden": true,
|
|
130
|
+
className: cn("absolute inset-y-0", muted ? "bg-muted-foreground/25" : outOfCredits ? "bg-destructive" : "bg-warn"),
|
|
131
|
+
style: {
|
|
132
|
+
left: `${baseWidth}%`,
|
|
133
|
+
width: `${estimateWidth}%`
|
|
134
|
+
}
|
|
135
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
136
|
+
"aria-hidden": true,
|
|
137
|
+
className: "absolute -inset-y-1 -ml-px w-px bg-foreground",
|
|
138
|
+
style: {
|
|
139
|
+
left: `${limitPosition}%`
|
|
140
|
+
}
|
|
141
|
+
})]
|
|
142
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
143
|
+
className: "pt-0.5",
|
|
144
|
+
children: /*#__PURE__*/_jsx(MeterLegend, {
|
|
145
|
+
...props,
|
|
146
|
+
muted: muted
|
|
147
|
+
})
|
|
148
|
+
})]
|
|
149
|
+
});
|
|
49
150
|
}
|
|
@@ -1,45 +1,131 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { ShieldAlert as ShieldAlertIcon, Tools as WrenchIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, cn } from "@locusgraph/components";
|
|
4
3
|
import { 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 { toolNameOf } from "../../types.js";
|
|
7
6
|
import { DecisionSummary } from "../shared/decision-line.js";
|
|
8
7
|
import { riskCopy, riskLabels, riskRing } from "../shared/risk-badge.js";
|
|
9
8
|
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
10
9
|
import { DenyForm } from "./deny-form.js";
|
|
11
10
|
import { ToolInputs } from "./tool-inputs.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
12
|
const settledStateLabels = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"approval-responded": "Reply sent. Waiting for the tool to run.",
|
|
14
|
+
"output-available": "Approved and run.",
|
|
15
|
+
"output-error": "Approved, but the tool failed.",
|
|
16
|
+
"output-denied": "Denied. The tool did not run."
|
|
17
17
|
};
|
|
18
18
|
function settledLabel(state) {
|
|
19
|
-
|
|
19
|
+
return settledStateLabels[state] ?? "Waiting for the tool inputs.";
|
|
20
20
|
}
|
|
21
21
|
function headerStatus(awaiting, decision) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
22
|
+
if (decision) {
|
|
23
|
+
return decision.approved ? {
|
|
24
|
+
status: "Approved",
|
|
25
|
+
tone: "done"
|
|
26
|
+
} : {
|
|
27
|
+
status: "Denied",
|
|
28
|
+
tone: "danger"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return awaiting ? {
|
|
32
|
+
status: "Waiting for you",
|
|
33
|
+
tone: "waiting"
|
|
34
|
+
} : {
|
|
35
|
+
tone: "idle"
|
|
36
|
+
};
|
|
28
37
|
}
|
|
29
38
|
function decidedResult(toolName, state, decision) {
|
|
30
|
-
|
|
39
|
+
return settledStateLabels[state] ?? `${toolName} ${decision.approved ? "approved" : "denied"}`;
|
|
31
40
|
}
|
|
32
|
-
export function Approval({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
export function Approval({
|
|
42
|
+
part,
|
|
43
|
+
risk = "write",
|
|
44
|
+
actionLabel,
|
|
45
|
+
description,
|
|
46
|
+
decision,
|
|
47
|
+
onApprove,
|
|
48
|
+
onDeny,
|
|
49
|
+
autoFocus = true,
|
|
50
|
+
className
|
|
51
|
+
}) {
|
|
52
|
+
const [denying, setDenying] = useState(false);
|
|
53
|
+
const toolName = toolNameOf(part);
|
|
54
|
+
const awaiting = !decision && part.state === "approval-requested";
|
|
55
|
+
const approveRef = useFocusOnMount(autoFocus && awaiting);
|
|
56
|
+
const destructive = risk === "destructive";
|
|
57
|
+
const Icon = destructive ? ShieldAlertIcon : WrenchIcon;
|
|
58
|
+
const header = headerStatus(awaiting, decision);
|
|
59
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
60
|
+
"data-slot": "approval",
|
|
61
|
+
"data-risk": risk,
|
|
62
|
+
"data-state": decision ? decision.approved ? "approved" : "denied" : part.state,
|
|
63
|
+
"aria-label": `Approve ${toolName}`,
|
|
64
|
+
className: cn(awaiting && riskRing[risk], className),
|
|
65
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
66
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
67
|
+
"aria-hidden": true
|
|
68
|
+
}),
|
|
69
|
+
eyebrow: awaiting ? "Approval needed" : "Tool call",
|
|
70
|
+
aside: riskLabels[risk],
|
|
71
|
+
status: header.status,
|
|
72
|
+
tone: header.tone
|
|
73
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
74
|
+
className: cn("truncate font-mono", !awaiting && "text-muted-foreground"),
|
|
75
|
+
children: toolName
|
|
76
|
+
}), awaiting && /*#__PURE__*/_jsx("p", {
|
|
77
|
+
className: "px-5 pt-1 text-sm text-muted-foreground",
|
|
78
|
+
children: description ?? riskCopy[risk](toolName)
|
|
79
|
+
}), awaiting && !denying && /*#__PURE__*/_jsxs(_Fragment, {
|
|
80
|
+
children: [/*#__PURE__*/_jsx(PanelBody, {
|
|
81
|
+
children: /*#__PURE__*/_jsx(ToolInputs, {
|
|
82
|
+
input: part.input
|
|
83
|
+
})
|
|
84
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
85
|
+
className: "justify-between",
|
|
86
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
87
|
+
className: "hidden font-mono text-[11px] text-muted-foreground sm:inline",
|
|
88
|
+
children: "The run is paused"
|
|
89
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
90
|
+
className: "flex flex-wrap gap-2",
|
|
91
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
92
|
+
type: "button",
|
|
93
|
+
size: "sm",
|
|
94
|
+
variant: "ghost",
|
|
95
|
+
onClick: () => setDenying(true),
|
|
96
|
+
children: "Deny"
|
|
97
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
98
|
+
ref: approveRef,
|
|
99
|
+
type: "button",
|
|
100
|
+
size: "sm",
|
|
101
|
+
variant: destructive ? "destructive" : "default",
|
|
102
|
+
onClick: onApprove,
|
|
103
|
+
children: actionLabel ?? `Run ${toolName}`
|
|
104
|
+
})]
|
|
105
|
+
})]
|
|
106
|
+
})]
|
|
107
|
+
}), awaiting && denying && /*#__PURE__*/_jsxs(_Fragment, {
|
|
108
|
+
children: [/*#__PURE__*/_jsx(PanelBody, {
|
|
109
|
+
className: "pb-4",
|
|
110
|
+
children: /*#__PURE__*/_jsx(ToolInputs, {
|
|
111
|
+
input: part.input,
|
|
112
|
+
muted: true
|
|
113
|
+
})
|
|
114
|
+
}), /*#__PURE__*/_jsx(DenyForm, {
|
|
115
|
+
onDeny: onDeny,
|
|
116
|
+
onBack: () => setDenying(false)
|
|
117
|
+
})]
|
|
118
|
+
}), !awaiting && /*#__PURE__*/_jsx(PanelBody, {
|
|
119
|
+
className: "pt-3",
|
|
120
|
+
children: decision ? /*#__PURE__*/_jsx(DecisionSummary, {
|
|
121
|
+
decision: decision,
|
|
122
|
+
result: decidedResult(toolName, part.state, decision)
|
|
123
|
+
}) : /*#__PURE__*/_jsx("p", {
|
|
124
|
+
className: "text-sm text-muted-foreground",
|
|
125
|
+
children: settledLabel(part.state)
|
|
126
|
+
})
|
|
127
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
128
|
+
message: decision ? `${toolName} ${decision.approved ? "approved" : "denied"} by ${decision.by}` : awaiting ? `${toolName} is waiting for your approval` : settledLabel(part.state)
|
|
129
|
+
})]
|
|
130
|
+
});
|
|
45
131
|
}
|
|
@@ -1,37 +1,115 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Edit as SquarePenIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, cn } from "@locusgraph/components";
|
|
4
3
|
import { useId, useMemo, 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 { riskCopy, riskLabels, riskRing } from "../../shared/risk-badge.js";
|
|
8
7
|
import { useFocusOnMount } from "../../shared/use-focus-on-mount.js";
|
|
9
8
|
import { ArgsField } from "./args-field.js";
|
|
10
9
|
import { draftsFrom, validateDrafts, valuesFromDrafts } from "./args-validation.js";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
11
|
function errorSummary(count) {
|
|
12
|
-
|
|
12
|
+
return count === 1 ? "1 field needs a fix." : `${count} fields need a fix.`;
|
|
13
13
|
}
|
|
14
|
-
export function ArgsEditor({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
export function ArgsEditor({
|
|
15
|
+
toolName,
|
|
16
|
+
fields,
|
|
17
|
+
initialValues = {},
|
|
18
|
+
risk = "write",
|
|
19
|
+
actionLabel,
|
|
20
|
+
description,
|
|
21
|
+
decision,
|
|
22
|
+
onApprove,
|
|
23
|
+
onCancel,
|
|
24
|
+
autoFocus = false,
|
|
25
|
+
className
|
|
26
|
+
}) {
|
|
27
|
+
const baseId = useId();
|
|
28
|
+
const [drafts, setDrafts] = useState(() => draftsFrom(fields, initialValues));
|
|
29
|
+
const [showErrors, setShowErrors] = useState(false);
|
|
30
|
+
const errors = useMemo(() => validateDrafts(fields, drafts), [fields, drafts]);
|
|
31
|
+
const errorCount = Object.keys(errors).length;
|
|
32
|
+
const visibleErrors = showErrors ? errors : {};
|
|
33
|
+
const destructive = risk === "destructive";
|
|
34
|
+
const submitRef = useFocusOnMount(autoFocus && !decision);
|
|
35
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
36
|
+
"data-slot": "args-editor",
|
|
37
|
+
"data-risk": risk,
|
|
38
|
+
"aria-label": `Edit ${toolName} inputs`,
|
|
39
|
+
"data-state": decision ? decision.approved ? "approved" : "denied" : "editing",
|
|
40
|
+
className: cn(!decision && riskRing[risk], className),
|
|
41
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
42
|
+
icon: /*#__PURE__*/_jsx(SquarePenIcon, {
|
|
43
|
+
"aria-hidden": true
|
|
44
|
+
}),
|
|
45
|
+
eyebrow: decision ? "Tool call" : "Edit before approving",
|
|
46
|
+
aside: riskLabels[risk],
|
|
47
|
+
status: decision ? decision.approved ? "Approved" : "Cancelled" : "Waiting for you",
|
|
48
|
+
tone: decision ? decision.approved ? "done" : "danger" : "waiting"
|
|
49
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
50
|
+
className: cn("truncate font-mono", decision && "text-muted-foreground"),
|
|
51
|
+
children: toolName
|
|
52
|
+
}), decision ? /*#__PURE__*/_jsx(PanelBody, {
|
|
53
|
+
className: "pt-3",
|
|
54
|
+
children: /*#__PURE__*/_jsx(DecisionSummary, {
|
|
55
|
+
decision: decision,
|
|
56
|
+
deniedVerb: "Cancelled",
|
|
57
|
+
result: decision.approved ? `${toolName} approved with edited inputs` : `${toolName} cancelled`
|
|
58
|
+
})
|
|
59
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
60
|
+
children: [/*#__PURE__*/_jsxs("p", {
|
|
61
|
+
className: "px-5 pt-1 text-sm text-muted-foreground",
|
|
62
|
+
children: [description ?? riskCopy[risk](toolName), " The tool runs with what you send."]
|
|
63
|
+
}), /*#__PURE__*/_jsxs("form", {
|
|
64
|
+
noValidate: true,
|
|
65
|
+
onSubmit: event => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
const firstInvalid = fields.find(field => errors[field.name]);
|
|
68
|
+
if (firstInvalid) {
|
|
69
|
+
setShowErrors(true);
|
|
70
|
+
const control = event.currentTarget.elements.namedItem(firstInvalid.name);
|
|
71
|
+
if (control instanceof HTMLElement) control.focus();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
onApprove(valuesFromDrafts(fields, drafts));
|
|
75
|
+
},
|
|
76
|
+
children: [/*#__PURE__*/_jsx(PanelBody, {
|
|
77
|
+
className: "gap-5 pt-5",
|
|
78
|
+
children: fields.map(field => /*#__PURE__*/_jsx(ArgsField, {
|
|
79
|
+
id: `${baseId}-${field.name}`,
|
|
80
|
+
field: field,
|
|
81
|
+
draft: drafts[field.name],
|
|
82
|
+
error: visibleErrors[field.name],
|
|
83
|
+
onChange: draft => setDrafts(current => ({
|
|
84
|
+
...current,
|
|
85
|
+
[field.name]: draft
|
|
86
|
+
}))
|
|
87
|
+
}, field.name))
|
|
88
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
89
|
+
className: "justify-between",
|
|
90
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
91
|
+
className: cn("hidden font-mono text-[11px] sm:inline", showErrors && errorCount > 0 ? "text-destructive" : "text-muted-foreground"),
|
|
92
|
+
children: showErrors && errorCount > 0 ? errorSummary(errorCount) : "The run is paused"
|
|
93
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
94
|
+
className: "flex flex-wrap gap-2",
|
|
95
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
96
|
+
type: "button",
|
|
97
|
+
size: "sm",
|
|
98
|
+
variant: "ghost",
|
|
99
|
+
onClick: onCancel,
|
|
100
|
+
children: "Cancel"
|
|
101
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
102
|
+
ref: submitRef,
|
|
103
|
+
type: "submit",
|
|
104
|
+
size: "sm",
|
|
105
|
+
variant: destructive ? "destructive" : "default",
|
|
106
|
+
children: actionLabel ?? `Run ${toolName} with these inputs`
|
|
107
|
+
})]
|
|
108
|
+
})]
|
|
109
|
+
})]
|
|
110
|
+
})]
|
|
111
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
112
|
+
message: showErrors && errorCount > 0 ? errorSummary(errorCount) : ""
|
|
113
|
+
})]
|
|
114
|
+
});
|
|
37
115
|
}
|
|
@@ -1,28 +1,85 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Checkbox, Input, Label, NativeSelect, NativeSelectOption } from "@locusgraph/components";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
function describedBy(id, field, error) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const ids = [field.description && `${id}-hint`, error && `${id}-error`].filter(Boolean);
|
|
5
|
+
return ids.length > 0 ? ids.join(" ") : undefined;
|
|
6
6
|
}
|
|
7
|
-
function FieldControl({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
7
|
+
function FieldControl({
|
|
8
|
+
id,
|
|
9
|
+
field,
|
|
10
|
+
draft,
|
|
11
|
+
error,
|
|
12
|
+
onChange
|
|
13
|
+
}) {
|
|
14
|
+
const shared = {
|
|
15
|
+
id,
|
|
16
|
+
name: field.name,
|
|
17
|
+
"aria-invalid": error ? true : undefined,
|
|
18
|
+
"aria-describedby": describedBy(id, field, error),
|
|
19
|
+
"aria-required": field.required || undefined
|
|
20
|
+
};
|
|
21
|
+
if (field.type === "boolean") {
|
|
22
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
23
|
+
...shared,
|
|
24
|
+
checked: draft === true,
|
|
25
|
+
onCheckedChange: checked => onChange(checked === true)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const text = typeof draft === "string" ? draft : "";
|
|
29
|
+
if (field.type === "select") {
|
|
30
|
+
return /*#__PURE__*/_jsxs(NativeSelect, {
|
|
31
|
+
...shared,
|
|
32
|
+
value: text,
|
|
33
|
+
onChange: event => onChange(event.target.value),
|
|
34
|
+
children: [/*#__PURE__*/_jsx(NativeSelectOption, {
|
|
35
|
+
value: "",
|
|
36
|
+
children: "Choose\u2026"
|
|
37
|
+
}), (field.options ?? []).map(option => /*#__PURE__*/_jsx(NativeSelectOption, {
|
|
38
|
+
value: option.value,
|
|
39
|
+
children: option.label
|
|
40
|
+
}, option.value))]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return /*#__PURE__*/_jsx(Input, {
|
|
44
|
+
...shared,
|
|
45
|
+
type: field.type === "number" ? "number" : "text",
|
|
46
|
+
inputMode: field.type === "number" ? "decimal" : undefined,
|
|
47
|
+
min: field.min,
|
|
48
|
+
max: field.max,
|
|
49
|
+
value: text,
|
|
50
|
+
onChange: event => onChange(event.target.value)
|
|
51
|
+
});
|
|
23
52
|
}
|
|
24
53
|
export function ArgsField(props) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
54
|
+
const {
|
|
55
|
+
id,
|
|
56
|
+
field,
|
|
57
|
+
error
|
|
58
|
+
} = props;
|
|
59
|
+
const inline = field.type === "boolean";
|
|
60
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
61
|
+
"data-slot": "args-field",
|
|
62
|
+
"data-type": field.type,
|
|
63
|
+
className: "flex flex-col gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full",
|
|
64
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
65
|
+
className: inline ? "flex flex-row-reverse items-center justify-end gap-2" : "contents",
|
|
66
|
+
children: [/*#__PURE__*/_jsxs(Label, {
|
|
67
|
+
htmlFor: id,
|
|
68
|
+
children: [field.label, field.required && /*#__PURE__*/_jsx("span", {
|
|
69
|
+
className: "text-xs font-normal text-muted-foreground",
|
|
70
|
+
children: "required"
|
|
71
|
+
})]
|
|
72
|
+
}), /*#__PURE__*/_jsx(FieldControl, {
|
|
73
|
+
...props
|
|
74
|
+
})]
|
|
75
|
+
}), field.description && /*#__PURE__*/_jsx("p", {
|
|
76
|
+
id: `${id}-hint`,
|
|
77
|
+
className: "text-xs text-muted-foreground",
|
|
78
|
+
children: field.description
|
|
79
|
+
}), error && /*#__PURE__*/_jsx("p", {
|
|
80
|
+
id: `${id}-error`,
|
|
81
|
+
className: "text-xs text-destructive",
|
|
82
|
+
children: error
|
|
83
|
+
})]
|
|
84
|
+
});
|
|
28
85
|
}
|