@locusgraph/loop 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +2 -0
  2. package/dist/agent/pulse/gradient-label.js +36 -15
  3. package/dist/agent/pulse/marks/bars-mark.js +24 -10
  4. package/dist/agent/pulse/marks/glyph-mark.js +17 -11
  5. package/dist/agent/pulse/marks/locus-mark.js +39 -28
  6. package/dist/agent/pulse/marks/orb-mark.js +21 -8
  7. package/dist/agent/pulse/marks/spinner-mark.js +20 -1
  8. package/dist/agent/pulse/pulse.js +63 -35
  9. package/dist/agent/pulse/use-loop-animation.js +14 -16
  10. package/dist/agent/steps/step-icon.js +40 -24
  11. package/dist/agent/steps/steps.js +72 -25
  12. package/dist/agent/thinking/thinking.js +203 -23
  13. package/dist/agent/thinking/thought-duration.js +7 -9
  14. package/dist/agent/tool/json-block.js +18 -11
  15. package/dist/agent/tool/tool-status.js +28 -18
  16. package/dist/agent/tool/tool.js +184 -6
  17. package/dist/approval/inbox/inbox-row.d.ts +3 -2
  18. package/dist/approval/inbox/inbox-row.js +96 -7
  19. package/dist/approval/inbox/inbox-selection.js +7 -13
  20. package/dist/approval/inbox/inbox.d.ts +2 -1
  21. package/dist/approval/inbox/inbox.js +99 -18
  22. package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
  23. package/dist/approval/inbox/virtual-inbox-list.js +53 -0
  24. package/dist/approval/memory/memory-choices.js +27 -22
  25. package/dist/approval/memory/memory-review.js +108 -17
  26. package/dist/approval/memory/memory-row.js +80 -19
  27. package/dist/approval/plan/plan-review.js +129 -28
  28. package/dist/approval/plan/plan-step-row.js +91 -44
  29. package/dist/approval/plan/plan-steps.js +24 -23
  30. package/dist/approval/plan/question-choices.js +73 -40
  31. package/dist/approval/plan/question.d.ts +1 -1
  32. package/dist/approval/plan/question.js +108 -27
  33. package/dist/approval/run/run-bar.js +94 -22
  34. package/dist/approval/shared/decision-line.js +1 -1
  35. package/dist/approval/shared/risk-badge.js +32 -16
  36. package/dist/approval/shared/time.js +5 -8
  37. package/dist/approval/shared/use-focus-on-mount.js +7 -6
  38. package/dist/approval/spend/raise-cap-form.js +64 -19
  39. package/dist/approval/spend/spend-gate.js +124 -21
  40. package/dist/approval/spend/spend-math.js +7 -8
  41. package/dist/approval/spend/spend-meter.js +136 -35
  42. package/dist/approval/tool/approval.js +113 -27
  43. package/dist/approval/tool/args/args-editor.js +104 -26
  44. package/dist/approval/tool/args/args-field.js +79 -22
  45. package/dist/approval/tool/args/args-validation.js +38 -47
  46. package/dist/approval/tool/deny-form.js +43 -10
  47. package/dist/approval/tool/tool-inputs.js +62 -38
  48. package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
  49. package/dist/chat/chat/chat-item-spacing.js +19 -0
  50. package/dist/chat/chat/chat.d.ts +2 -1
  51. package/dist/chat/chat/chat.js +181 -5
  52. package/dist/chat/chat/use-stick-to-bottom.js +71 -48
  53. package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
  54. package/dist/chat/chat/virtual-chat-items.js +60 -0
  55. package/dist/chat/composer/composer-actions.js +69 -17
  56. package/dist/chat/composer/composer.js +330 -32
  57. package/dist/chat/composer/use-auto-grow.js +9 -9
  58. package/dist/chat/files/file-meta.js +19 -19
  59. package/dist/chat/files/files.js +92 -29
  60. package/dist/chat/reply/fenced-code.js +23 -21
  61. package/dist/chat/reply/markdown-components.js +137 -17
  62. package/dist/chat/reply/reply.js +30 -10
  63. package/dist/chat/turn/group-parts.js +43 -29
  64. package/dist/chat/turn/turn.js +87 -30
  65. package/dist/cost/context.js +104 -23
  66. package/dist/cost/cost-steps.js +67 -14
  67. package/dist/cost/cost.js +128 -23
  68. package/dist/cost/model-picker.js +51 -6
  69. package/dist/cost/shared/context-breakdown.js +83 -10
  70. package/dist/cost/shared/meter-marks.js +49 -9
  71. package/dist/cost/shared/model-option-row.js +56 -22
  72. package/dist/cost/shared/step-cost-row.js +65 -22
  73. package/dist/cost/shared/usage-totals.js +22 -18
  74. package/dist/memory/cite.js +62 -12
  75. package/dist/memory/memorized.js +65 -11
  76. package/dist/memory/recall.js +101 -17
  77. package/dist/memory/shared/host-label.js +19 -22
  78. package/dist/memory/shared/source-mark.js +11 -3
  79. package/dist/memory/sources.js +78 -14
  80. package/dist/shared/decision-summary.js +51 -14
  81. package/dist/shared/panel-empty.js +20 -3
  82. package/dist/shared/panel.js +69 -13
  83. package/dist/shared/status-dot.js +16 -8
  84. package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
  85. package/dist/shared/virtual/use-list-virtualizer.js +68 -0
  86. package/dist/thread/actions/action-button.js +22 -3
  87. package/dist/thread/actions/actions.js +184 -13
  88. package/dist/thread/actions/branch-switcher.js +28 -5
  89. package/dist/thread/canvas/canvas.js +205 -5
  90. package/dist/thread/canvas/version-switcher.js +54 -8
  91. package/dist/thread/code/code.js +186 -24
  92. package/dist/thread/code/copy-code-button.js +30 -14
  93. package/dist/thread/code/highlight.js +30 -29
  94. package/dist/thread/history/history-rows.d.ts +16 -0
  95. package/dist/thread/history/history-rows.js +23 -0
  96. package/dist/thread/history/history.d.ts +3 -2
  97. package/dist/thread/history/history.js +174 -5
  98. package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
  99. package/dist/thread/history/row/history-row.js +58 -0
  100. package/dist/thread/history/row/thread-item-menu.js +31 -0
  101. package/dist/thread/history/row/thread-title-editor.js +38 -0
  102. package/dist/thread/history/thread-groups.d.ts +1 -1
  103. package/dist/thread/history/thread-groups.js +40 -34
  104. package/dist/thread/history/virtual-history-list.d.ts +11 -0
  105. package/dist/thread/history/virtual-history-list.js +71 -0
  106. package/dist/thread/index.d.ts +1 -1
  107. package/dist/thread/starters/starters.js +33 -8
  108. package/dist/thread/use-copied.js +18 -16
  109. package/dist/types.js +1 -1
  110. package/package.json +6 -4
  111. package/dist/thread/history/history-row.js +0 -17
  112. package/dist/thread/history/thread-item-menu.js +0 -6
  113. package/dist/thread/history/thread-title-editor.js +0 -25
  114. /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
  115. /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
@@ -1,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
- const speedLabel = { fast: "Fast", balanced: "Balanced", deep: "Deep" };
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
- const input = model.inputPerMillionMicroUsd;
9
- const output = model.outputPerMillionMicroUsd;
10
- if (input === undefined && output === undefined)
11
- return undefined;
12
- if (output === undefined)
13
- return `${formatMicroUsd(input ?? 0)} / 1M in`;
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
- return [
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({ model }) {
25
- const input = model.inputPerMillionMicroUsd;
26
- const output = model.outputPerMillionMicroUsd;
27
- return (_jsxs("span", { className: "flex flex-col items-end font-mono text-[11px] text-muted-foreground tabular-nums", children: [input !== undefined && _jsxs("span", { children: [formatMicroUsd(input), " in"] }), output !== undefined && _jsxs("span", { children: [formatMicroUsd(output), " out"] })] }));
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({ model }) {
30
- const facts = modelFacts(model);
31
- return (_jsxs(DropdownMenuRadioItem, { value: model.id, "data-slot": "model-picker-item", 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", children: [_jsxs("span", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("span", { className: "flex items-baseline gap-2", children: [_jsx("span", { className: "truncate font-medium", children: model.name }), _jsx("span", { className: "truncate text-xs text-muted-foreground", children: model.provider })] }), facts.length > 0 && (_jsx("span", { className: "font-mono text-[11px] text-muted-foreground tabular-nums", children: facts.join(" · ") }))] }), _jsx(PriceColumn, { model: model }), _jsx(CheckIcon, { "aria-hidden": true, className: "size-4 text-foreground opacity-0 group-data-[state=checked]:opacity-100" })] }));
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
- return step.status === "failed" || step.usage.failed === true;
6
+ return step.status === "failed" || step.usage.failed === true;
7
7
  }
8
8
  function barTone(step) {
9
- if (isWastedStep(step))
10
- return "bg-destructive";
11
- if (step.status === "retried")
12
- return "bg-warn/40";
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
- failed: { text: "Failed", className: "text-destructive" },
19
- retried: { text: "Retried", className: "text-warn" },
20
- running: { text: "Running", className: "text-muted-foreground" },
21
- skipped: { text: "Skipped", className: "text-muted-foreground" },
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
- if (maxCost <= 0)
25
- return 0;
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({ step, maxCost, totalCost, }) {
29
- const cost = step.usage.costMicroUsd;
30
- const wasted = isWastedStep(step);
31
- const share = totalCost > 0 ? Math.round((cost / totalCost) * 100) : 0;
32
- const mark = wasted ? statusMark.failed : statusMark[step.status];
33
- return (_jsxs("li", { "data-slot": "step-cost-row", "data-status": step.status, "data-wasted": wasted || undefined, "aria-label": `${step.title}: ${formatMicroUsd(cost)}, ${share}% of run${mark ? `, ${mark.text.toLowerCase()}` : ""}`, 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]", children: [_jsxs("span", { className: "flex min-w-0 items-baseline gap-2", children: [_jsx("span", { className: cn("truncate", step.status === "skipped" && "text-muted-foreground"), children: step.title }), mark && (_jsx("span", { className: cn("shrink-0 font-mono text-[11px] tracking-wide uppercase", mark.className), children: mark.text }))] }), _jsx("span", { "aria-hidden": true, className: "relative h-1.5 w-full bg-muted-foreground/10 max-sm:col-span-3 max-sm:row-start-2", children: _jsx("span", { className: cn("absolute inset-y-0 left-0 transition-[width] duration-300 motion-reduce:transition-none", barTone(step)), style: { width: `${barWidth(cost, maxCost)}%` } }) }), _jsx("span", { className: "text-right font-mono text-[11px] text-muted-foreground", children: step.durationMs !== undefined ? formatDuration(step.durationMs) : "" }), _jsx("span", { className: cn("text-right font-mono text-xs", wasted && "text-destructive"), children: formatMicroUsd(cost) })] }));
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
- 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
- }), { inputTokens: 0, outputTokens: 0, costMicroUsd: 0, wastedMicroUsd: 0, failedAttempts: 0 });
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
- notation: "compact",
12
- maximumFractionDigits: 1,
17
+ notation: "compact",
18
+ maximumFractionDigits: 1
13
19
  });
14
20
  export function formatTokensShort(tokens) {
15
- return compactCount.format(tokens);
21
+ return compactCount.format(tokens);
16
22
  }
17
23
  export function formatDuration(durationMs) {
18
- if (durationMs < 1000)
19
- return `${Math.round(durationMs)}ms`;
20
- const seconds = durationMs / 1000;
21
- if (seconds < 60)
22
- return `${seconds.toFixed(1)}s`;
23
- const minutes = Math.floor(seconds / 60);
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
  }
@@ -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
- return `Source ${citation.index}: ${citation.title}`;
7
+ return `Source ${citation.index}: ${citation.title}`;
8
8
  }
9
- export function Cite({ citation, onOpen, className }) {
10
- const host = hostLabel(citation.url);
11
- const label = citationLabel(citation);
12
- const open = (event) => {
13
- if (!onOpen)
14
- return;
15
- event.preventDefault();
16
- onOpen(citation);
17
- };
18
- return (_jsx("sup", { "data-slot": "cite", "data-index": citation.index, className: cn("relative -top-1 ml-0.5 align-baseline leading-none", className), children: _jsxs(HoverCard, { openDelay: 150, closeDelay: 100, children: [_jsx(HoverCardTrigger, { asChild: true, children: citation.url ? (_jsx("a", { href: citation.url, target: "_blank", rel: "noreferrer", "aria-label": label, onClick: open, className: pillClass, children: citation.index })) : (_jsx("button", { type: "button", "aria-label": label, onClick: open, className: pillClass, children: citation.index })) }), _jsxs(HoverCardContent, { "data-slot": "cite-card", side: "bottom", align: "start", sideOffset: 6, className: "flex w-72 flex-col gap-2 rounded-none border-0 p-4 ring-1 ring-border", children: [_jsxs("span", { className: "eyebrow flex min-w-0 items-center gap-2", children: [_jsx(SourceMark, { citation: citation }), _jsx("span", { className: "truncate", children: host ?? "Source" })] }), _jsx("span", { className: "text-sm leading-snug font-medium", children: citation.title }), citation.snippet && (_jsx("p", { className: "line-clamp-4 text-xs leading-relaxed text-muted-foreground", children: citation.snippet }))] })] }) }));
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
  }
@@ -1,19 +1,73 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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
- const saved = items.filter((item) => item.status === "saved").length;
9
- return `Saved ${pluralize(saved, "memory", "memories")}`;
8
+ const saved = items.filter(item => item.status === "saved").length;
9
+ return `Saved ${pluralize(saved, "memory", "memories")}`;
10
10
  }
11
- export function Memorized({ items, onUndo, className }) {
12
- if (items.length === 0)
13
- return null;
14
- return (_jsxs("section", { "data-slot": "memorized", "aria-label": "Saved to memory", className: cn("flex min-w-0 flex-col gap-2", className), children: [_jsxs("header", { "aria-live": "polite", className: cn("flex items-center gap-2 py-1", eyebrowClass), children: [_jsx(BookmarkPlusIcon, { "aria-hidden": true }), memorizedSummary(items)] }), _jsx("ul", { className: ruledListClass, children: items.map((item) => (_jsx(MemorizedRow, { item: item, onUndo: onUndo }, item.id))) })] }));
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({ item, onUndo }) {
17
- const undone = item.status === "undone";
18
- return (_jsxs("li", { "data-slot": "memorized-item", "data-status": item.status, className: "flex min-h-11 items-center gap-3 px-3 py-2.5", children: [_jsx(CheckIcon, { "aria-hidden": true, className: cn("size-3.5 shrink-0", undone ? "text-muted-foreground/40" : "text-good") }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("span", { className: cn("text-sm font-medium", undone && "font-normal text-muted-foreground line-through decoration-muted-foreground"), children: item.text }), item.kind && _jsx("span", { className: "font-mono text-xs text-muted-foreground", children: item.kind })] }), undone ? (_jsxs("span", { className: "eyebrow flex shrink-0 items-center gap-1.5", children: [_jsx(StatusDot, { tone: "idle" }), "Undone"] })) : (onUndo && (_jsxs(Button, { variant: "ghost", size: "xs", className: "-mr-2 text-muted-foreground hover:text-foreground", "aria-label": `Undo saving ${item.text}`, onClick: () => onUndo(item.id), children: [_jsx(Undo2Icon, { "aria-hidden": true }), "Undo"] })))] }));
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
  }
@@ -1,24 +1,108 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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, } from "./shared/disclosure.js";
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
- return Math.round(Math.min(Math.max(relevance, 0), 1) * 100);
7
+ return Math.round(Math.min(Math.max(relevance, 0), 1) * 100);
8
8
  }
9
- export function Recall({ memories, onOpenMemory, defaultOpen = false, className }) {
10
- if (memories.length === 0)
11
- return null;
12
- return (_jsxs(Collapsible, { "data-slot": "recall", defaultOpen: defaultOpen, className: cn("flex min-w-0 flex-col gap-2", className), children: [_jsxs(CollapsibleTrigger, { className: collapsibleTriggerClass, children: [_jsx(HistoryIcon, { "aria-hidden": true }), "Recalled ", pluralize(memories.length, "memory", "memories"), _jsx(ChevronRightIcon, { "aria-hidden": true, className: chevronClass })] }), _jsx(CollapsibleContent, { children: _jsx("ul", { className: ruledListClass, children: memories.map((memory) => (_jsx(RecallRow, { memory: memory, onOpenMemory: onOpenMemory }, memory.id))) }) })] }));
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({ memory }) {
15
- if (memory.relevance === undefined)
16
- return null;
17
- const percent = relevancePercent(memory.relevance);
18
- return (_jsxs("span", { className: "flex shrink-0 items-center gap-2", children: [_jsx("span", { role: "meter", "aria-label": `Relevance of ${memory.label}`, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, "aria-valuetext": `${percent}% relevant`, className: "relative h-[3px] w-10 overflow-hidden bg-muted", children: _jsx("span", { className: "absolute inset-y-0 left-0 bg-foreground/60 transition-[width] duration-300 motion-reduce:transition-none", style: { width: `${percent}%` } }) }), _jsxs("span", { className: "w-8 text-right font-mono text-xs text-muted-foreground tabular-nums", children: [percent, "%"] })] }));
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({ memory, onOpenMemory, }) {
21
- const content = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "flex w-full items-baseline gap-3", children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-sm font-medium", children: memory.label }), _jsx(RelevanceMeter, { memory: memory })] }), (memory.kind || memory.snippet) && (_jsxs("span", { className: "flex w-full gap-2 text-xs text-muted-foreground", children: [memory.kind && _jsx("span", { className: "shrink-0 font-mono", children: memory.kind }), memory.kind && memory.snippet && _jsx("span", { "aria-hidden": true, children: "\u00B7" }), memory.snippet && _jsx("span", { className: "line-clamp-2 min-w-0", children: memory.snippet })] }))] }));
22
- const rowClass = "flex w-full flex-col items-start gap-1 px-3 py-2.5 text-left";
23
- return (_jsx("li", { "data-slot": "recall-item", "data-id": memory.id, children: onOpenMemory ? (_jsx("button", { type: "button", "aria-label": `Open memory ${memory.label}`, onClick: () => onOpenMemory(memory.id), className: cn(rowClass, interactiveRowClass), children: content })) : (_jsx("div", { className: rowClass, children: content })) }));
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
- if (!url)
3
- return undefined;
4
- try {
5
- return new URL(url).host.replace(/^www\./, "");
6
- }
7
- catch {
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
- return "type" in item && item.type === "source-url";
10
+ return "type" in item && item.type === "source-url";
13
11
  }
14
12
  export function toCitation(item, position) {
15
- if (!isSourceUrlPart(item))
16
- return item;
17
- return {
18
- index: position + 1,
19
- title: item.title ?? hostLabel(item.url) ?? item.url,
20
- url: item.url,
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
- return isSourceUrlPart(item) ? item.sourceId : `${item.index}:${position}`;
21
+ return isSourceUrlPart(item) ? item.sourceId : `${item.index}:${position}`;
25
22
  }
26
23
  function siteNameOf(host) {
27
- const labels = host.split(".");
28
- return labels.length > 2 ? labels.slice(-2).join(".") : host;
24
+ const labels = host.split(".");
25
+ return labels.length > 2 ? labels.slice(-2).join(".") : host;
29
26
  }
30
27
  export function sourceInitial(citation) {
31
- const host = hostLabel(citation.url);
32
- const name = host ? siteNameOf(host) : citation.title;
33
- return name.trim().charAt(0).toUpperCase() || "?";
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
- export function SourceMark({ citation, className }) {
5
- return (_jsx("span", { "aria-hidden": true, "data-slot": "source-mark", 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), children: sourceInitial(citation) }));
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
  }