@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,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
  }
@@ -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
- return scale <= 0 ? 0 : Math.min(100, Math.max(0, (value / scale) * 100));
5
+ return scale <= 0 ? 0 : Math.min(100, Math.max(0, value / scale * 100));
6
6
  }
7
- function meterFrame({ spentMicroUsd, estimateMicroUsd, capMicroUsd, balanceMicroUsd, outOfCredits, }) {
8
- if (outOfCredits) {
9
- const limit = Math.max(balanceMicroUsd, 0);
10
- return {
11
- base: limit,
12
- extra: Math.max(estimateMicroUsd - limit, 0),
13
- scale: Math.max(limit, estimateMicroUsd),
14
- limit,
15
- limitLabel: "Credits",
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
- base: spentMicroUsd,
21
- extra: estimateMicroUsd,
22
- scale,
23
- limit: capMicroUsd,
24
- limitLabel: "Cap",
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
- if (position > 80)
29
- return "-translate-x-full";
30
- if (position < 20)
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({ value, muted }) {
35
- return (_jsx("span", { className: cn("font-medium", !muted && "text-foreground"), children: formatMicroUsd(value) }));
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
- const { spentMicroUsd, estimateMicroUsd, capMicroUsd, balanceMicroUsd, outOfCredits, muted } = props;
39
- return (_jsx("div", { className: "flex flex-wrap justify-between gap-x-4 gap-y-1 text-xs text-muted-foreground tabular-nums", children: outOfCredits ? (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Next step needs ", _jsx(Amount, { value: estimateMicroUsd, muted: muted }), ", you have", " ", _jsx("span", { className: cn("font-medium", !muted && "text-destructive"), children: formatMicroUsd(balanceMicroUsd) }), " ", "in credits"] }), _jsxs("span", { children: [formatMicroUsd(spentMicroUsd), " spent this run"] })] })) : (_jsxs(_Fragment, { children: [_jsxs("span", { children: [_jsx(Amount, { value: spentMicroUsd, muted: muted }), " spent of a", " ", _jsx(Amount, { value: capMicroUsd, muted: muted }), " cap"] }), _jsxs("span", { children: [formatMicroUsd(balanceMicroUsd), " credits left"] })] })) }));
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
- const { outOfCredits, muted = false } = props;
43
- const { base, extra, scale, limit, limitLabel } = meterFrame(props);
44
- const baseWidth = percentOf(base, scale);
45
- const estimateWidth = percentOf(extra, scale);
46
- const limitPosition = percentOf(limit, scale);
47
- const projected = base + extra;
48
- return (_jsxs("div", { "data-slot": "spend-meter", className: "flex flex-col gap-1.5", children: [_jsx("div", { "aria-hidden": true, className: "relative h-4", children: _jsxs("span", { className: cn("eyebrow absolute bottom-0 whitespace-nowrap", labelAlignment(limitPosition)), style: { left: `${limitPosition}%` }, children: [limitLabel, " ", formatMicroUsd(limit)] }) }), _jsxs("div", { role: "meter", "aria-label": outOfCredits ? "Next step against your credits" : "Run spend against its cap", "aria-valuemin": 0, "aria-valuemax": scale, "aria-valuenow": projected, "aria-valuetext": `${formatMicroUsd(projected)} after the next step, ${limitLabel.toLowerCase()} ${formatMicroUsd(limit)}`, className: "relative h-1.5 bg-muted-foreground/20", children: [_jsx("span", { "aria-hidden": true, className: cn("absolute inset-y-0 left-0", muted ? "bg-muted-foreground/40" : "bg-foreground/70"), style: { width: `${baseWidth}%` } }), _jsx("span", { "aria-hidden": true, className: cn("absolute inset-y-0", muted ? "bg-muted-foreground/25" : outOfCredits ? "bg-destructive" : "bg-warn"), style: { left: `${baseWidth}%`, width: `${estimateWidth}%` } }), _jsx("span", { "aria-hidden": true, className: "absolute -inset-y-1 -ml-px w-px bg-foreground", style: { left: `${limitPosition}%` } })] }), _jsx("div", { className: "pt-0.5", children: _jsx(MeterLegend, { ...props, muted: muted }) })] }));
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, } from "../../shared/panel.js";
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
- "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.",
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
- return settledStateLabels[state] ?? "Waiting for the tool inputs.";
19
+ return settledStateLabels[state] ?? "Waiting for the tool inputs.";
20
20
  }
21
21
  function headerStatus(awaiting, decision) {
22
- if (decision) {
23
- return decision.approved
24
- ? { status: "Approved", tone: "done" }
25
- : { status: "Denied", tone: "danger" };
26
- }
27
- return awaiting ? { status: "Waiting for you", tone: "waiting" } : { tone: "idle" };
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
- return settledStateLabels[state] ?? `${toolName} ${decision.approved ? "approved" : "denied"}`;
39
+ return settledStateLabels[state] ?? `${toolName} ${decision.approved ? "approved" : "denied"}`;
31
40
  }
32
- export function Approval({ part, risk = "write", actionLabel, description, decision, onApprove, onDeny, autoFocus = true, className, }) {
33
- const [denying, setDenying] = useState(false);
34
- const toolName = toolNameOf(part);
35
- const awaiting = !decision && part.state === "approval-requested";
36
- const approveRef = useFocusOnMount(autoFocus && awaiting);
37
- const destructive = risk === "destructive";
38
- const Icon = destructive ? ShieldAlertIcon : WrenchIcon;
39
- const header = headerStatus(awaiting, decision);
40
- return (_jsxs(ApprovalPanel, { "data-slot": "approval", "data-risk": risk, "data-state": decision ? (decision.approved ? "approved" : "denied") : part.state, "aria-label": `Approve ${toolName}`, className: cn(awaiting && riskRing[risk], className), children: [_jsx(PanelHeader, { icon: _jsx(Icon, { "aria-hidden": true }), eyebrow: awaiting ? "Approval needed" : "Tool call", aside: riskLabels[risk], status: header.status, tone: header.tone }), _jsx(PanelTitle, { className: cn("truncate font-mono", !awaiting && "text-muted-foreground"), children: toolName }), awaiting && (_jsx("p", { className: "px-5 pt-1 text-sm text-muted-foreground", children: description ?? riskCopy[risk](toolName) })), awaiting && !denying && (_jsxs(_Fragment, { children: [_jsx(PanelBody, { children: _jsx(ToolInputs, { input: part.input }) }), _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, { type: "button", size: "sm", variant: "ghost", onClick: () => setDenying(true), children: "Deny" }), _jsx(Button, { ref: approveRef, type: "button", size: "sm", variant: destructive ? "destructive" : "default", onClick: onApprove, children: actionLabel ?? `Run ${toolName}` })] })] })] })), awaiting && denying && (_jsxs(_Fragment, { children: [_jsx(PanelBody, { className: "pb-4", children: _jsx(ToolInputs, { input: part.input, muted: true }) }), _jsx(DenyForm, { onDeny: onDeny, onBack: () => setDenying(false) })] })), !awaiting && (_jsx(PanelBody, { className: "pt-3", children: decision ? (_jsx(DecisionSummary, { decision: decision, result: decidedResult(toolName, part.state, decision) })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: settledLabel(part.state) })) })), _jsx(LiveStatus, { message: decision
41
- ? `${toolName} ${decision.approved ? "approved" : "denied"} by ${decision.by}`
42
- : awaiting
43
- ? `${toolName} is waiting for your approval`
44
- : settledLabel(part.state) })] }));
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, } from "../../../shared/panel.js";
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
- return count === 1 ? "1 field needs a fix." : `${count} fields need a fix.`;
12
+ return count === 1 ? "1 field needs a fix." : `${count} fields need a fix.`;
13
13
  }
14
- export function ArgsEditor({ toolName, fields, initialValues = {}, risk = "write", actionLabel, description, decision, onApprove, onCancel, autoFocus = false, className, }) {
15
- const baseId = useId();
16
- const [drafts, setDrafts] = useState(() => draftsFrom(fields, initialValues));
17
- const [showErrors, setShowErrors] = useState(false);
18
- const errors = useMemo(() => validateDrafts(fields, drafts), [fields, drafts]);
19
- const errorCount = Object.keys(errors).length;
20
- const visibleErrors = showErrors ? errors : {};
21
- const destructive = risk === "destructive";
22
- const submitRef = useFocusOnMount(autoFocus && !decision);
23
- return (_jsxs(ApprovalPanel, { "data-slot": "args-editor", "data-risk": risk, "aria-label": `Edit ${toolName} inputs`, "data-state": decision ? (decision.approved ? "approved" : "denied") : "editing", className: cn(!decision && riskRing[risk], className), children: [_jsx(PanelHeader, { icon: _jsx(SquarePenIcon, { "aria-hidden": true }), eyebrow: decision ? "Tool call" : "Edit before approving", aside: riskLabels[risk], status: decision ? (decision.approved ? "Approved" : "Cancelled") : "Waiting for you", tone: decision ? (decision.approved ? "done" : "danger") : "waiting" }), _jsx(PanelTitle, { className: cn("truncate font-mono", decision && "text-muted-foreground"), children: toolName }), decision ? (_jsx(PanelBody, { className: "pt-3", children: _jsx(DecisionSummary, { decision: decision, deniedVerb: "Cancelled", result: decision.approved
24
- ? `${toolName} approved with edited inputs`
25
- : `${toolName} cancelled` }) })) : (_jsxs(_Fragment, { children: [_jsxs("p", { className: "px-5 pt-1 text-sm text-muted-foreground", children: [description ?? riskCopy[risk](toolName), " The tool runs with what you send."] }), _jsxs("form", { noValidate: true, onSubmit: (event) => {
26
- event.preventDefault();
27
- const firstInvalid = fields.find((field) => errors[field.name]);
28
- if (firstInvalid) {
29
- setShowErrors(true);
30
- const control = event.currentTarget.elements.namedItem(firstInvalid.name);
31
- if (control instanceof HTMLElement)
32
- control.focus();
33
- return;
34
- }
35
- onApprove(valuesFromDrafts(fields, drafts));
36
- }, children: [_jsx(PanelBody, { className: "gap-5 pt-5", children: fields.map((field) => (_jsx(ArgsField, { id: `${baseId}-${field.name}`, field: field, draft: drafts[field.name], error: visibleErrors[field.name], onChange: (draft) => setDrafts((current) => ({ ...current, [field.name]: draft })) }, field.name))) }), _jsxs(PanelFooter, { className: "justify-between", children: [_jsx("span", { className: cn("hidden font-mono text-[11px] sm:inline", showErrors && errorCount > 0 ? "text-destructive" : "text-muted-foreground"), children: showErrors && errorCount > 0 ? errorSummary(errorCount) : "The run is paused" }), _jsxs("span", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: onCancel, children: "Cancel" }), _jsx(Button, { ref: submitRef, type: "submit", size: "sm", variant: destructive ? "destructive" : "default", children: actionLabel ?? `Run ${toolName} with these inputs` })] })] })] })] })), _jsx(LiveStatus, { message: showErrors && errorCount > 0 ? errorSummary(errorCount) : "" })] }));
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
- const ids = [field.description && `${id}-hint`, error && `${id}-error`].filter(Boolean);
5
- return ids.length > 0 ? ids.join(" ") : undefined;
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({ id, field, draft, error, onChange }) {
8
- const shared = {
9
- id,
10
- name: field.name,
11
- "aria-invalid": error ? true : undefined,
12
- "aria-describedby": describedBy(id, field, error),
13
- "aria-required": field.required || undefined,
14
- };
15
- if (field.type === "boolean") {
16
- return (_jsx(Checkbox, { ...shared, checked: draft === true, onCheckedChange: (checked) => onChange(checked === true) }));
17
- }
18
- const text = typeof draft === "string" ? draft : "";
19
- if (field.type === "select") {
20
- return (_jsxs(NativeSelect, { ...shared, value: text, onChange: (event) => onChange(event.target.value), children: [_jsx(NativeSelectOption, { value: "", children: "Choose\u2026" }), (field.options ?? []).map((option) => (_jsx(NativeSelectOption, { value: option.value, children: option.label }, option.value)))] }));
21
- }
22
- return (_jsx(Input, { ...shared, type: field.type === "number" ? "number" : "text", inputMode: field.type === "number" ? "decimal" : undefined, min: field.min, max: field.max, value: text, onChange: (event) => onChange(event.target.value) }));
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
- const { id, field, error } = props;
26
- const inline = field.type === "boolean";
27
- return (_jsxs("div", { "data-slot": "args-field", "data-type": field.type, className: "flex flex-col gap-1.5 [&_[data-slot=native-select-wrapper]]:w-full", children: [_jsxs("div", { className: inline ? "flex flex-row-reverse items-center justify-end gap-2" : "contents", children: [_jsxs(Label, { htmlFor: id, children: [field.label, field.required && (_jsx("span", { className: "text-xs font-normal text-muted-foreground", children: "required" }))] }), _jsx(FieldControl, { ...props })] }), field.description && (_jsx("p", { id: `${id}-hint`, className: "text-xs text-muted-foreground", children: field.description })), error && (_jsx("p", { id: `${id}-error`, className: "text-xs text-destructive", children: error }))] }));
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
  }