@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,32 +1,66 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { Checkmark as CheckIcon } from "@carbon/icons-react";
|
|
3
2
|
import { DropdownMenuRadioItem } from "@locusgraph/components";
|
|
4
3
|
import { formatMicroUsd } from "@locusgraph/utils";
|
|
5
4
|
import { formatTokensShort } from "./usage-totals.js";
|
|
6
|
-
|
|
5
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const speedLabel = {
|
|
7
|
+
fast: "Fast",
|
|
8
|
+
balanced: "Balanced",
|
|
9
|
+
deep: "Deep"
|
|
10
|
+
};
|
|
7
11
|
export function modelPriceLabel(model) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (input === undefined)
|
|
15
|
-
return `${formatMicroUsd(output)} / 1M out`;
|
|
16
|
-
return `${formatMicroUsd(input)} in · ${formatMicroUsd(output)} out / 1M`;
|
|
12
|
+
const input = model.inputPerMillionMicroUsd;
|
|
13
|
+
const output = model.outputPerMillionMicroUsd;
|
|
14
|
+
if (input === undefined && output === undefined) return undefined;
|
|
15
|
+
if (output === undefined) return `${formatMicroUsd(input ?? 0)} / 1M in`;
|
|
16
|
+
if (input === undefined) return `${formatMicroUsd(output)} / 1M out`;
|
|
17
|
+
return `${formatMicroUsd(input)} in · ${formatMicroUsd(output)} out / 1M`;
|
|
17
18
|
}
|
|
18
19
|
function modelFacts(model) {
|
|
19
|
-
|
|
20
|
-
model.speed && speedLabel[model.speed],
|
|
21
|
-
model.contextTokens !== undefined && `${formatTokensShort(model.contextTokens)} context`,
|
|
22
|
-
].filter((fact) => typeof fact === "string");
|
|
20
|
+
return [model.speed && speedLabel[model.speed], model.contextTokens !== undefined && `${formatTokensShort(model.contextTokens)} context`].filter(fact => typeof fact === "string");
|
|
23
21
|
}
|
|
24
|
-
function PriceColumn({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
function PriceColumn({
|
|
23
|
+
model
|
|
24
|
+
}) {
|
|
25
|
+
const input = model.inputPerMillionMicroUsd;
|
|
26
|
+
const output = model.outputPerMillionMicroUsd;
|
|
27
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
28
|
+
className: "flex flex-col items-end font-mono text-[11px] text-muted-foreground tabular-nums",
|
|
29
|
+
children: [input !== undefined && /*#__PURE__*/_jsxs("span", {
|
|
30
|
+
children: [formatMicroUsd(input), " in"]
|
|
31
|
+
}), output !== undefined && /*#__PURE__*/_jsxs("span", {
|
|
32
|
+
children: [formatMicroUsd(output), " out"]
|
|
33
|
+
})]
|
|
34
|
+
});
|
|
28
35
|
}
|
|
29
|
-
export function ModelOptionRow({
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
export function ModelOptionRow({
|
|
37
|
+
model
|
|
38
|
+
}) {
|
|
39
|
+
const facts = modelFacts(model);
|
|
40
|
+
return /*#__PURE__*/_jsxs(DropdownMenuRadioItem, {
|
|
41
|
+
value: model.id,
|
|
42
|
+
"data-slot": "model-picker-item",
|
|
43
|
+
className: "group grid grid-cols-[1fr_auto_1rem] items-center gap-x-3 rounded-none px-3 py-2.5 transition-colors duration-150 focus:bg-accent/50 data-[state=checked]:bg-accent motion-reduce:transition-none [&>span:first-child]:hidden",
|
|
44
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
45
|
+
className: "flex min-w-0 flex-col gap-0.5",
|
|
46
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
47
|
+
className: "flex items-baseline gap-2",
|
|
48
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
49
|
+
className: "truncate font-medium",
|
|
50
|
+
children: model.name
|
|
51
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
52
|
+
className: "truncate text-xs text-muted-foreground",
|
|
53
|
+
children: model.provider
|
|
54
|
+
})]
|
|
55
|
+
}), facts.length > 0 && /*#__PURE__*/_jsx("span", {
|
|
56
|
+
className: "font-mono text-[11px] text-muted-foreground tabular-nums",
|
|
57
|
+
children: facts.join(" · ")
|
|
58
|
+
})]
|
|
59
|
+
}), /*#__PURE__*/_jsx(PriceColumn, {
|
|
60
|
+
model: model
|
|
61
|
+
}), /*#__PURE__*/_jsx(CheckIcon, {
|
|
62
|
+
"aria-hidden": true,
|
|
63
|
+
className: "size-4 text-foreground opacity-0 group-data-[state=checked]:opacity-100"
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
32
66
|
}
|
|
@@ -1,34 +1,77 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { cn } from "@locusgraph/components";
|
|
3
2
|
import { formatMicroUsd } from "@locusgraph/utils";
|
|
4
3
|
import { formatDuration } from "./usage-totals.js";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
export function isWastedStep(step) {
|
|
6
|
-
|
|
6
|
+
return step.status === "failed" || step.usage.failed === true;
|
|
7
7
|
}
|
|
8
8
|
function barTone(step) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (step.status === "running")
|
|
14
|
-
return "bg-warn/60 motion-safe:animate-pulse";
|
|
15
|
-
return "bg-primary/35";
|
|
9
|
+
if (isWastedStep(step)) return "bg-destructive";
|
|
10
|
+
if (step.status === "retried") return "bg-warn/40";
|
|
11
|
+
if (step.status === "running") return "bg-warn/60 motion-safe:animate-pulse";
|
|
12
|
+
return "bg-primary/35";
|
|
16
13
|
}
|
|
17
14
|
const statusMark = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
failed: {
|
|
16
|
+
text: "Failed",
|
|
17
|
+
className: "text-destructive"
|
|
18
|
+
},
|
|
19
|
+
retried: {
|
|
20
|
+
text: "Retried",
|
|
21
|
+
className: "text-warn"
|
|
22
|
+
},
|
|
23
|
+
running: {
|
|
24
|
+
text: "Running",
|
|
25
|
+
className: "text-muted-foreground"
|
|
26
|
+
},
|
|
27
|
+
skipped: {
|
|
28
|
+
text: "Skipped",
|
|
29
|
+
className: "text-muted-foreground"
|
|
30
|
+
}
|
|
22
31
|
};
|
|
23
32
|
function barWidth(cost, maxCost) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return Math.max((cost / maxCost) * 100, cost > 0 ? 2 : 0);
|
|
33
|
+
if (maxCost <= 0) return 0;
|
|
34
|
+
return Math.max(cost / maxCost * 100, cost > 0 ? 2 : 0);
|
|
27
35
|
}
|
|
28
|
-
export function StepCostRow({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
export function StepCostRow({
|
|
37
|
+
step,
|
|
38
|
+
maxCost,
|
|
39
|
+
totalCost
|
|
40
|
+
}) {
|
|
41
|
+
const cost = step.usage.costMicroUsd;
|
|
42
|
+
const wasted = isWastedStep(step);
|
|
43
|
+
const share = totalCost > 0 ? Math.round(cost / totalCost * 100) : 0;
|
|
44
|
+
const mark = wasted ? statusMark.failed : statusMark[step.status];
|
|
45
|
+
return /*#__PURE__*/_jsxs("li", {
|
|
46
|
+
"data-slot": "step-cost-row",
|
|
47
|
+
"data-status": step.status,
|
|
48
|
+
"data-wasted": wasted || undefined,
|
|
49
|
+
"aria-label": `${step.title}: ${formatMicroUsd(cost)}, ${share}% of run${mark ? `, ${mark.text.toLowerCase()}` : ""}`,
|
|
50
|
+
className: "grid grid-cols-[minmax(0,11rem)_1fr_3.5rem_4.5rem] items-center gap-x-4 gap-y-1.5 px-5 py-2.5 text-sm tabular-nums max-sm:grid-cols-[1fr_auto_auto]",
|
|
51
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
52
|
+
className: "flex min-w-0 items-baseline gap-2",
|
|
53
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
54
|
+
className: cn("truncate", step.status === "skipped" && "text-muted-foreground"),
|
|
55
|
+
children: step.title
|
|
56
|
+
}), mark && /*#__PURE__*/_jsx("span", {
|
|
57
|
+
className: cn("shrink-0 font-mono text-[11px] tracking-wide uppercase", mark.className),
|
|
58
|
+
children: mark.text
|
|
59
|
+
})]
|
|
60
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
61
|
+
"aria-hidden": true,
|
|
62
|
+
className: "relative h-1.5 w-full bg-muted-foreground/10 max-sm:col-span-3 max-sm:row-start-2",
|
|
63
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
64
|
+
className: cn("absolute inset-y-0 left-0 transition-[width] duration-300 motion-reduce:transition-none", barTone(step)),
|
|
65
|
+
style: {
|
|
66
|
+
width: `${barWidth(cost, maxCost)}%`
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
70
|
+
className: "text-right font-mono text-[11px] text-muted-foreground",
|
|
71
|
+
children: step.durationMs !== undefined ? formatDuration(step.durationMs) : ""
|
|
72
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
73
|
+
className: cn("text-right font-mono text-xs", wasted && "text-destructive"),
|
|
74
|
+
children: formatMicroUsd(cost)
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
34
77
|
}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
export function sumUsage(attempts) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return attempts.reduce((totals, attempt) => ({
|
|
3
|
+
inputTokens: totals.inputTokens + attempt.inputTokens,
|
|
4
|
+
outputTokens: totals.outputTokens + attempt.outputTokens,
|
|
5
|
+
costMicroUsd: totals.costMicroUsd + attempt.costMicroUsd,
|
|
6
|
+
wastedMicroUsd: totals.wastedMicroUsd + (attempt.failed ? attempt.costMicroUsd : 0),
|
|
7
|
+
failedAttempts: totals.failedAttempts + (attempt.failed ? 1 : 0)
|
|
8
|
+
}), {
|
|
9
|
+
inputTokens: 0,
|
|
10
|
+
outputTokens: 0,
|
|
11
|
+
costMicroUsd: 0,
|
|
12
|
+
wastedMicroUsd: 0,
|
|
13
|
+
failedAttempts: 0
|
|
14
|
+
});
|
|
9
15
|
}
|
|
10
16
|
const compactCount = new Intl.NumberFormat("en-US", {
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
notation: "compact",
|
|
18
|
+
maximumFractionDigits: 1
|
|
13
19
|
});
|
|
14
20
|
export function formatTokensShort(tokens) {
|
|
15
|
-
|
|
21
|
+
return compactCount.format(tokens);
|
|
16
22
|
}
|
|
17
23
|
export function formatDuration(durationMs) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const remainder = Math.round(seconds % 60);
|
|
25
|
-
return `${minutes}m ${String(remainder).padStart(2, "0")}s`;
|
|
24
|
+
if (durationMs < 1000) return `${Math.round(durationMs)}ms`;
|
|
25
|
+
const seconds = durationMs / 1000;
|
|
26
|
+
if (seconds < 60) return `${seconds.toFixed(1)}s`;
|
|
27
|
+
const minutes = Math.floor(seconds / 60);
|
|
28
|
+
const remainder = Math.round(seconds % 60);
|
|
29
|
+
return `${minutes}m ${String(remainder).padStart(2, "0")}s`;
|
|
26
30
|
}
|
package/dist/memory/cite.js
CHANGED
|
@@ -1,19 +1,69 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { cn, HoverCard, HoverCardContent, HoverCardTrigger } from "@locusgraph/components";
|
|
3
2
|
import { hostLabel } from "./shared/host-label.js";
|
|
4
3
|
import { SourceMark } from "./shared/source-mark.js";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
const pillClass = "inline-flex h-4 min-w-4 items-center justify-center bg-muted px-1 font-mono text-[11px] leading-none font-medium text-foreground/80 tabular-nums no-underline ring-1 ring-border transition-colors duration-150 outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-reduce:transition-none";
|
|
6
6
|
export function citationLabel(citation) {
|
|
7
|
-
|
|
7
|
+
return `Source ${citation.index}: ${citation.title}`;
|
|
8
8
|
}
|
|
9
|
-
export function Cite({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
export function Cite({
|
|
10
|
+
citation,
|
|
11
|
+
onOpen,
|
|
12
|
+
className
|
|
13
|
+
}) {
|
|
14
|
+
const host = hostLabel(citation.url);
|
|
15
|
+
const label = citationLabel(citation);
|
|
16
|
+
const open = event => {
|
|
17
|
+
if (!onOpen) return;
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
onOpen(citation);
|
|
20
|
+
};
|
|
21
|
+
return /*#__PURE__*/_jsx("sup", {
|
|
22
|
+
"data-slot": "cite",
|
|
23
|
+
"data-index": citation.index,
|
|
24
|
+
className: cn("relative -top-1 ml-0.5 align-baseline leading-none", className),
|
|
25
|
+
children: /*#__PURE__*/_jsxs(HoverCard, {
|
|
26
|
+
openDelay: 150,
|
|
27
|
+
closeDelay: 100,
|
|
28
|
+
children: [/*#__PURE__*/_jsx(HoverCardTrigger, {
|
|
29
|
+
asChild: true,
|
|
30
|
+
children: citation.url ? /*#__PURE__*/_jsx("a", {
|
|
31
|
+
href: citation.url,
|
|
32
|
+
target: "_blank",
|
|
33
|
+
rel: "noreferrer",
|
|
34
|
+
"aria-label": label,
|
|
35
|
+
onClick: open,
|
|
36
|
+
className: pillClass,
|
|
37
|
+
children: citation.index
|
|
38
|
+
}) : /*#__PURE__*/_jsx("button", {
|
|
39
|
+
type: "button",
|
|
40
|
+
"aria-label": label,
|
|
41
|
+
onClick: open,
|
|
42
|
+
className: pillClass,
|
|
43
|
+
children: citation.index
|
|
44
|
+
})
|
|
45
|
+
}), /*#__PURE__*/_jsxs(HoverCardContent, {
|
|
46
|
+
"data-slot": "cite-card",
|
|
47
|
+
side: "bottom",
|
|
48
|
+
align: "start",
|
|
49
|
+
sideOffset: 6,
|
|
50
|
+
className: "flex w-72 flex-col gap-2 rounded-none border-0 p-4 ring-1 ring-border",
|
|
51
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
52
|
+
className: "eyebrow flex min-w-0 items-center gap-2",
|
|
53
|
+
children: [/*#__PURE__*/_jsx(SourceMark, {
|
|
54
|
+
citation: citation
|
|
55
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
56
|
+
className: "truncate",
|
|
57
|
+
children: host ?? "Source"
|
|
58
|
+
})]
|
|
59
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
60
|
+
className: "text-sm leading-snug font-medium",
|
|
61
|
+
children: citation.title
|
|
62
|
+
}), citation.snippet && /*#__PURE__*/_jsx("p", {
|
|
63
|
+
className: "line-clamp-4 text-xs leading-relaxed text-muted-foreground",
|
|
64
|
+
children: citation.snippet
|
|
65
|
+
})]
|
|
66
|
+
})]
|
|
67
|
+
})
|
|
68
|
+
});
|
|
19
69
|
}
|
package/dist/memory/memorized.js
CHANGED
|
@@ -1,19 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BookmarkAdd as BookmarkPlusIcon, Checkmark as CheckIcon, Undo as Undo2Icon, } from "@carbon/icons-react";
|
|
1
|
+
import { BookmarkAdd as BookmarkPlusIcon, Checkmark as CheckIcon, Undo as Undo2Icon } from "@carbon/icons-react";
|
|
3
2
|
import { Button, cn } from "@locusgraph/components";
|
|
4
3
|
import { pluralize } from "@locusgraph/utils";
|
|
5
4
|
import { StatusDot } from "../shared/status-dot.js";
|
|
6
5
|
import { eyebrowClass, ruledListClass } from "./shared/disclosure.js";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
7
|
export function memorizedSummary(items) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const saved = items.filter(item => item.status === "saved").length;
|
|
9
|
+
return `Saved ${pluralize(saved, "memory", "memories")}`;
|
|
10
10
|
}
|
|
11
|
-
export function Memorized({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export function Memorized({
|
|
12
|
+
items,
|
|
13
|
+
onUndo,
|
|
14
|
+
className
|
|
15
|
+
}) {
|
|
16
|
+
if (items.length === 0) return null;
|
|
17
|
+
return /*#__PURE__*/_jsxs("section", {
|
|
18
|
+
"data-slot": "memorized",
|
|
19
|
+
"aria-label": "Saved to memory",
|
|
20
|
+
className: cn("flex min-w-0 flex-col gap-2", className),
|
|
21
|
+
children: [/*#__PURE__*/_jsxs("header", {
|
|
22
|
+
"aria-live": "polite",
|
|
23
|
+
className: cn("flex items-center gap-2 py-1", eyebrowClass),
|
|
24
|
+
children: [/*#__PURE__*/_jsx(BookmarkPlusIcon, {
|
|
25
|
+
"aria-hidden": true
|
|
26
|
+
}), memorizedSummary(items)]
|
|
27
|
+
}), /*#__PURE__*/_jsx("ul", {
|
|
28
|
+
className: ruledListClass,
|
|
29
|
+
children: items.map(item => /*#__PURE__*/_jsx(MemorizedRow, {
|
|
30
|
+
item: item,
|
|
31
|
+
onUndo: onUndo
|
|
32
|
+
}, item.id))
|
|
33
|
+
})]
|
|
34
|
+
});
|
|
15
35
|
}
|
|
16
|
-
function MemorizedRow({
|
|
17
|
-
|
|
18
|
-
|
|
36
|
+
function MemorizedRow({
|
|
37
|
+
item,
|
|
38
|
+
onUndo
|
|
39
|
+
}) {
|
|
40
|
+
const undone = item.status === "undone";
|
|
41
|
+
return /*#__PURE__*/_jsxs("li", {
|
|
42
|
+
"data-slot": "memorized-item",
|
|
43
|
+
"data-status": item.status,
|
|
44
|
+
className: "flex min-h-11 items-center gap-3 px-3 py-2.5",
|
|
45
|
+
children: [/*#__PURE__*/_jsx(CheckIcon, {
|
|
46
|
+
"aria-hidden": true,
|
|
47
|
+
className: cn("size-3.5 shrink-0", undone ? "text-muted-foreground/40" : "text-good")
|
|
48
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
49
|
+
className: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
50
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
51
|
+
className: cn("text-sm font-medium", undone && "font-normal text-muted-foreground line-through decoration-muted-foreground"),
|
|
52
|
+
children: item.text
|
|
53
|
+
}), item.kind && /*#__PURE__*/_jsx("span", {
|
|
54
|
+
className: "font-mono text-xs text-muted-foreground",
|
|
55
|
+
children: item.kind
|
|
56
|
+
})]
|
|
57
|
+
}), undone ? /*#__PURE__*/_jsxs("span", {
|
|
58
|
+
className: "eyebrow flex shrink-0 items-center gap-1.5",
|
|
59
|
+
children: [/*#__PURE__*/_jsx(StatusDot, {
|
|
60
|
+
tone: "idle"
|
|
61
|
+
}), "Undone"]
|
|
62
|
+
}) : onUndo && /*#__PURE__*/_jsxs(Button, {
|
|
63
|
+
variant: "ghost",
|
|
64
|
+
size: "xs",
|
|
65
|
+
className: "-mr-2 text-muted-foreground hover:text-foreground",
|
|
66
|
+
"aria-label": `Undo saving ${item.text}`,
|
|
67
|
+
onClick: () => onUndo(item.id),
|
|
68
|
+
children: [/*#__PURE__*/_jsx(Undo2Icon, {
|
|
69
|
+
"aria-hidden": true
|
|
70
|
+
}), "Undo"]
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
19
73
|
}
|
package/dist/memory/recall.js
CHANGED
|
@@ -1,24 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChevronRight as ChevronRightIcon, RecentlyViewed as HistoryIcon, } from "@carbon/icons-react";
|
|
1
|
+
import { ChevronRight as ChevronRightIcon, RecentlyViewed as HistoryIcon } from "@carbon/icons-react";
|
|
3
2
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger, cn } from "@locusgraph/components";
|
|
4
3
|
import { pluralize } from "@locusgraph/utils";
|
|
5
|
-
import { chevronClass, collapsibleTriggerClass, interactiveRowClass, ruledListClass
|
|
4
|
+
import { chevronClass, collapsibleTriggerClass, interactiveRowClass, ruledListClass } from "./shared/disclosure.js";
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
6
|
export function relevancePercent(relevance) {
|
|
7
|
-
|
|
7
|
+
return Math.round(Math.min(Math.max(relevance, 0), 1) * 100);
|
|
8
8
|
}
|
|
9
|
-
export function Recall({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export function Recall({
|
|
10
|
+
memories,
|
|
11
|
+
onOpenMemory,
|
|
12
|
+
defaultOpen = false,
|
|
13
|
+
className
|
|
14
|
+
}) {
|
|
15
|
+
if (memories.length === 0) return null;
|
|
16
|
+
return /*#__PURE__*/_jsxs(Collapsible, {
|
|
17
|
+
"data-slot": "recall",
|
|
18
|
+
defaultOpen: defaultOpen,
|
|
19
|
+
className: cn("flex min-w-0 flex-col gap-2", className),
|
|
20
|
+
children: [/*#__PURE__*/_jsxs(CollapsibleTrigger, {
|
|
21
|
+
className: collapsibleTriggerClass,
|
|
22
|
+
children: [/*#__PURE__*/_jsx(HistoryIcon, {
|
|
23
|
+
"aria-hidden": true
|
|
24
|
+
}), "Recalled ", pluralize(memories.length, "memory", "memories"), /*#__PURE__*/_jsx(ChevronRightIcon, {
|
|
25
|
+
"aria-hidden": true,
|
|
26
|
+
className: chevronClass
|
|
27
|
+
})]
|
|
28
|
+
}), /*#__PURE__*/_jsx(CollapsibleContent, {
|
|
29
|
+
children: /*#__PURE__*/_jsx("ul", {
|
|
30
|
+
className: ruledListClass,
|
|
31
|
+
children: memories.map(memory => /*#__PURE__*/_jsx(RecallRow, {
|
|
32
|
+
memory: memory,
|
|
33
|
+
onOpenMemory: onOpenMemory
|
|
34
|
+
}, memory.id))
|
|
35
|
+
})
|
|
36
|
+
})]
|
|
37
|
+
});
|
|
13
38
|
}
|
|
14
|
-
function RelevanceMeter({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
function RelevanceMeter({
|
|
40
|
+
memory
|
|
41
|
+
}) {
|
|
42
|
+
if (memory.relevance === undefined) return null;
|
|
43
|
+
const percent = relevancePercent(memory.relevance);
|
|
44
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
45
|
+
className: "flex shrink-0 items-center gap-2",
|
|
46
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
47
|
+
role: "meter",
|
|
48
|
+
"aria-label": `Relevance of ${memory.label}`,
|
|
49
|
+
"aria-valuemin": 0,
|
|
50
|
+
"aria-valuemax": 100,
|
|
51
|
+
"aria-valuenow": percent,
|
|
52
|
+
"aria-valuetext": `${percent}% relevant`,
|
|
53
|
+
className: "relative h-[3px] w-10 overflow-hidden bg-muted",
|
|
54
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
55
|
+
className: "absolute inset-y-0 left-0 bg-foreground/60 transition-[width] duration-300 motion-reduce:transition-none",
|
|
56
|
+
style: {
|
|
57
|
+
width: `${percent}%`
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
61
|
+
className: "w-8 text-right font-mono text-xs text-muted-foreground tabular-nums",
|
|
62
|
+
children: [percent, "%"]
|
|
63
|
+
})]
|
|
64
|
+
});
|
|
19
65
|
}
|
|
20
|
-
function RecallRow({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
66
|
+
function RecallRow({
|
|
67
|
+
memory,
|
|
68
|
+
onOpenMemory
|
|
69
|
+
}) {
|
|
70
|
+
const content = /*#__PURE__*/_jsxs(_Fragment, {
|
|
71
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
72
|
+
className: "flex w-full items-baseline gap-3",
|
|
73
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
74
|
+
className: "min-w-0 flex-1 truncate text-sm font-medium",
|
|
75
|
+
children: memory.label
|
|
76
|
+
}), /*#__PURE__*/_jsx(RelevanceMeter, {
|
|
77
|
+
memory: memory
|
|
78
|
+
})]
|
|
79
|
+
}), (memory.kind || memory.snippet) && /*#__PURE__*/_jsxs("span", {
|
|
80
|
+
className: "flex w-full gap-2 text-xs text-muted-foreground",
|
|
81
|
+
children: [memory.kind && /*#__PURE__*/_jsx("span", {
|
|
82
|
+
className: "shrink-0 font-mono",
|
|
83
|
+
children: memory.kind
|
|
84
|
+
}), memory.kind && memory.snippet && /*#__PURE__*/_jsx("span", {
|
|
85
|
+
"aria-hidden": true,
|
|
86
|
+
children: "\xB7"
|
|
87
|
+
}), memory.snippet && /*#__PURE__*/_jsx("span", {
|
|
88
|
+
className: "line-clamp-2 min-w-0",
|
|
89
|
+
children: memory.snippet
|
|
90
|
+
})]
|
|
91
|
+
})]
|
|
92
|
+
});
|
|
93
|
+
const rowClass = "flex w-full flex-col items-start gap-1 px-3 py-2.5 text-left";
|
|
94
|
+
return /*#__PURE__*/_jsx("li", {
|
|
95
|
+
"data-slot": "recall-item",
|
|
96
|
+
"data-id": memory.id,
|
|
97
|
+
children: onOpenMemory ? /*#__PURE__*/_jsx("button", {
|
|
98
|
+
type: "button",
|
|
99
|
+
"aria-label": `Open memory ${memory.label}`,
|
|
100
|
+
onClick: () => onOpenMemory(memory.id),
|
|
101
|
+
className: cn(rowClass, interactiveRowClass),
|
|
102
|
+
children: content
|
|
103
|
+
}) : /*#__PURE__*/_jsx("div", {
|
|
104
|
+
className: rowClass,
|
|
105
|
+
children: content
|
|
106
|
+
})
|
|
107
|
+
});
|
|
24
108
|
}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
export function hostLabel(url) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return url;
|
|
9
|
-
}
|
|
2
|
+
if (!url) return undefined;
|
|
3
|
+
try {
|
|
4
|
+
return new URL(url).host.replace(/^www\./, "");
|
|
5
|
+
} catch {
|
|
6
|
+
return url;
|
|
7
|
+
}
|
|
10
8
|
}
|
|
11
9
|
function isSourceUrlPart(item) {
|
|
12
|
-
|
|
10
|
+
return "type" in item && item.type === "source-url";
|
|
13
11
|
}
|
|
14
12
|
export function toCitation(item, position) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
13
|
+
if (!isSourceUrlPart(item)) return item;
|
|
14
|
+
return {
|
|
15
|
+
index: position + 1,
|
|
16
|
+
title: item.title ?? hostLabel(item.url) ?? item.url,
|
|
17
|
+
url: item.url
|
|
18
|
+
};
|
|
22
19
|
}
|
|
23
20
|
export function sourceKey(item, position) {
|
|
24
|
-
|
|
21
|
+
return isSourceUrlPart(item) ? item.sourceId : `${item.index}:${position}`;
|
|
25
22
|
}
|
|
26
23
|
function siteNameOf(host) {
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const labels = host.split(".");
|
|
25
|
+
return labels.length > 2 ? labels.slice(-2).join(".") : host;
|
|
29
26
|
}
|
|
30
27
|
export function sourceInitial(citation) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const host = hostLabel(citation.url);
|
|
29
|
+
const name = host ? siteNameOf(host) : citation.title;
|
|
30
|
+
return name.trim().charAt(0).toUpperCase() || "?";
|
|
34
31
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import { cn } from "@locusgraph/components";
|
|
3
2
|
import { sourceInitial } from "./host-label.js";
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export function SourceMark({
|
|
5
|
+
citation,
|
|
6
|
+
className
|
|
7
|
+
}) {
|
|
8
|
+
return /*#__PURE__*/_jsx("span", {
|
|
9
|
+
"aria-hidden": true,
|
|
10
|
+
"data-slot": "source-mark",
|
|
11
|
+
className: cn("flex size-4 shrink-0 items-center justify-center bg-muted font-mono text-[11px] leading-none font-medium text-muted-foreground ring-1 ring-border", className),
|
|
12
|
+
children: sourceInitial(citation)
|
|
13
|
+
});
|
|
6
14
|
}
|