@locusgraph/loop 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/agent/pulse/gradient-label.js +36 -15
- package/dist/agent/pulse/marks/bars-mark.js +24 -10
- package/dist/agent/pulse/marks/glyph-mark.js +17 -11
- package/dist/agent/pulse/marks/locus-mark.js +39 -28
- package/dist/agent/pulse/marks/orb-mark.js +21 -8
- package/dist/agent/pulse/marks/spinner-mark.js +20 -1
- package/dist/agent/pulse/pulse.js +63 -35
- package/dist/agent/pulse/use-loop-animation.js +14 -16
- package/dist/agent/steps/step-icon.js +40 -24
- package/dist/agent/steps/steps.js +72 -25
- package/dist/agent/thinking/thinking.js +203 -23
- package/dist/agent/thinking/thought-duration.js +7 -9
- package/dist/agent/tool/json-block.js +18 -11
- package/dist/agent/tool/tool-status.js +28 -18
- package/dist/agent/tool/tool.js +184 -6
- package/dist/approval/inbox/inbox-row.d.ts +3 -2
- package/dist/approval/inbox/inbox-row.js +96 -7
- package/dist/approval/inbox/inbox-selection.js +7 -13
- package/dist/approval/inbox/inbox.d.ts +2 -1
- package/dist/approval/inbox/inbox.js +99 -18
- package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
- package/dist/approval/inbox/virtual-inbox-list.js +53 -0
- package/dist/approval/memory/memory-choices.js +27 -22
- package/dist/approval/memory/memory-review.js +108 -17
- package/dist/approval/memory/memory-row.js +80 -19
- package/dist/approval/plan/plan-review.js +129 -28
- package/dist/approval/plan/plan-step-row.js +91 -44
- package/dist/approval/plan/plan-steps.js +24 -23
- package/dist/approval/plan/question-choices.js +73 -40
- package/dist/approval/plan/question.d.ts +1 -1
- package/dist/approval/plan/question.js +108 -27
- package/dist/approval/run/run-bar.js +94 -22
- package/dist/approval/shared/decision-line.js +1 -1
- package/dist/approval/shared/risk-badge.js +32 -16
- package/dist/approval/shared/time.js +5 -8
- package/dist/approval/shared/use-focus-on-mount.js +7 -6
- package/dist/approval/spend/raise-cap-form.js +64 -19
- package/dist/approval/spend/spend-gate.js +124 -21
- package/dist/approval/spend/spend-math.js +7 -8
- package/dist/approval/spend/spend-meter.js +136 -35
- package/dist/approval/tool/approval.js +113 -27
- package/dist/approval/tool/args/args-editor.js +104 -26
- package/dist/approval/tool/args/args-field.js +79 -22
- package/dist/approval/tool/args/args-validation.js +38 -47
- package/dist/approval/tool/deny-form.js +43 -10
- package/dist/approval/tool/tool-inputs.js +62 -38
- package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
- package/dist/chat/chat/chat-item-spacing.js +19 -0
- package/dist/chat/chat/chat.d.ts +2 -1
- package/dist/chat/chat/chat.js +181 -5
- package/dist/chat/chat/use-stick-to-bottom.js +71 -48
- package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
- package/dist/chat/chat/virtual-chat-items.js +60 -0
- package/dist/chat/composer/composer-actions.js +69 -17
- package/dist/chat/composer/composer.js +330 -32
- package/dist/chat/composer/use-auto-grow.js +9 -9
- package/dist/chat/files/file-meta.js +19 -19
- package/dist/chat/files/files.js +92 -29
- package/dist/chat/reply/fenced-code.js +23 -21
- package/dist/chat/reply/markdown-components.js +137 -17
- package/dist/chat/reply/reply.js +30 -10
- package/dist/chat/turn/group-parts.js +43 -29
- package/dist/chat/turn/turn.js +87 -30
- package/dist/cost/context.js +104 -23
- package/dist/cost/cost-steps.js +67 -14
- package/dist/cost/cost.js +128 -23
- package/dist/cost/model-picker.js +51 -6
- package/dist/cost/shared/context-breakdown.js +83 -10
- package/dist/cost/shared/meter-marks.js +49 -9
- package/dist/cost/shared/model-option-row.js +56 -22
- package/dist/cost/shared/step-cost-row.js +65 -22
- package/dist/cost/shared/usage-totals.js +22 -18
- package/dist/memory/cite.js +62 -12
- package/dist/memory/memorized.js +65 -11
- package/dist/memory/recall.js +101 -17
- package/dist/memory/shared/host-label.js +19 -22
- package/dist/memory/shared/source-mark.js +11 -3
- package/dist/memory/sources.js +78 -14
- package/dist/shared/decision-summary.js +51 -14
- package/dist/shared/panel-empty.js +20 -3
- package/dist/shared/panel.js +69 -13
- package/dist/shared/status-dot.js +16 -8
- package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
- package/dist/shared/virtual/use-list-virtualizer.js +68 -0
- package/dist/thread/actions/action-button.js +22 -3
- package/dist/thread/actions/actions.js +184 -13
- package/dist/thread/actions/branch-switcher.js +28 -5
- package/dist/thread/canvas/canvas.js +205 -5
- package/dist/thread/canvas/version-switcher.js +54 -8
- package/dist/thread/code/code.js +186 -24
- package/dist/thread/code/copy-code-button.js +30 -14
- package/dist/thread/code/highlight.js +30 -29
- package/dist/thread/history/history-rows.d.ts +16 -0
- package/dist/thread/history/history-rows.js +23 -0
- package/dist/thread/history/history.d.ts +3 -2
- package/dist/thread/history/history.js +174 -5
- package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
- package/dist/thread/history/row/history-row.js +58 -0
- package/dist/thread/history/row/thread-item-menu.js +31 -0
- package/dist/thread/history/row/thread-title-editor.js +38 -0
- package/dist/thread/history/thread-groups.d.ts +1 -1
- package/dist/thread/history/thread-groups.js +40 -34
- package/dist/thread/history/virtual-history-list.d.ts +11 -0
- package/dist/thread/history/virtual-history-list.js +71 -0
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/starters/starters.js +33 -8
- package/dist/thread/use-copied.js +18 -16
- package/dist/types.js +1 -1
- package/package.json +6 -4
- package/dist/thread/history/history-row.js +0 -17
- package/dist/thread/history/thread-item-menu.js +0 -6
- package/dist/thread/history/thread-title-editor.js +0 -25
- /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
- /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
export function bulkApprovable(items) {
|
|
2
|
-
|
|
2
|
+
return items.filter(item => item.risk !== "destructive");
|
|
3
3
|
}
|
|
4
4
|
export function selectedIn(items, selected) {
|
|
5
|
-
|
|
6
|
-
.map((item) => item.id)
|
|
7
|
-
.filter((id) => selected.has(id));
|
|
5
|
+
return bulkApprovable(items).map(item => item.id).filter(id => selected.has(id));
|
|
8
6
|
}
|
|
9
7
|
export function selectAllState(selectableCount, selectedCount) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return selectedCount === selectableCount ? true : "indeterminate";
|
|
8
|
+
if (selectedCount === 0 || selectableCount === 0) return false;
|
|
9
|
+
return selectedCount === selectableCount ? true : "indeterminate";
|
|
13
10
|
}
|
|
14
11
|
export function toggled(selected, id, on) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
else
|
|
19
|
-
next.delete(id);
|
|
20
|
-
return next;
|
|
12
|
+
const next = new Set(selected);
|
|
13
|
+
if (on) next.add(id);else next.delete(id);
|
|
14
|
+
return next;
|
|
21
15
|
}
|
|
@@ -6,6 +6,7 @@ export type InboxProps = {
|
|
|
6
6
|
onApprove: (id: string) => void;
|
|
7
7
|
onDeny: (id: string) => void;
|
|
8
8
|
onApproveAll: (ids: string[]) => void;
|
|
9
|
+
virtualize?: boolean;
|
|
9
10
|
className?: string;
|
|
10
11
|
};
|
|
11
|
-
export declare function Inbox({ items, now, title, onApprove, onDeny, onApproveAll, className, }: InboxProps): import("react").JSX.Element;
|
|
12
|
+
export declare function Inbox({ items, now, title, onApprove, onDeny, onApproveAll, virtualize, className, }: InboxProps): import("react").JSX.Element;
|
|
@@ -1,26 +1,107 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { MailAll as InboxIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, Checkbox, Label } from "@locusgraph/components";
|
|
4
3
|
import { pluralize } from "@locusgraph/utils";
|
|
5
4
|
import { useId, useState } from "react";
|
|
6
|
-
import { ApprovalPanel, LiveStatus, PanelFooter, PanelHeader, PanelTitle
|
|
5
|
+
import { ApprovalPanel, LiveStatus, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
|
|
7
6
|
import { PanelEmpty } from "../../shared/panel-empty.js";
|
|
7
|
+
import { shouldVirtualize } from "../../shared/virtual/use-list-virtualizer.js";
|
|
8
8
|
import { InboxRow } from "./inbox-row.js";
|
|
9
9
|
import { bulkApprovable, selectAllState, selectedIn, toggled } from "./inbox-selection.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
import { VirtualInboxList } from "./virtual-inbox-list.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
|
+
export function Inbox({
|
|
13
|
+
items,
|
|
14
|
+
now = Date.now(),
|
|
15
|
+
title = "Waiting for approval",
|
|
16
|
+
onApprove,
|
|
17
|
+
onDeny,
|
|
18
|
+
onApproveAll,
|
|
19
|
+
virtualize = true,
|
|
20
|
+
className
|
|
21
|
+
}) {
|
|
22
|
+
const selectAllId = useId();
|
|
23
|
+
const [selected, setSelected] = useState(() => new Set());
|
|
24
|
+
const selectable = bulkApprovable(items);
|
|
25
|
+
const selectedIds = selectedIn(items, selected);
|
|
26
|
+
const allState = selectAllState(selectable.length, selectedIds.length);
|
|
27
|
+
const hasDestructive = selectable.length < items.length;
|
|
28
|
+
const empty = items.length === 0;
|
|
29
|
+
const rowHandlers = {
|
|
30
|
+
isSelected: id => selected.has(id),
|
|
31
|
+
onSelect: (id, on) => setSelected(current => toggled(current, id, on)),
|
|
32
|
+
onApprove,
|
|
33
|
+
onDeny
|
|
34
|
+
};
|
|
35
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
36
|
+
"data-slot": "inbox",
|
|
37
|
+
"aria-label": title,
|
|
38
|
+
className: className,
|
|
39
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
40
|
+
icon: /*#__PURE__*/_jsx(InboxIcon, {
|
|
41
|
+
"aria-hidden": true
|
|
42
|
+
}),
|
|
43
|
+
eyebrow: "Approvals",
|
|
44
|
+
status: empty ? "All clear" : `${items.length} waiting`,
|
|
45
|
+
tone: empty ? "done" : "waiting"
|
|
46
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
47
|
+
children: title
|
|
48
|
+
}), empty ? /*#__PURE__*/_jsx(PanelEmpty, {
|
|
49
|
+
"data-slot": "inbox-empty",
|
|
50
|
+
icon: /*#__PURE__*/_jsx(InboxIcon, {
|
|
51
|
+
"aria-hidden": true
|
|
52
|
+
}),
|
|
53
|
+
title: "Nothing waiting for you",
|
|
54
|
+
description: "When an agent needs approval to write, pay, send or delete, it shows up here."
|
|
55
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
56
|
+
children: [shouldVirtualize(items.length, virtualize) ? /*#__PURE__*/_jsx(VirtualInboxList, {
|
|
57
|
+
items: items,
|
|
58
|
+
now: now,
|
|
59
|
+
...rowHandlers
|
|
60
|
+
}) : /*#__PURE__*/_jsx("ul", {
|
|
61
|
+
className: "mt-4 flex flex-col divide-y border-t",
|
|
62
|
+
children: items.map(item => /*#__PURE__*/_jsx(InboxRow, {
|
|
63
|
+
item: item,
|
|
64
|
+
now: now,
|
|
65
|
+
selected: rowHandlers.isSelected(item.id),
|
|
66
|
+
onSelect: on => rowHandlers.onSelect(item.id, on),
|
|
67
|
+
onApprove: () => onApprove(item.id),
|
|
68
|
+
onDeny: () => onDeny(item.id)
|
|
69
|
+
}, item.id))
|
|
70
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
71
|
+
className: "justify-between gap-3",
|
|
72
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
73
|
+
className: "flex min-w-0 items-center gap-3",
|
|
74
|
+
children: [selectable.length > 0 && /*#__PURE__*/_jsx(Checkbox, {
|
|
75
|
+
id: selectAllId,
|
|
76
|
+
checked: allState,
|
|
77
|
+
onCheckedChange: checked => setSelected(checked === true ? new Set(selectable.map(item => item.id)) : new Set())
|
|
78
|
+
}), /*#__PURE__*/_jsxs(Label, {
|
|
79
|
+
htmlFor: selectAllId,
|
|
80
|
+
className: "flex min-w-0 flex-col items-start gap-0 font-normal",
|
|
81
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
82
|
+
className: "text-sm tabular-nums",
|
|
83
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
84
|
+
className: "sr-only",
|
|
85
|
+
children: "Select all that can be approved together. "
|
|
86
|
+
}), selectedIds.length > 0 ? `${selectedIds.length} selected` : "Select all"]
|
|
87
|
+
}), hasDestructive && /*#__PURE__*/_jsx("span", {
|
|
88
|
+
className: "text-xs text-muted-foreground",
|
|
89
|
+
children: "Destructive requests are approved one at a time."
|
|
90
|
+
})]
|
|
91
|
+
})]
|
|
92
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
93
|
+
type: "button",
|
|
94
|
+
size: "sm",
|
|
95
|
+
disabled: selectedIds.length === 0,
|
|
96
|
+
onClick: () => {
|
|
97
|
+
onApproveAll(selectedIds);
|
|
98
|
+
setSelected(new Set());
|
|
99
|
+
},
|
|
100
|
+
children: selectedIds.length > 0 ? `Approve ${selectedIds.length} selected` : "Approve selected"
|
|
101
|
+
})]
|
|
102
|
+
})]
|
|
103
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
104
|
+
message: empty ? "No approvals waiting" : `${pluralize(items.length, "approval")} waiting, ${selectedIds.length} selected`
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
26
107
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PendingApproval } from "../types.js";
|
|
2
|
+
export type InboxRowHandlers = {
|
|
3
|
+
isSelected: (id: string) => boolean;
|
|
4
|
+
onSelect: (id: string, selected: boolean) => void;
|
|
5
|
+
onApprove: (id: string) => void;
|
|
6
|
+
onDeny: (id: string) => void;
|
|
7
|
+
};
|
|
8
|
+
type VirtualInboxListProps = InboxRowHandlers & {
|
|
9
|
+
items: PendingApproval[];
|
|
10
|
+
now: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function VirtualInboxList({ items, now, isSelected, onSelect, onApprove, onDeny, }: VirtualInboxListProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cn } from "@locusgraph/components";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { rowOffsetStyle, useListVirtualizer, virtualRowClassName } from "../../shared/virtual/use-list-virtualizer.js";
|
|
4
|
+
import { InboxRow } from "./inbox-row.js";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const estimatedRowHeightPx = 57;
|
|
7
|
+
export function VirtualInboxList({
|
|
8
|
+
items,
|
|
9
|
+
now,
|
|
10
|
+
isSelected,
|
|
11
|
+
onSelect,
|
|
12
|
+
onApprove,
|
|
13
|
+
onDeny
|
|
14
|
+
}) {
|
|
15
|
+
const scrollRef = useRef(null);
|
|
16
|
+
const {
|
|
17
|
+
rows,
|
|
18
|
+
totalSize,
|
|
19
|
+
itemProps
|
|
20
|
+
} = useListVirtualizer({
|
|
21
|
+
count: items.length,
|
|
22
|
+
getScrollElement: () => scrollRef.current,
|
|
23
|
+
estimateSize: () => estimatedRowHeightPx,
|
|
24
|
+
getItemKey: index => items[index].id
|
|
25
|
+
});
|
|
26
|
+
return /*#__PURE__*/_jsx("div", {
|
|
27
|
+
ref: scrollRef,
|
|
28
|
+
"data-slot": "inbox-scroll",
|
|
29
|
+
className: "mt-4 max-h-[min(36rem,70vh)] overflow-y-auto overscroll-contain border-t",
|
|
30
|
+
children: /*#__PURE__*/_jsx("ul", {
|
|
31
|
+
className: "relative",
|
|
32
|
+
style: {
|
|
33
|
+
height: totalSize
|
|
34
|
+
},
|
|
35
|
+
children: rows.map(row => {
|
|
36
|
+
const item = items[row.index];
|
|
37
|
+
return /*#__PURE__*/_jsx(InboxRow, {
|
|
38
|
+
...itemProps(row.index),
|
|
39
|
+
"aria-posinset": row.index + 1,
|
|
40
|
+
"aria-setsize": items.length,
|
|
41
|
+
className: cn(virtualRowClassName, "border-b"),
|
|
42
|
+
style: rowOffsetStyle(row.start),
|
|
43
|
+
item: item,
|
|
44
|
+
now: now,
|
|
45
|
+
selected: isSelected(item.id),
|
|
46
|
+
onSelect: on => onSelect(item.id, on),
|
|
47
|
+
onApprove: () => onApprove(item.id),
|
|
48
|
+
onDeny: () => onDeny(item.id)
|
|
49
|
+
}, row.key);
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
export function initialDrafts(memories) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
return Object.fromEntries(memories.map(memory => [memory.id, {
|
|
3
|
+
choice: memory.sensitive ? "discard" : "keep",
|
|
4
|
+
text: memory.text
|
|
5
|
+
}]));
|
|
6
6
|
}
|
|
7
7
|
export function reviewResult(memories, drafts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const result = {
|
|
9
|
+
kept: [],
|
|
10
|
+
edited: [],
|
|
11
|
+
discarded: []
|
|
12
|
+
};
|
|
13
|
+
for (const memory of memories) {
|
|
14
|
+
const draft = drafts[memory.id] ?? {
|
|
15
|
+
choice: "keep",
|
|
16
|
+
text: memory.text
|
|
17
|
+
};
|
|
18
|
+
const text = draft.text.trim();
|
|
19
|
+
if (draft.choice === "discard") result.discarded.push(memory);else if (draft.choice === "edit" && text !== "" && text !== memory.text) {
|
|
20
|
+
result.edited.push({
|
|
21
|
+
...memory,
|
|
22
|
+
text
|
|
23
|
+
});
|
|
24
|
+
} else result.kept.push(memory);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
21
27
|
}
|
|
22
28
|
export function hasBlankEdit(drafts) {
|
|
23
|
-
|
|
29
|
+
return Object.values(drafts).some(draft => draft.choice === "edit" && draft.text.trim() === "");
|
|
24
30
|
}
|
|
25
31
|
export function submitLabel(result) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return `Save ${saved} ${saved === 1 ? "memory" : "memories"}`;
|
|
32
|
+
const saved = result.kept.length + result.edited.length;
|
|
33
|
+
if (saved === 0) return "Discard all";
|
|
34
|
+
return `Save ${saved} ${saved === 1 ? "memory" : "memories"}`;
|
|
30
35
|
}
|
|
@@ -1,31 +1,122 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Idea as BrainIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Button } from "@locusgraph/components";
|
|
4
3
|
import { pluralize } from "@locusgraph/utils";
|
|
5
4
|
import { useMemo, useState } from "react";
|
|
6
|
-
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle
|
|
5
|
+
import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
|
|
7
6
|
import { PanelEmpty } from "../../shared/panel-empty.js";
|
|
8
7
|
import { DecisionSummary } from "../shared/decision-line.js";
|
|
9
8
|
import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
|
|
10
9
|
import { hasBlankEdit, initialDrafts, reviewResult, submitLabel } from "./memory-choices.js";
|
|
11
10
|
import { MemoryRow } from "./memory-row.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
12
|
function resultSummary(result) {
|
|
13
|
-
|
|
13
|
+
return `${result.kept.length} kept, ${result.edited.length} edited, ${result.discarded.length} discarded`;
|
|
14
14
|
}
|
|
15
15
|
function headerStatus(decision, empty) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (decision) return {
|
|
17
|
+
status: "Reviewed",
|
|
18
|
+
tone: "done"
|
|
19
|
+
};
|
|
20
|
+
if (empty) return {
|
|
21
|
+
status: "Nothing new",
|
|
22
|
+
tone: "idle"
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
status: "Waiting for you",
|
|
26
|
+
tone: "waiting"
|
|
27
|
+
};
|
|
21
28
|
}
|
|
22
|
-
export function MemoryReview({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
export function MemoryReview({
|
|
30
|
+
memories,
|
|
31
|
+
title = "Review new memories",
|
|
32
|
+
description = "The agent wants to remember these in LocusGraph. Keep, edit or discard each one.",
|
|
33
|
+
decision,
|
|
34
|
+
onSubmit,
|
|
35
|
+
autoFocus = true,
|
|
36
|
+
className
|
|
37
|
+
}) {
|
|
38
|
+
const [drafts, setDrafts] = useState(() => initialDrafts(memories));
|
|
39
|
+
const result = useMemo(() => reviewResult(memories, drafts), [memories, drafts]);
|
|
40
|
+
const blankEdit = hasBlankEdit(drafts);
|
|
41
|
+
const empty = memories.length === 0;
|
|
42
|
+
const sensitiveCount = memories.filter(memory => memory.sensitive).length;
|
|
43
|
+
const submitRef = useFocusOnMount(autoFocus && !decision && !empty);
|
|
44
|
+
const {
|
|
45
|
+
status,
|
|
46
|
+
tone
|
|
47
|
+
} = headerStatus(decision, empty);
|
|
48
|
+
return /*#__PURE__*/_jsxs(ApprovalPanel, {
|
|
49
|
+
"data-slot": "memory-review",
|
|
50
|
+
"aria-label": title,
|
|
51
|
+
className: className,
|
|
52
|
+
children: [/*#__PURE__*/_jsx(PanelHeader, {
|
|
53
|
+
icon: /*#__PURE__*/_jsx(BrainIcon, {
|
|
54
|
+
"aria-hidden": true
|
|
55
|
+
}),
|
|
56
|
+
eyebrow: "Memory",
|
|
57
|
+
status: status,
|
|
58
|
+
tone: tone,
|
|
59
|
+
aside: empty ? undefined : pluralize(memories.length, "proposed", "proposed")
|
|
60
|
+
}), /*#__PURE__*/_jsx(PanelTitle, {
|
|
61
|
+
className: decision ? "text-muted-foreground" : undefined,
|
|
62
|
+
children: title
|
|
63
|
+
}), empty ? /*#__PURE__*/_jsx(PanelEmpty, {
|
|
64
|
+
icon: /*#__PURE__*/_jsx(BrainIcon, {
|
|
65
|
+
"aria-hidden": true
|
|
66
|
+
}),
|
|
67
|
+
title: "No new memories to review.",
|
|
68
|
+
description: "When an agent wants to remember something in LocusGraph, it shows up here."
|
|
69
|
+
}) : decision ? /*#__PURE__*/_jsx(PanelBody, {
|
|
70
|
+
children: /*#__PURE__*/_jsx(DecisionSummary, {
|
|
71
|
+
decision: decision,
|
|
72
|
+
approvedVerb: "Reviewed",
|
|
73
|
+
deniedVerb: "Discarded",
|
|
74
|
+
result: decision.approved ? "Memories reviewed" : "All memories discarded"
|
|
75
|
+
})
|
|
76
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
77
|
+
children: [/*#__PURE__*/_jsxs("p", {
|
|
78
|
+
className: "px-5 pt-1 text-sm text-muted-foreground",
|
|
79
|
+
children: [description, sensitiveCount > 0 && /*#__PURE__*/_jsxs("span", {
|
|
80
|
+
className: "text-warn",
|
|
81
|
+
children: [" ", pluralize(sensitiveCount, "memory", "memories"), " flagged as sensitive, set to discard."]
|
|
82
|
+
})]
|
|
83
|
+
}), /*#__PURE__*/_jsx(PanelBody, {
|
|
84
|
+
className: "pb-0",
|
|
85
|
+
children: /*#__PURE__*/_jsx("ul", {
|
|
86
|
+
className: "-mx-5 flex flex-col divide-y border-t",
|
|
87
|
+
children: memories.map(memory => /*#__PURE__*/_jsx(MemoryRow, {
|
|
88
|
+
memory: memory,
|
|
89
|
+
draft: drafts[memory.id] ?? {
|
|
90
|
+
choice: "keep",
|
|
91
|
+
text: memory.text
|
|
92
|
+
},
|
|
93
|
+
onChange: draft => setDrafts(current => ({
|
|
94
|
+
...current,
|
|
95
|
+
[memory.id]: draft
|
|
96
|
+
}))
|
|
97
|
+
}, memory.id))
|
|
98
|
+
})
|
|
99
|
+
}), /*#__PURE__*/_jsxs(PanelFooter, {
|
|
100
|
+
className: "justify-between",
|
|
101
|
+
children: [blankEdit ? /*#__PURE__*/_jsx("span", {
|
|
102
|
+
className: "text-xs text-destructive",
|
|
103
|
+
children: "An edited memory can't be empty."
|
|
104
|
+
}) : /*#__PURE__*/_jsxs("span", {
|
|
105
|
+
className: "hidden font-mono text-[11px] text-muted-foreground tabular-nums sm:inline",
|
|
106
|
+
children: [result.kept.length, " kept \xB7 ", result.edited.length, " edited \xB7", " ", result.discarded.length, " discarded"]
|
|
107
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
108
|
+
ref: submitRef,
|
|
109
|
+
type: "button",
|
|
110
|
+
size: "sm",
|
|
111
|
+
className: "ml-auto",
|
|
112
|
+
variant: result.kept.length + result.edited.length === 0 ? "destructive" : "default",
|
|
113
|
+
disabled: blankEdit,
|
|
114
|
+
onClick: () => onSubmit(result),
|
|
115
|
+
children: submitLabel(result)
|
|
116
|
+
})]
|
|
117
|
+
})]
|
|
118
|
+
}), /*#__PURE__*/_jsx(LiveStatus, {
|
|
119
|
+
message: decision ? "Memories reviewed" : resultSummary(result)
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
31
122
|
}
|
|
@@ -1,30 +1,91 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { ShieldAlert as ShieldAlertIcon } from "@carbon/icons-react";
|
|
3
2
|
import { cn, Textarea } from "@locusgraph/components";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
const choiceLabels = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
keep: "Keep",
|
|
6
|
+
edit: "Edit",
|
|
7
|
+
discard: "Discard"
|
|
8
8
|
};
|
|
9
9
|
const choices = ["keep", "edit", "discard"];
|
|
10
10
|
const selectedChoiceClass = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
keep: "text-foreground shadow-[inset_0_-2px_0_var(--color-primary)]",
|
|
12
|
+
edit: "text-foreground shadow-[inset_0_-2px_0_var(--color-primary)]",
|
|
13
|
+
discard: "text-destructive shadow-[inset_0_-2px_0_var(--color-destructive)]"
|
|
14
14
|
};
|
|
15
|
-
function ChoiceSegments({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
function ChoiceSegments({
|
|
16
|
+
value,
|
|
17
|
+
onChange
|
|
18
|
+
}) {
|
|
19
|
+
return /*#__PURE__*/_jsxs("fieldset", {
|
|
20
|
+
className: "flex shrink-0 gap-1 self-start",
|
|
21
|
+
children: [/*#__PURE__*/_jsx("legend", {
|
|
22
|
+
className: "sr-only",
|
|
23
|
+
children: "What to do with this memory"
|
|
24
|
+
}), choices.map(choice => {
|
|
25
|
+
const pressed = value === choice;
|
|
26
|
+
return /*#__PURE__*/_jsx("button", {
|
|
27
|
+
type: "button",
|
|
28
|
+
"aria-pressed": pressed,
|
|
29
|
+
onClick: () => onChange(choice),
|
|
30
|
+
className: cn("h-7 px-2 text-xs outline-none motion-safe:transition-colors focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-ring/70", pressed ? cn("font-medium", selectedChoiceClass[choice]) : "text-muted-foreground hover:text-foreground"),
|
|
31
|
+
children: choiceLabels[choice]
|
|
32
|
+
}, choice);
|
|
33
|
+
})]
|
|
34
|
+
});
|
|
22
35
|
}
|
|
23
36
|
function SensitiveMarker() {
|
|
24
|
-
|
|
37
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
38
|
+
className: "flex items-center gap-1 text-warn",
|
|
39
|
+
children: [/*#__PURE__*/_jsx(ShieldAlertIcon, {
|
|
40
|
+
"aria-hidden": true,
|
|
41
|
+
className: "size-3"
|
|
42
|
+
}), "Sensitive"]
|
|
43
|
+
});
|
|
25
44
|
}
|
|
26
|
-
export function MemoryRow({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
export function MemoryRow({
|
|
46
|
+
memory,
|
|
47
|
+
draft,
|
|
48
|
+
onChange
|
|
49
|
+
}) {
|
|
50
|
+
const discarded = draft.choice === "discard";
|
|
51
|
+
const editing = draft.choice === "edit";
|
|
52
|
+
return /*#__PURE__*/_jsxs("li", {
|
|
53
|
+
"data-slot": "memory-review-item",
|
|
54
|
+
"data-choice": draft.choice,
|
|
55
|
+
"data-sensitive": memory.sensitive || undefined,
|
|
56
|
+
className: cn("flex flex-col gap-2 px-5 py-2.5 motion-safe:transition-colors", editing ? "bg-accent/30" : "hover:bg-accent/30"),
|
|
57
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
58
|
+
className: "flex items-start gap-3",
|
|
59
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
60
|
+
className: "flex min-w-0 flex-1 flex-col gap-1",
|
|
61
|
+
children: [(memory.kind || memory.sensitive) && /*#__PURE__*/_jsxs("span", {
|
|
62
|
+
className: "eyebrow flex items-center gap-2",
|
|
63
|
+
children: [memory.kind && /*#__PURE__*/_jsx("span", {
|
|
64
|
+
children: memory.kind
|
|
65
|
+
}), memory.sensitive && /*#__PURE__*/_jsx(SensitiveMarker, {})]
|
|
66
|
+
}), !editing && /*#__PURE__*/_jsx("p", {
|
|
67
|
+
className: cn("text-sm", discarded && "text-muted-foreground line-through decoration-muted-foreground/60"),
|
|
68
|
+
children: memory.text
|
|
69
|
+
})]
|
|
70
|
+
}), /*#__PURE__*/_jsx(ChoiceSegments, {
|
|
71
|
+
value: draft.choice,
|
|
72
|
+
onChange: choice => onChange({
|
|
73
|
+
...draft,
|
|
74
|
+
choice
|
|
75
|
+
})
|
|
76
|
+
})]
|
|
77
|
+
}), editing && /*#__PURE__*/_jsx(Textarea, {
|
|
78
|
+
"aria-label": "Memory text",
|
|
79
|
+
value: draft.text,
|
|
80
|
+
"aria-invalid": draft.text.trim() === "" || undefined,
|
|
81
|
+
onChange: event => onChange({
|
|
82
|
+
...draft,
|
|
83
|
+
text: event.target.value
|
|
84
|
+
}),
|
|
85
|
+
className: "min-h-16 text-sm"
|
|
86
|
+
}), memory.sensitive && !discarded && /*#__PURE__*/_jsx("p", {
|
|
87
|
+
className: "text-xs text-warn",
|
|
88
|
+
children: "This looks like personal or secret data. Keep it only if the agent should remember it."
|
|
89
|
+
})]
|
|
90
|
+
});
|
|
30
91
|
}
|