@locusgraph/loop 0.1.0 → 0.2.1

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