@locusgraph/loop 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/agent/index.d.ts +5 -0
- package/dist/agent/index.js +5 -0
- package/dist/agent/pulse/gradient-label.d.ts +7 -0
- package/dist/agent/pulse/gradient-label.js +23 -0
- package/dist/agent/pulse/marks/bars-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/bars-mark.js +15 -0
- package/dist/agent/pulse/marks/glyph-mark.d.ts +4 -0
- package/dist/agent/pulse/marks/glyph-mark.js +17 -0
- package/dist/agent/pulse/marks/locus-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/locus-mark.js +38 -0
- package/dist/agent/pulse/marks/orb-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/orb-mark.js +11 -0
- package/dist/agent/pulse/marks/spinner-mark.d.ts +1 -0
- package/dist/agent/pulse/marks/spinner-mark.js +4 -0
- package/dist/agent/pulse/pulse-tone.d.ts +1 -0
- package/dist/agent/pulse/pulse-tone.js +1 -0
- package/dist/agent/pulse/pulse.d.ts +12 -0
- package/dist/agent/pulse/pulse.js +51 -0
- package/dist/agent/pulse/use-loop-animation.d.ts +2 -0
- package/dist/agent/pulse/use-loop-animation.js +21 -0
- package/dist/agent/shared/status-dot.d.ts +1 -0
- package/dist/agent/shared/status-dot.js +1 -0
- package/dist/agent/steps/step-icon.d.ts +8 -0
- package/dist/agent/steps/step-icon.js +31 -0
- package/dist/agent/steps/steps.d.ts +7 -0
- package/dist/agent/steps/steps.js +39 -0
- package/dist/agent/thinking/thinking.d.ts +6 -0
- package/dist/agent/thinking/thinking.js +31 -0
- package/dist/agent/thinking/thought-duration.d.ts +2 -0
- package/dist/agent/thinking/thought-duration.js +13 -0
- package/dist/agent/tool/json-block.d.ts +5 -0
- package/dist/agent/tool/json-block.js +15 -0
- package/dist/agent/tool/tool-status.d.ts +6 -0
- package/dist/agent/tool/tool-status.js +26 -0
- package/dist/agent/tool/tool.d.ts +7 -0
- package/dist/agent/tool/tool.js +14 -0
- package/dist/approval/inbox/inbox-row.d.ts +11 -0
- package/dist/approval/inbox/inbox-row.js +14 -0
- package/dist/approval/inbox/inbox-selection.d.ts +6 -0
- package/dist/approval/inbox/inbox-selection.js +21 -0
- package/dist/approval/inbox/inbox.d.ts +11 -0
- package/dist/approval/inbox/inbox.js +26 -0
- package/dist/approval/index.d.ts +9 -0
- package/dist/approval/index.js +8 -0
- package/dist/approval/memory/memory-choices.d.ts +10 -0
- package/dist/approval/memory/memory-choices.js +30 -0
- package/dist/approval/memory/memory-review.d.ts +11 -0
- package/dist/approval/memory/memory-review.js +31 -0
- package/dist/approval/memory/memory-row.d.ts +9 -0
- package/dist/approval/memory/memory-row.js +30 -0
- package/dist/approval/plan/plan-review.d.ts +13 -0
- package/dist/approval/plan/plan-review.js +38 -0
- package/dist/approval/plan/plan-step-row.d.ts +13 -0
- package/dist/approval/plan/plan-step-row.js +50 -0
- package/dist/approval/plan/plan-steps.d.ts +8 -0
- package/dist/approval/plan/plan-steps.js +29 -0
- package/dist/approval/plan/question-choices.d.ts +10 -0
- package/dist/approval/plan/question-choices.js +47 -0
- package/dist/approval/plan/question.d.ts +18 -0
- package/dist/approval/plan/question.js +35 -0
- package/dist/approval/run/run-bar.d.ts +13 -0
- package/dist/approval/run/run-bar.js +33 -0
- package/dist/approval/shared/decision-line.d.ts +1 -0
- package/dist/approval/shared/decision-line.js +1 -0
- package/dist/approval/shared/risk-badge.d.ts +10 -0
- package/dist/approval/shared/risk-badge.js +26 -0
- package/dist/approval/shared/time.d.ts +3 -0
- package/dist/approval/shared/time.js +15 -0
- package/dist/approval/shared/use-focus-on-mount.d.ts +2 -0
- package/dist/approval/shared/use-focus-on-mount.js +9 -0
- package/dist/approval/spend/raise-cap-form.d.ts +8 -0
- package/dist/approval/spend/raise-cap-form.js +26 -0
- package/dist/approval/spend/spend-gate.d.ts +16 -0
- package/dist/approval/spend/spend-gate.js +32 -0
- package/dist/approval/spend/spend-math.d.ts +5 -0
- package/dist/approval/spend/spend-math.js +18 -0
- package/dist/approval/spend/spend-meter.d.ts +10 -0
- package/dist/approval/spend/spend-meter.js +49 -0
- package/dist/approval/tool/approval.d.ts +14 -0
- package/dist/approval/tool/approval.js +45 -0
- package/dist/approval/tool/args/args-editor.d.ts +16 -0
- package/dist/approval/tool/args/args-editor.js +37 -0
- package/dist/approval/tool/args/args-field.d.ts +11 -0
- package/dist/approval/tool/args/args-field.js +28 -0
- package/dist/approval/tool/args/args-validation.d.ts +8 -0
- package/dist/approval/tool/args/args-validation.js +59 -0
- package/dist/approval/tool/deny-form.d.ts +6 -0
- package/dist/approval/tool/deny-form.js +15 -0
- package/dist/approval/tool/tool-inputs.d.ts +6 -0
- package/dist/approval/tool/tool-inputs.js +53 -0
- package/dist/approval/types.d.ts +59 -0
- package/dist/approval/types.js +1 -0
- package/dist/chat/chat/chat.d.ts +7 -0
- package/dist/chat/chat/chat.js +11 -0
- package/dist/chat/chat/use-stick-to-bottom.d.ts +7 -0
- package/dist/chat/chat/use-stick-to-bottom.js +57 -0
- package/dist/chat/composer/composer-actions.d.ts +15 -0
- package/dist/chat/composer/composer-actions.js +23 -0
- package/dist/chat/composer/composer.d.ts +20 -0
- package/dist/chat/composer/composer.js +42 -0
- package/dist/chat/composer/use-auto-grow.d.ts +2 -0
- package/dist/chat/composer/use-auto-grow.js +14 -0
- package/dist/chat/files/file-meta.d.ts +13 -0
- package/dist/chat/files/file-meta.js +30 -0
- package/dist/chat/files/files.d.ts +9 -0
- package/dist/chat/files/files.js +39 -0
- package/dist/chat/index.d.ts +7 -0
- package/dist/chat/index.js +7 -0
- package/dist/chat/reply/fenced-code.d.ts +8 -0
- package/dist/chat/reply/fenced-code.js +29 -0
- package/dist/chat/reply/markdown-components.d.ts +2 -0
- package/dist/chat/reply/markdown-components.js +22 -0
- package/dist/chat/reply/reply.d.ts +8 -0
- package/dist/chat/reply/reply.js +21 -0
- package/dist/chat/turn/group-parts.d.ts +24 -0
- package/dist/chat/turn/group-parts.js +35 -0
- package/dist/chat/turn/turn.d.ts +11 -0
- package/dist/chat/turn/turn.js +45 -0
- package/dist/cost/context.d.ts +13 -0
- package/dist/cost/context.js +35 -0
- package/dist/cost/cost-steps.d.ts +17 -0
- package/dist/cost/cost-steps.js +24 -0
- package/dist/cost/cost.d.ts +8 -0
- package/dist/cost/cost.js +37 -0
- package/dist/cost/index.d.ts +4 -0
- package/dist/cost/index.js +4 -0
- package/dist/cost/model-picker.d.ts +11 -0
- package/dist/cost/model-picker.js +9 -0
- package/dist/cost/shared/context-breakdown.d.ts +15 -0
- package/dist/cost/shared/context-breakdown.js +17 -0
- package/dist/cost/shared/meter-marks.d.ts +9 -0
- package/dist/cost/shared/meter-marks.js +16 -0
- package/dist/cost/shared/model-option-row.d.ts +14 -0
- package/dist/cost/shared/model-option-row.js +32 -0
- package/dist/cost/shared/step-cost-row.d.ts +15 -0
- package/dist/cost/shared/step-cost-row.js +34 -0
- package/dist/cost/shared/usage-totals.d.ts +11 -0
- package/dist/cost/shared/usage-totals.js +26 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/memory/cite.d.ts +8 -0
- package/dist/memory/cite.js +19 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.js +4 -0
- package/dist/memory/memorized.d.ts +14 -0
- package/dist/memory/memorized.js +19 -0
- package/dist/memory/recall.d.ts +9 -0
- package/dist/memory/recall.js +24 -0
- package/dist/memory/shared/disclosure.d.ts +6 -0
- package/dist/memory/shared/disclosure.js +6 -0
- package/dist/memory/shared/host-label.d.ts +6 -0
- package/dist/memory/shared/host-label.js +34 -0
- package/dist/memory/shared/source-mark.d.ts +5 -0
- package/dist/memory/shared/source-mark.js +6 -0
- package/dist/memory/sources.d.ts +9 -0
- package/dist/memory/sources.js +22 -0
- package/dist/shared/decision-summary.d.ts +18 -0
- package/dist/shared/decision-summary.js +25 -0
- package/dist/shared/panel-empty.d.ts +8 -0
- package/dist/shared/panel-empty.js +5 -0
- package/dist/shared/panel.d.ts +19 -0
- package/dist/shared/panel.js +21 -0
- package/dist/shared/status-dot.d.ts +6 -0
- package/dist/shared/status-dot.js +12 -0
- package/dist/sources.css +1 -0
- package/dist/thread/actions/action-button.d.ts +8 -0
- package/dist/thread/actions/action-button.js +5 -0
- package/dist/thread/actions/actions.d.ts +13 -0
- package/dist/thread/actions/actions.js +21 -0
- package/dist/thread/actions/branch-switcher.d.ts +10 -0
- package/dist/thread/actions/branch-switcher.js +7 -0
- package/dist/thread/canvas/canvas.d.ts +14 -0
- package/dist/thread/canvas/canvas.js +12 -0
- package/dist/thread/canvas/version-switcher.d.ts +12 -0
- package/dist/thread/canvas/version-switcher.js +11 -0
- package/dist/thread/code/code.d.ts +10 -0
- package/dist/thread/code/code.js +33 -0
- package/dist/thread/code/copy-code-button.d.ts +6 -0
- package/dist/thread/code/copy-code-button.js +18 -0
- package/dist/thread/code/highlight.d.ts +1 -0
- package/dist/thread/code/highlight.js +39 -0
- package/dist/thread/history/history-row.d.ts +14 -0
- package/dist/thread/history/history-row.js +17 -0
- package/dist/thread/history/history.d.ts +15 -0
- package/dist/thread/history/history.js +10 -0
- package/dist/thread/history/thread-groups.d.ts +8 -0
- package/dist/thread/history/thread-groups.js +46 -0
- package/dist/thread/history/thread-item-menu.d.ts +7 -0
- package/dist/thread/history/thread-item-menu.js +6 -0
- package/dist/thread/history/thread-title-editor.d.ts +7 -0
- package/dist/thread/history/thread-title-editor.js +25 -0
- package/dist/thread/index.d.ts +8 -0
- package/dist/thread/index.js +5 -0
- package/dist/thread/starters/starters.d.ts +12 -0
- package/dist/thread/starters/starters.js +15 -0
- package/dist/thread/use-copied.d.ts +5 -0
- package/dist/thread/use-copied.js +22 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +3 -0
- package/package.json +57 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type RaiseCapFormProps = {
|
|
2
|
+
capMicroUsd: number;
|
|
3
|
+
suggestedMicroUsd: number;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
onRaiseCap: (newCapMicroUsd: number) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function RaiseCapForm({ capMicroUsd, suggestedMicroUsd, disabled, onRaiseCap, }: RaiseCapFormProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Input, Label } from "@locusgraph/components";
|
|
3
|
+
import { formatMicroUsd } from "@locusgraph/utils";
|
|
4
|
+
import { useId, useState } from "react";
|
|
5
|
+
import { dollarsToMicroUsd, microUsdToDollarsInput } from "./spend-math.js";
|
|
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;
|
|
12
|
+
}
|
|
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 }))] }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ApprovalDecision } from "../types.js";
|
|
2
|
+
export type SpendGateProps = {
|
|
3
|
+
spentMicroUsd: number;
|
|
4
|
+
estimateMicroUsd: number;
|
|
5
|
+
capMicroUsd: number;
|
|
6
|
+
balanceMicroUsd: number;
|
|
7
|
+
runName?: string;
|
|
8
|
+
decision?: ApprovalDecision;
|
|
9
|
+
onAllowOnce: () => void;
|
|
10
|
+
onRaiseCap: (newCapMicroUsd: number) => void;
|
|
11
|
+
onStop: () => void;
|
|
12
|
+
onBuyCredits?: () => void;
|
|
13
|
+
autoFocus?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function SpendGate({ spentMicroUsd, estimateMicroUsd, capMicroUsd, balanceMicroUsd, runName, decision, onAllowOnce, onRaiseCap, onStop, onBuyCredits, autoFocus, className, }: SpendGateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CurrencyDollar as CircleDollarSignIcon } from "@carbon/icons-react";
|
|
3
|
+
import { Button, cn } from "@locusgraph/components";
|
|
4
|
+
import { formatMicroUsd } from "@locusgraph/utils";
|
|
5
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle, } from "../../shared/panel.js";
|
|
6
|
+
import { DecisionSummary } from "../shared/decision-line.js";
|
|
7
|
+
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
8
|
+
import { RaiseCapForm } from "./raise-cap-form.js";
|
|
9
|
+
import { spendSituation, suggestedCapMicroUsd } from "./spend-math.js";
|
|
10
|
+
import { SpendMeter } from "./spend-meter.js";
|
|
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
|
+
},
|
|
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 })] }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type SpendSituation = "over-cap" | "out-of-credits";
|
|
2
|
+
export declare function spendSituation(balanceMicroUsd: number, estimateMicroUsd: number): SpendSituation;
|
|
3
|
+
export declare function suggestedCapMicroUsd(projectedMicroUsd: number, capMicroUsd: number): number;
|
|
4
|
+
export declare function dollarsToMicroUsd(dollars: string): number | null;
|
|
5
|
+
export declare function microUsdToDollarsInput(microUsd: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const microUsdPerDollar = 1_000_000;
|
|
2
|
+
const microUsdPerCent = 10_000;
|
|
3
|
+
export function spendSituation(balanceMicroUsd, estimateMicroUsd) {
|
|
4
|
+
return balanceMicroUsd <= 0 || balanceMicroUsd < estimateMicroUsd ? "out-of-credits" : "over-cap";
|
|
5
|
+
}
|
|
6
|
+
export function suggestedCapMicroUsd(projectedMicroUsd, capMicroUsd) {
|
|
7
|
+
const target = Math.max(projectedMicroUsd, capMicroUsd + microUsdPerCent);
|
|
8
|
+
return Math.ceil(target / microUsdPerDollar) * microUsdPerDollar;
|
|
9
|
+
}
|
|
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);
|
|
15
|
+
}
|
|
16
|
+
export function microUsdToDollarsInput(microUsd) {
|
|
17
|
+
return (microUsd / microUsdPerDollar).toFixed(2);
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type SpendMeterProps = {
|
|
2
|
+
spentMicroUsd: number;
|
|
3
|
+
estimateMicroUsd: number;
|
|
4
|
+
capMicroUsd: number;
|
|
5
|
+
balanceMicroUsd: number;
|
|
6
|
+
outOfCredits: boolean;
|
|
7
|
+
muted?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function SpendMeter(props: SpendMeterProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "@locusgraph/components";
|
|
3
|
+
import { formatMicroUsd } from "@locusgraph/utils";
|
|
4
|
+
function percentOf(value, scale) {
|
|
5
|
+
return scale <= 0 ? 0 : Math.min(100, Math.max(0, (value / scale) * 100));
|
|
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);
|
|
19
|
+
return {
|
|
20
|
+
base: spentMicroUsd,
|
|
21
|
+
extra: estimateMicroUsd,
|
|
22
|
+
scale,
|
|
23
|
+
limit: capMicroUsd,
|
|
24
|
+
limitLabel: "Cap",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function labelAlignment(position) {
|
|
28
|
+
if (position > 80)
|
|
29
|
+
return "-translate-x-full";
|
|
30
|
+
if (position < 20)
|
|
31
|
+
return "";
|
|
32
|
+
return "-translate-x-1/2";
|
|
33
|
+
}
|
|
34
|
+
function Amount({ value, muted }) {
|
|
35
|
+
return (_jsx("span", { className: cn("font-medium", !muted && "text-foreground"), children: formatMicroUsd(value) }));
|
|
36
|
+
}
|
|
37
|
+
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"] })] })) }));
|
|
40
|
+
}
|
|
41
|
+
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 }) })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RiskLevel, type ToolPart } from "../../types.js";
|
|
2
|
+
import type { ApprovalDecision } from "../types.js";
|
|
3
|
+
export type ApprovalProps = {
|
|
4
|
+
part: ToolPart;
|
|
5
|
+
risk?: RiskLevel;
|
|
6
|
+
actionLabel?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
decision?: ApprovalDecision;
|
|
9
|
+
onApprove: () => void;
|
|
10
|
+
onDeny: (reason?: string) => void;
|
|
11
|
+
autoFocus?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function Approval({ part, risk, actionLabel, description, decision, onApprove, onDeny, autoFocus, className, }: ApprovalProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ShieldAlert as ShieldAlertIcon, Tools as WrenchIcon } from "@carbon/icons-react";
|
|
3
|
+
import { Button, cn } from "@locusgraph/components";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle, } from "../../shared/panel.js";
|
|
6
|
+
import { toolNameOf } from "../../types.js";
|
|
7
|
+
import { DecisionSummary } from "../shared/decision-line.js";
|
|
8
|
+
import { riskCopy, riskLabels, riskRing } from "../shared/risk-badge.js";
|
|
9
|
+
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
10
|
+
import { DenyForm } from "./deny-form.js";
|
|
11
|
+
import { ToolInputs } from "./tool-inputs.js";
|
|
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.",
|
|
17
|
+
};
|
|
18
|
+
function settledLabel(state) {
|
|
19
|
+
return settledStateLabels[state] ?? "Waiting for the tool inputs.";
|
|
20
|
+
}
|
|
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" };
|
|
28
|
+
}
|
|
29
|
+
function decidedResult(toolName, state, decision) {
|
|
30
|
+
return settledStateLabels[state] ?? `${toolName} ${decision.approved ? "approved" : "denied"}`;
|
|
31
|
+
}
|
|
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) })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RiskLevel } from "../../../types.js";
|
|
2
|
+
import type { ApprovalDecision, ArgField, ArgValues } from "../../types.js";
|
|
3
|
+
export type ArgsEditorProps = {
|
|
4
|
+
toolName: string;
|
|
5
|
+
fields: ArgField[];
|
|
6
|
+
initialValues?: ArgValues;
|
|
7
|
+
risk?: RiskLevel;
|
|
8
|
+
actionLabel?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
decision?: ApprovalDecision;
|
|
11
|
+
onApprove: (editedInput: ArgValues) => void;
|
|
12
|
+
onCancel: () => void;
|
|
13
|
+
autoFocus?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function ArgsEditor({ toolName, fields, initialValues, risk, actionLabel, description, decision, onApprove, onCancel, autoFocus, className, }: ArgsEditorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Edit as SquarePenIcon } from "@carbon/icons-react";
|
|
3
|
+
import { Button, cn } from "@locusgraph/components";
|
|
4
|
+
import { useId, useMemo, useState } from "react";
|
|
5
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle, } from "../../../shared/panel.js";
|
|
6
|
+
import { DecisionSummary } from "../../shared/decision-line.js";
|
|
7
|
+
import { riskCopy, riskLabels, riskRing } from "../../shared/risk-badge.js";
|
|
8
|
+
import { useFocusOnMount } from "../../shared/use-focus-on-mount.js";
|
|
9
|
+
import { ArgsField } from "./args-field.js";
|
|
10
|
+
import { draftsFrom, validateDrafts, valuesFromDrafts } from "./args-validation.js";
|
|
11
|
+
function errorSummary(count) {
|
|
12
|
+
return count === 1 ? "1 field needs a fix." : `${count} fields need a fix.`;
|
|
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) : "" })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ArgField } from "../../types.js";
|
|
2
|
+
import type { ArgDraft } from "./args-validation.js";
|
|
3
|
+
type ArgsFieldProps = {
|
|
4
|
+
id: string;
|
|
5
|
+
field: ArgField;
|
|
6
|
+
draft: ArgDraft | undefined;
|
|
7
|
+
error?: string;
|
|
8
|
+
onChange: (draft: ArgDraft) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function ArgsField(props: ArgsFieldProps): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Checkbox, Input, Label, NativeSelect, NativeSelectOption } from "@locusgraph/components";
|
|
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;
|
|
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) }));
|
|
23
|
+
}
|
|
24
|
+
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 }))] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ArgField, ArgValues } from "../../types.js";
|
|
2
|
+
export type ArgDraft = string | boolean;
|
|
3
|
+
export type ArgDrafts = Record<string, ArgDraft>;
|
|
4
|
+
export type ArgErrors = Record<string, string>;
|
|
5
|
+
export declare function draftsFrom(fields: ArgField[], initialValues: ArgValues): ArgDrafts;
|
|
6
|
+
export declare function fieldError(field: ArgField, draft: ArgDraft | undefined): string | undefined;
|
|
7
|
+
export declare function validateDrafts(fields: ArgField[], drafts: ArgDrafts): ArgErrors;
|
|
8
|
+
export declare function valuesFromDrafts(fields: ArgField[], drafts: ArgDrafts): ArgValues;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function draftsFrom(fields, initialValues) {
|
|
2
|
+
return Object.fromEntries(fields.map((field) => {
|
|
3
|
+
const initial = initialValues[field.name];
|
|
4
|
+
if (field.type === "boolean")
|
|
5
|
+
return [field.name, initial === true];
|
|
6
|
+
return [field.name, initial === undefined ? "" : String(initial)];
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
function numberError(field, draft) {
|
|
10
|
+
const value = Number(draft);
|
|
11
|
+
if (!Number.isFinite(value))
|
|
12
|
+
return `${field.label} must be a number.`;
|
|
13
|
+
if (field.min !== undefined && value < field.min) {
|
|
14
|
+
return `${field.label} must be at least ${field.min}.`;
|
|
15
|
+
}
|
|
16
|
+
if (field.max !== undefined && value > field.max) {
|
|
17
|
+
return `${field.label} must be at most ${field.max}.`;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function fieldError(field, draft) {
|
|
22
|
+
if (field.type === "boolean")
|
|
23
|
+
return undefined;
|
|
24
|
+
const text = typeof draft === "string" ? draft.trim() : "";
|
|
25
|
+
if (text === "")
|
|
26
|
+
return field.required ? `${field.label} is required.` : undefined;
|
|
27
|
+
if (field.type === "number")
|
|
28
|
+
return numberError(field, text);
|
|
29
|
+
if (field.type === "select" && !field.options?.some((option) => option.value === text)) {
|
|
30
|
+
return `Choose one of the listed ${field.label.toLowerCase()} options.`;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
export function validateDrafts(fields, drafts) {
|
|
35
|
+
const errors = {};
|
|
36
|
+
for (const field of fields) {
|
|
37
|
+
const error = fieldError(field, drafts[field.name]);
|
|
38
|
+
if (error)
|
|
39
|
+
errors[field.name] = error;
|
|
40
|
+
}
|
|
41
|
+
return errors;
|
|
42
|
+
}
|
|
43
|
+
function valueFromDraft(field, draft) {
|
|
44
|
+
if (field.type === "boolean")
|
|
45
|
+
return draft === true;
|
|
46
|
+
const text = typeof draft === "string" ? draft.trim() : "";
|
|
47
|
+
if (text === "")
|
|
48
|
+
return undefined;
|
|
49
|
+
return field.type === "number" ? Number(text) : text;
|
|
50
|
+
}
|
|
51
|
+
export function valuesFromDrafts(fields, drafts) {
|
|
52
|
+
const values = {};
|
|
53
|
+
for (const field of fields) {
|
|
54
|
+
const value = valueFromDraft(field, drafts[field.name]);
|
|
55
|
+
if (value !== undefined)
|
|
56
|
+
values[field.name] = value;
|
|
57
|
+
}
|
|
58
|
+
return values;
|
|
59
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Label, Textarea } from "@locusgraph/components";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { PanelBody, PanelFooter } from "../../shared/panel.js";
|
|
5
|
+
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
6
|
+
export function DenyForm({ onDeny, onBack }) {
|
|
7
|
+
const [reason, setReason] = useState("");
|
|
8
|
+
const reasonId = useId();
|
|
9
|
+
const reasonRef = useFocusOnMount(true);
|
|
10
|
+
const trimmed = reason.trim();
|
|
11
|
+
return (_jsxs("form", { "data-slot": "deny-form", onSubmit: (event) => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
onDeny(trimmed === "" ? undefined : trimmed);
|
|
14
|
+
}, children: [_jsxs(PanelBody, { className: "gap-2 pt-0", children: [_jsx(Label, { htmlFor: reasonId, className: "text-xs font-normal text-muted-foreground", children: "Reason for the agent (optional)" }), _jsx(Textarea, { id: reasonId, ref: reasonRef, value: reason, placeholder: "Tell the agent what to do instead", onChange: (event) => setReason(event.target.value) })] }), _jsxs(PanelFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: onBack, children: "Back" }), _jsx(Button, { type: "submit", variant: "destructive", size: "sm", children: "Send denial" })] })] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "@locusgraph/components";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
function isPlainRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function isPrimitive(value) {
|
|
8
|
+
return value === null || ["string", "number", "boolean"].includes(typeof value);
|
|
9
|
+
}
|
|
10
|
+
export function readableValue(value) {
|
|
11
|
+
if (value === null || value === undefined)
|
|
12
|
+
return "None";
|
|
13
|
+
if (typeof value === "boolean")
|
|
14
|
+
return value ? "Yes" : "No";
|
|
15
|
+
if (typeof value === "string" || typeof value === "number")
|
|
16
|
+
return String(value);
|
|
17
|
+
if (Array.isArray(value) && value.every(isPrimitive)) {
|
|
18
|
+
return value.length === 0 ? "None" : value.map(readableValue).join(", ");
|
|
19
|
+
}
|
|
20
|
+
return JSON.stringify(value);
|
|
21
|
+
}
|
|
22
|
+
const acronyms = {
|
|
23
|
+
api: "API",
|
|
24
|
+
csv: "CSV",
|
|
25
|
+
id: "ID",
|
|
26
|
+
ids: "IDs",
|
|
27
|
+
json: "JSON",
|
|
28
|
+
pdf: "PDF",
|
|
29
|
+
sql: "SQL",
|
|
30
|
+
url: "URL",
|
|
31
|
+
urls: "URLs",
|
|
32
|
+
usd: "USD",
|
|
33
|
+
};
|
|
34
|
+
export function humanizeKey(key) {
|
|
35
|
+
const words = key
|
|
36
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
37
|
+
.replace(/[_-]+/g, " ")
|
|
38
|
+
.trim()
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.split(/\s+/)
|
|
41
|
+
.map((word) => acronyms[word] ?? word);
|
|
42
|
+
const sentence = words.join(" ");
|
|
43
|
+
return sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
44
|
+
}
|
|
45
|
+
function rawJson(input) {
|
|
46
|
+
return JSON.stringify(input, null, 2) ?? "undefined";
|
|
47
|
+
}
|
|
48
|
+
export function ToolInputs({ input, muted = false }) {
|
|
49
|
+
const [showRaw, setShowRaw] = useState(false);
|
|
50
|
+
const rawId = useId();
|
|
51
|
+
const entries = isPlainRecord(input) ? Object.entries(input) : null;
|
|
52
|
+
return (_jsxs("div", { "data-slot": "tool-inputs", className: "flex flex-col gap-2", children: [entries && !showRaw && (_jsxs("dl", { className: cn("-mx-5 flex flex-col divide-y border-y text-sm", muted && "text-muted-foreground"), children: [entries.map(([key, value]) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,8.5rem)_minmax(0,1fr)] items-baseline gap-3 px-5 py-2.5", children: [_jsx("dt", { className: "text-xs text-muted-foreground", children: humanizeKey(key) }), _jsx("dd", { className: "font-mono text-sm break-words", children: readableValue(value) })] }, key))), entries.length === 0 && (_jsx("div", { className: "px-5 py-2.5 text-xs text-muted-foreground", children: "No inputs." }))] })), (showRaw || !entries) && (_jsx("pre", { id: rawId, className: "overflow-x-auto bg-muted/40 p-3 font-mono text-xs", children: rawJson(input) })), entries && (_jsx("button", { type: "button", className: "eyebrow self-start outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-safe:transition-colors", "aria-expanded": showRaw, "aria-controls": showRaw ? rawId : undefined, onClick: () => setShowRaw((current) => !current), children: showRaw ? "Show fields" : "Show raw" }))] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RiskLevel } from "../types.js";
|
|
2
|
+
export type DecidedAt = number | string | Date;
|
|
3
|
+
export type ApprovalDecision = {
|
|
4
|
+
approved: boolean;
|
|
5
|
+
by: string;
|
|
6
|
+
at: DecidedAt;
|
|
7
|
+
reason?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ArgFieldType = "text" | "number" | "boolean" | "select";
|
|
10
|
+
export type ArgFieldOption = {
|
|
11
|
+
value: string;
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
export type ArgField = {
|
|
15
|
+
name: string;
|
|
16
|
+
label: string;
|
|
17
|
+
type: ArgFieldType;
|
|
18
|
+
options?: ArgFieldOption[];
|
|
19
|
+
required?: boolean;
|
|
20
|
+
min?: number;
|
|
21
|
+
max?: number;
|
|
22
|
+
description?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ArgValue = string | number | boolean;
|
|
25
|
+
export type ArgValues = Record<string, ArgValue>;
|
|
26
|
+
export type PlanStepDraft = {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
detail?: string;
|
|
30
|
+
};
|
|
31
|
+
export type QuestionOption = {
|
|
32
|
+
id: string;
|
|
33
|
+
label: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
};
|
|
36
|
+
export type QuestionAnswer = {
|
|
37
|
+
optionId?: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
};
|
|
40
|
+
export type ProposedMemory = {
|
|
41
|
+
id: string;
|
|
42
|
+
text: string;
|
|
43
|
+
kind?: string;
|
|
44
|
+
sensitive?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type MemoryReviewResult = {
|
|
47
|
+
kept: ProposedMemory[];
|
|
48
|
+
edited: ProposedMemory[];
|
|
49
|
+
discarded: ProposedMemory[];
|
|
50
|
+
};
|
|
51
|
+
export type RunBarStatus = "running" | "paused" | "stopped" | "done";
|
|
52
|
+
export type PendingApproval = {
|
|
53
|
+
id: string;
|
|
54
|
+
title: string;
|
|
55
|
+
runName: string;
|
|
56
|
+
risk: RiskLevel;
|
|
57
|
+
requestedAt: DecidedAt;
|
|
58
|
+
summary?: string;
|
|
59
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type ChatProps = React.ComponentProps<"div"> & {
|
|
3
|
+
empty?: React.ReactNode;
|
|
4
|
+
label?: string;
|
|
5
|
+
jumpLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function Chat({ children, empty, label, jumpLabel, className, ...props }: ChatProps): React.JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ArrowDown as ArrowDownIcon } from "@carbon/icons-react";
|
|
4
|
+
import { Button, cn } from "@locusgraph/components";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { useStickToBottom } from "./use-stick-to-bottom.js";
|
|
7
|
+
export function Chat({ children, empty, label = "Chat", jumpLabel = "Jump to latest", className, ...props }) {
|
|
8
|
+
const { viewportRef, contentRef, isAtBottom, handleScroll, scrollToLatest } = useStickToBottom();
|
|
9
|
+
const isEmpty = React.Children.toArray(children).length === 0;
|
|
10
|
+
return (_jsxs("div", { "data-slot": "chat", "data-empty": isEmpty || undefined, className: cn("relative flex min-h-0 flex-1 flex-col overflow-hidden", className), ...props, children: [_jsx("div", { ref: viewportRef, "data-slot": "chat-viewport", role: "log", "aria-label": label, tabIndex: 0, onScroll: handleScroll, className: "min-h-0 flex-1 overflow-y-auto overscroll-contain outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset", children: _jsx("div", { ref: contentRef, "data-slot": "chat-content", className: "mx-auto flex min-h-full w-full max-w-3xl flex-col gap-8 px-4 py-6 [&>[data-role=user]+[data-role=assistant]]:-mt-4", children: isEmpty ? (_jsx("div", { "data-slot": "chat-empty", className: "flex flex-1 flex-col items-center justify-center text-center", children: empty })) : (children) }) }), !isEmpty && !isAtBottom && (_jsxs(Button, { type: "button", variant: "outline", size: "sm", "data-slot": "chat-jump", onClick: scrollToLatest, className: "absolute bottom-3 left-1/2 h-7 -translate-x-1/2 bg-card px-3 text-xs text-muted-foreground shadow-none hover:text-foreground motion-safe:animate-in motion-safe:fade-in-0 dark:bg-card", children: [_jsx(ArrowDownIcon, { "aria-hidden": "true", className: "size-3.5" }), jumpLabel] }))] }));
|
|
11
|
+
}
|