@locusgraph/loop 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/dist/agent/index.d.ts +5 -0
  4. package/dist/agent/index.js +5 -0
  5. package/dist/agent/pulse/gradient-label.d.ts +7 -0
  6. package/dist/agent/pulse/gradient-label.js +23 -0
  7. package/dist/agent/pulse/marks/bars-mark.d.ts +1 -0
  8. package/dist/agent/pulse/marks/bars-mark.js +15 -0
  9. package/dist/agent/pulse/marks/glyph-mark.d.ts +4 -0
  10. package/dist/agent/pulse/marks/glyph-mark.js +17 -0
  11. package/dist/agent/pulse/marks/locus-mark.d.ts +1 -0
  12. package/dist/agent/pulse/marks/locus-mark.js +38 -0
  13. package/dist/agent/pulse/marks/orb-mark.d.ts +1 -0
  14. package/dist/agent/pulse/marks/orb-mark.js +11 -0
  15. package/dist/agent/pulse/marks/spinner-mark.d.ts +1 -0
  16. package/dist/agent/pulse/marks/spinner-mark.js +4 -0
  17. package/dist/agent/pulse/pulse-tone.d.ts +1 -0
  18. package/dist/agent/pulse/pulse-tone.js +1 -0
  19. package/dist/agent/pulse/pulse.d.ts +12 -0
  20. package/dist/agent/pulse/pulse.js +51 -0
  21. package/dist/agent/pulse/use-loop-animation.d.ts +2 -0
  22. package/dist/agent/pulse/use-loop-animation.js +21 -0
  23. package/dist/agent/shared/status-dot.d.ts +1 -0
  24. package/dist/agent/shared/status-dot.js +1 -0
  25. package/dist/agent/steps/step-icon.d.ts +8 -0
  26. package/dist/agent/steps/step-icon.js +31 -0
  27. package/dist/agent/steps/steps.d.ts +7 -0
  28. package/dist/agent/steps/steps.js +39 -0
  29. package/dist/agent/thinking/thinking.d.ts +6 -0
  30. package/dist/agent/thinking/thinking.js +31 -0
  31. package/dist/agent/thinking/thought-duration.d.ts +2 -0
  32. package/dist/agent/thinking/thought-duration.js +13 -0
  33. package/dist/agent/tool/json-block.d.ts +5 -0
  34. package/dist/agent/tool/json-block.js +15 -0
  35. package/dist/agent/tool/tool-status.d.ts +6 -0
  36. package/dist/agent/tool/tool-status.js +26 -0
  37. package/dist/agent/tool/tool.d.ts +7 -0
  38. package/dist/agent/tool/tool.js +14 -0
  39. package/dist/approval/inbox/inbox-row.d.ts +11 -0
  40. package/dist/approval/inbox/inbox-row.js +14 -0
  41. package/dist/approval/inbox/inbox-selection.d.ts +6 -0
  42. package/dist/approval/inbox/inbox-selection.js +21 -0
  43. package/dist/approval/inbox/inbox.d.ts +11 -0
  44. package/dist/approval/inbox/inbox.js +26 -0
  45. package/dist/approval/index.d.ts +9 -0
  46. package/dist/approval/index.js +8 -0
  47. package/dist/approval/memory/memory-choices.d.ts +10 -0
  48. package/dist/approval/memory/memory-choices.js +30 -0
  49. package/dist/approval/memory/memory-review.d.ts +11 -0
  50. package/dist/approval/memory/memory-review.js +31 -0
  51. package/dist/approval/memory/memory-row.d.ts +9 -0
  52. package/dist/approval/memory/memory-row.js +30 -0
  53. package/dist/approval/plan/plan-review.d.ts +13 -0
  54. package/dist/approval/plan/plan-review.js +38 -0
  55. package/dist/approval/plan/plan-step-row.d.ts +13 -0
  56. package/dist/approval/plan/plan-step-row.js +50 -0
  57. package/dist/approval/plan/plan-steps.d.ts +8 -0
  58. package/dist/approval/plan/plan-steps.js +29 -0
  59. package/dist/approval/plan/question-choices.d.ts +10 -0
  60. package/dist/approval/plan/question-choices.js +47 -0
  61. package/dist/approval/plan/question.d.ts +18 -0
  62. package/dist/approval/plan/question.js +35 -0
  63. package/dist/approval/run/run-bar.d.ts +13 -0
  64. package/dist/approval/run/run-bar.js +33 -0
  65. package/dist/approval/shared/decision-line.d.ts +1 -0
  66. package/dist/approval/shared/decision-line.js +1 -0
  67. package/dist/approval/shared/risk-badge.d.ts +10 -0
  68. package/dist/approval/shared/risk-badge.js +26 -0
  69. package/dist/approval/shared/time.d.ts +3 -0
  70. package/dist/approval/shared/time.js +15 -0
  71. package/dist/approval/shared/use-focus-on-mount.d.ts +2 -0
  72. package/dist/approval/shared/use-focus-on-mount.js +9 -0
  73. package/dist/approval/spend/raise-cap-form.d.ts +8 -0
  74. package/dist/approval/spend/raise-cap-form.js +26 -0
  75. package/dist/approval/spend/spend-gate.d.ts +16 -0
  76. package/dist/approval/spend/spend-gate.js +32 -0
  77. package/dist/approval/spend/spend-math.d.ts +5 -0
  78. package/dist/approval/spend/spend-math.js +18 -0
  79. package/dist/approval/spend/spend-meter.d.ts +10 -0
  80. package/dist/approval/spend/spend-meter.js +49 -0
  81. package/dist/approval/tool/approval.d.ts +14 -0
  82. package/dist/approval/tool/approval.js +45 -0
  83. package/dist/approval/tool/args/args-editor.d.ts +16 -0
  84. package/dist/approval/tool/args/args-editor.js +37 -0
  85. package/dist/approval/tool/args/args-field.d.ts +11 -0
  86. package/dist/approval/tool/args/args-field.js +28 -0
  87. package/dist/approval/tool/args/args-validation.d.ts +8 -0
  88. package/dist/approval/tool/args/args-validation.js +59 -0
  89. package/dist/approval/tool/deny-form.d.ts +6 -0
  90. package/dist/approval/tool/deny-form.js +15 -0
  91. package/dist/approval/tool/tool-inputs.d.ts +6 -0
  92. package/dist/approval/tool/tool-inputs.js +53 -0
  93. package/dist/approval/types.d.ts +59 -0
  94. package/dist/approval/types.js +1 -0
  95. package/dist/chat/chat/chat.d.ts +7 -0
  96. package/dist/chat/chat/chat.js +11 -0
  97. package/dist/chat/chat/use-stick-to-bottom.d.ts +7 -0
  98. package/dist/chat/chat/use-stick-to-bottom.js +57 -0
  99. package/dist/chat/composer/composer-actions.d.ts +15 -0
  100. package/dist/chat/composer/composer-actions.js +23 -0
  101. package/dist/chat/composer/composer.d.ts +20 -0
  102. package/dist/chat/composer/composer.js +42 -0
  103. package/dist/chat/composer/use-auto-grow.d.ts +2 -0
  104. package/dist/chat/composer/use-auto-grow.js +14 -0
  105. package/dist/chat/files/file-meta.d.ts +13 -0
  106. package/dist/chat/files/file-meta.js +30 -0
  107. package/dist/chat/files/files.d.ts +9 -0
  108. package/dist/chat/files/files.js +39 -0
  109. package/dist/chat/index.d.ts +7 -0
  110. package/dist/chat/index.js +7 -0
  111. package/dist/chat/reply/fenced-code.d.ts +8 -0
  112. package/dist/chat/reply/fenced-code.js +29 -0
  113. package/dist/chat/reply/markdown-components.d.ts +2 -0
  114. package/dist/chat/reply/markdown-components.js +22 -0
  115. package/dist/chat/reply/reply.d.ts +8 -0
  116. package/dist/chat/reply/reply.js +21 -0
  117. package/dist/chat/turn/group-parts.d.ts +24 -0
  118. package/dist/chat/turn/group-parts.js +35 -0
  119. package/dist/chat/turn/turn.d.ts +11 -0
  120. package/dist/chat/turn/turn.js +45 -0
  121. package/dist/cost/context.d.ts +13 -0
  122. package/dist/cost/context.js +35 -0
  123. package/dist/cost/cost-steps.d.ts +17 -0
  124. package/dist/cost/cost-steps.js +24 -0
  125. package/dist/cost/cost.d.ts +8 -0
  126. package/dist/cost/cost.js +37 -0
  127. package/dist/cost/index.d.ts +4 -0
  128. package/dist/cost/index.js +4 -0
  129. package/dist/cost/model-picker.d.ts +11 -0
  130. package/dist/cost/model-picker.js +9 -0
  131. package/dist/cost/shared/context-breakdown.d.ts +15 -0
  132. package/dist/cost/shared/context-breakdown.js +17 -0
  133. package/dist/cost/shared/meter-marks.d.ts +9 -0
  134. package/dist/cost/shared/meter-marks.js +16 -0
  135. package/dist/cost/shared/model-option-row.d.ts +14 -0
  136. package/dist/cost/shared/model-option-row.js +32 -0
  137. package/dist/cost/shared/step-cost-row.d.ts +15 -0
  138. package/dist/cost/shared/step-cost-row.js +34 -0
  139. package/dist/cost/shared/usage-totals.d.ts +11 -0
  140. package/dist/cost/shared/usage-totals.js +26 -0
  141. package/dist/index.d.ts +7 -0
  142. package/dist/index.js +7 -0
  143. package/dist/memory/cite.d.ts +8 -0
  144. package/dist/memory/cite.js +19 -0
  145. package/dist/memory/index.d.ts +5 -0
  146. package/dist/memory/index.js +4 -0
  147. package/dist/memory/memorized.d.ts +14 -0
  148. package/dist/memory/memorized.js +19 -0
  149. package/dist/memory/recall.d.ts +9 -0
  150. package/dist/memory/recall.js +24 -0
  151. package/dist/memory/shared/disclosure.d.ts +6 -0
  152. package/dist/memory/shared/disclosure.js +6 -0
  153. package/dist/memory/shared/host-label.d.ts +6 -0
  154. package/dist/memory/shared/host-label.js +34 -0
  155. package/dist/memory/shared/source-mark.d.ts +5 -0
  156. package/dist/memory/shared/source-mark.js +6 -0
  157. package/dist/memory/sources.d.ts +9 -0
  158. package/dist/memory/sources.js +22 -0
  159. package/dist/shared/decision-summary.d.ts +18 -0
  160. package/dist/shared/decision-summary.js +25 -0
  161. package/dist/shared/panel-empty.d.ts +8 -0
  162. package/dist/shared/panel-empty.js +5 -0
  163. package/dist/shared/panel.d.ts +19 -0
  164. package/dist/shared/panel.js +21 -0
  165. package/dist/shared/status-dot.d.ts +6 -0
  166. package/dist/shared/status-dot.js +12 -0
  167. package/dist/sources.css +1 -0
  168. package/dist/thread/actions/action-button.d.ts +8 -0
  169. package/dist/thread/actions/action-button.js +5 -0
  170. package/dist/thread/actions/actions.d.ts +13 -0
  171. package/dist/thread/actions/actions.js +21 -0
  172. package/dist/thread/actions/branch-switcher.d.ts +10 -0
  173. package/dist/thread/actions/branch-switcher.js +7 -0
  174. package/dist/thread/canvas/canvas.d.ts +14 -0
  175. package/dist/thread/canvas/canvas.js +12 -0
  176. package/dist/thread/canvas/version-switcher.d.ts +12 -0
  177. package/dist/thread/canvas/version-switcher.js +11 -0
  178. package/dist/thread/code/code.d.ts +10 -0
  179. package/dist/thread/code/code.js +33 -0
  180. package/dist/thread/code/copy-code-button.d.ts +6 -0
  181. package/dist/thread/code/copy-code-button.js +18 -0
  182. package/dist/thread/code/highlight.d.ts +1 -0
  183. package/dist/thread/code/highlight.js +39 -0
  184. package/dist/thread/history/history-row.d.ts +14 -0
  185. package/dist/thread/history/history-row.js +17 -0
  186. package/dist/thread/history/history.d.ts +15 -0
  187. package/dist/thread/history/history.js +10 -0
  188. package/dist/thread/history/thread-groups.d.ts +8 -0
  189. package/dist/thread/history/thread-groups.js +46 -0
  190. package/dist/thread/history/thread-item-menu.d.ts +7 -0
  191. package/dist/thread/history/thread-item-menu.js +6 -0
  192. package/dist/thread/history/thread-title-editor.d.ts +7 -0
  193. package/dist/thread/history/thread-title-editor.js +25 -0
  194. package/dist/thread/index.d.ts +8 -0
  195. package/dist/thread/index.js +5 -0
  196. package/dist/thread/starters/starters.d.ts +12 -0
  197. package/dist/thread/starters/starters.js +15 -0
  198. package/dist/thread/use-copied.d.ts +5 -0
  199. package/dist/thread/use-copied.js +22 -0
  200. package/dist/types.d.ts +70 -0
  201. package/dist/types.js +3 -0
  202. package/package.json +57 -3
@@ -0,0 +1,8 @@
1
+ import type { RunUsage } from "../types.js";
2
+ export type CostProps = {
3
+ usage: RunUsage | RunUsage[];
4
+ variant?: "compact" | "detailed";
5
+ label?: string;
6
+ className?: string;
7
+ };
8
+ export declare function Cost({ usage, variant, label, className }: CostProps): import("react").JSX.Element;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Money as CoinsIcon } from "@carbon/icons-react";
3
+ import { cn } from "@locusgraph/components";
4
+ import { formatCount, formatMicroUsd, pluralize } from "@locusgraph/utils";
5
+ import { ApprovalPanel, PanelHeader } from "../shared/panel.js";
6
+ import { sumUsage } from "./shared/usage-totals.js";
7
+ function attemptsOf(usage) {
8
+ return Array.isArray(usage) ? usage : [usage];
9
+ }
10
+ function modelsOf(attempts) {
11
+ const models = [...new Set(attempts.map((attempt) => attempt.model).filter(Boolean))];
12
+ return models.length > 0 ? models.join(", ") : undefined;
13
+ }
14
+ function WastedNote({ totals }) {
15
+ if (totals.failedAttempts === 0)
16
+ return null;
17
+ return (_jsxs("span", { "data-slot": "cost-wasted", className: "text-destructive tabular-nums", children: [pluralize(totals.failedAttempts, "failed attempt"), " \u00B7 ", formatMicroUsd(totals.wastedMicroUsd), " ", "wasted"] }));
18
+ }
19
+ function CompactCost({ attempts, totals, className, }) {
20
+ const model = modelsOf(attempts);
21
+ return (_jsxs("span", { "data-slot": "cost", "data-variant": "compact", "data-failed": totals.failedAttempts > 0 || undefined, className: cn("inline-flex flex-wrap items-baseline gap-x-3 gap-y-0.5 font-mono text-[11px] text-muted-foreground tabular-nums", className), children: [_jsx("span", { className: "font-medium text-foreground", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "whitespace-nowrap", children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out"] }), model && _jsx("span", { children: model }), _jsx(WastedNote, { totals: totals })] }));
22
+ }
23
+ function AttemptRow({ attempt, position }) {
24
+ return (_jsxs("li", { "data-slot": "cost-attempt", "data-failed": attempt.failed || undefined, className: "grid grid-cols-[1fr_auto_4.5rem] items-baseline gap-x-4 px-5 py-2.5 text-sm tabular-nums", children: [_jsxs("span", { className: "flex min-w-0 items-baseline gap-2", children: [_jsxs("span", { className: "eyebrow", children: ["#", position + 1] }), _jsx("span", { className: cn("truncate", attempt.failed && "text-muted-foreground"), children: attempt.model ?? "Attempt" }), attempt.failed && (_jsx("span", { className: "font-mono text-[11px] tracking-wide text-destructive uppercase", children: "Failed" }))] }), _jsxs("span", { className: "font-mono text-[11px] text-muted-foreground max-sm:hidden", children: [formatCount(attempt.inputTokens), " in \u00B7 ", formatCount(attempt.outputTokens), " out"] }), _jsx("span", { className: cn("text-right font-mono text-xs", attempt.failed && "text-muted-foreground line-through"), children: formatMicroUsd(attempt.costMicroUsd) })] }));
25
+ }
26
+ function DetailedCost({ attempts, totals, label, className, }) {
27
+ const failed = totals.failedAttempts > 0;
28
+ return (_jsxs(ApprovalPanel, { "data-slot": "cost", "data-variant": "detailed", "data-failed": failed || undefined, "aria-label": label, className: className, children: [_jsx(PanelHeader, { icon: _jsx(CoinsIcon, { "aria-hidden": true }), eyebrow: label, aside: pluralize(attempts.length, "attempt") }), _jsxs("div", { className: "flex flex-col gap-1 px-5 pt-2 pb-4", children: [_jsx("span", { className: "text-2xl font-semibold tracking-tight tabular-nums", children: formatMicroUsd(totals.costMicroUsd) }), _jsxs("span", { className: "flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground tabular-nums", children: [_jsxs("span", { children: [formatCount(totals.inputTokens), " in \u00B7 ", formatCount(totals.outputTokens), " out"] }), _jsx(WastedNote, { totals: totals })] })] }), _jsx("ol", { className: "flex flex-col divide-y divide-border border-t border-border", children: attempts.map((attempt, position) => (_jsx(AttemptRow, { attempt: attempt, position: position }, position))) })] }));
29
+ }
30
+ export function Cost({ usage, variant = "compact", label = "Run cost", className }) {
31
+ const attempts = attemptsOf(usage);
32
+ const totals = sumUsage(attempts);
33
+ if (variant === "detailed") {
34
+ return _jsx(DetailedCost, { attempts: attempts, totals: totals, label: label, className: className });
35
+ }
36
+ return _jsx(CompactCost, { attempts: attempts, totals: totals, className: className });
37
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./context.js";
2
+ export * from "./cost.js";
3
+ export * from "./cost-steps.js";
4
+ export * from "./model-picker.js";
@@ -0,0 +1,4 @@
1
+ export * from "./context.js";
2
+ export * from "./cost.js";
3
+ export * from "./cost-steps.js";
4
+ export * from "./model-picker.js";
@@ -0,0 +1,11 @@
1
+ import { type ModelOption } from "./shared/model-option-row.js";
2
+ export { type ModelOption, type ModelSpeed, modelPriceLabel, } from "./shared/model-option-row.js";
3
+ export type ModelPickerProps = {
4
+ models: ModelOption[];
5
+ value: string;
6
+ onChange: (id: string) => void;
7
+ label?: string;
8
+ disabled?: boolean;
9
+ className?: string;
10
+ };
11
+ export declare function ModelPicker({ models, value, onChange, label, disabled, className, }: ModelPickerProps): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronDown as ChevronDownIcon } from "@carbon/icons-react";
3
+ import { cn, DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuTrigger, } from "@locusgraph/components";
4
+ import { ModelOptionRow } from "./shared/model-option-row.js";
5
+ export { modelPriceLabel, } from "./shared/model-option-row.js";
6
+ export function ModelPicker({ models, value, onChange, label = "Model", disabled = false, className, }) {
7
+ const selected = models.find((model) => model.id === value);
8
+ return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { "data-slot": "model-picker", "data-value": value, disabled: disabled, "aria-label": `${label}: ${selected?.name ?? "none selected"}`, className: cn("group inline-flex h-7 max-w-full items-center gap-1.5 rounded-full px-2.5 text-xs outline-none transition-colors duration-150 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent motion-reduce:transition-none", className), children: [_jsx("span", { className: "truncate font-medium", children: selected?.name ?? label }), selected && (_jsx("span", { className: "truncate text-muted-foreground max-sm:hidden", children: selected.provider })), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3 shrink-0 text-muted-foreground transition-transform duration-150 group-data-[state=open]:rotate-180 motion-reduce:transition-none" })] }), _jsxs(DropdownMenuContent, { align: "start", sideOffset: 6, className: "w-80 rounded-none border-0 bg-popover p-0 shadow-overlay ring-1 ring-border", children: [_jsxs(DropdownMenuLabel, { className: "eyebrow flex justify-between gap-3 border-b border-border px-3 py-2 font-normal", children: [_jsx("span", { children: label }), _jsx("span", { className: "pr-7", children: "Per 1M tokens" })] }), _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: onChange, className: "flex flex-col divide-y divide-border", children: models.map((model) => (_jsx(ModelOptionRow, { model: model }, model.id))) })] })] }));
9
+ }
@@ -0,0 +1,15 @@
1
+ import { type MeterStatus } from "./meter-marks.js";
2
+ export type ContextSegment = {
3
+ label: string;
4
+ tokens: number;
5
+ };
6
+ type ContextBreakdownProps = {
7
+ label: string;
8
+ usedTokens: number;
9
+ limitTokens: number;
10
+ percent: number;
11
+ status: MeterStatus;
12
+ breakdown: ContextSegment[];
13
+ };
14
+ export declare function ContextBreakdown({ label, usedTokens, limitTokens, percent, status, breakdown, }: ContextBreakdownProps): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@locusgraph/components";
3
+ import { formatCount, quotaPercent } from "@locusgraph/utils";
4
+ import { MeterBar } from "./meter-marks.js";
5
+ const statusWord = { ok: "Room left", near: "Near limit", full: "Full" };
6
+ const statusDot = {
7
+ ok: "bg-good",
8
+ near: "bg-warn",
9
+ full: "bg-destructive",
10
+ };
11
+ function SegmentRow({ label, tokens, limitTokens, muted = false, }) {
12
+ return (_jsxs("li", { className: cn("grid grid-cols-[1fr_auto_3rem] items-baseline gap-x-3 px-4 py-2 text-xs tabular-nums", muted && "text-muted-foreground"), children: [_jsx("span", { className: "truncate", children: label }), _jsx("span", { className: "font-mono", children: formatCount(tokens) }), _jsxs("span", { className: "text-right font-mono text-muted-foreground", children: [quotaPercent({ used: tokens, included: limitTokens }), "%"] })] }));
13
+ }
14
+ export function ContextBreakdown({ label, usedTokens, limitTokens, percent, status, breakdown, }) {
15
+ const freeTokens = Math.max(limitTokens - usedTokens, 0);
16
+ return (_jsxs("div", { "data-slot": "context-breakdown", className: "flex flex-col", children: [_jsxs("div", { className: "eyebrow flex items-center gap-2 px-4 pt-3", children: [_jsx("span", { children: label }), _jsxs("span", { className: "ml-auto flex items-center gap-1.5", children: [_jsx("span", { "aria-hidden": true, className: cn("size-1.5 rounded-full", statusDot[status]) }), statusWord[status]] })] }), _jsxs("div", { className: "flex flex-col gap-2 px-4 pt-2 pb-3", children: [_jsxs("span", { className: "flex items-baseline gap-1.5 tabular-nums", children: [_jsxs("span", { className: "text-lg font-semibold tracking-tight", children: [percent, "%"] }), _jsxs("span", { className: "text-xs text-muted-foreground", children: [formatCount(usedTokens), " of ", formatCount(limitTokens), " tokens"] })] }), _jsx(MeterBar, { percent: percent, status: status })] }), _jsxs("ul", { className: "flex flex-col divide-y divide-border border-t border-border", children: [breakdown.map((segment) => (_jsx(SegmentRow, { label: segment.label, tokens: segment.tokens, limitTokens: limitTokens }, segment.label))), _jsx(SegmentRow, { label: "Free", tokens: freeTokens, limitTokens: limitTokens, muted: true })] })] }));
17
+ }
@@ -0,0 +1,9 @@
1
+ export type MeterStatus = "ok" | "near" | "full";
2
+ export declare function MeterRing({ percent, status }: {
3
+ percent: number;
4
+ status: MeterStatus;
5
+ }): import("react").JSX.Element;
6
+ export declare function MeterBar({ percent, status }: {
7
+ percent: number;
8
+ status: MeterStatus;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@locusgraph/components";
3
+ const ringRadius = 7;
4
+ const ringCircumference = 2 * Math.PI * ringRadius;
5
+ const ringStroke = {
6
+ ok: "stroke-primary",
7
+ near: "stroke-warn",
8
+ full: "stroke-destructive",
9
+ };
10
+ const barFill = { ok: "bg-primary", near: "bg-warn", full: "bg-destructive" };
11
+ export function MeterRing({ percent, status }) {
12
+ return (_jsxs("svg", { viewBox: "0 0 18 18", "aria-hidden": true, className: "size-3.5 shrink-0 -rotate-90", children: [_jsx("circle", { cx: "9", cy: "9", r: ringRadius, fill: "none", strokeWidth: "2.5", className: "stroke-muted-foreground/20" }), _jsx("circle", { cx: "9", cy: "9", r: ringRadius, fill: "none", strokeWidth: "2.5", strokeDasharray: ringCircumference, strokeDashoffset: ringCircumference * (1 - percent / 100), className: cn("transition-[stroke-dashoffset] duration-300 motion-reduce:transition-none", ringStroke[status]) })] }));
13
+ }
14
+ export function MeterBar({ percent, status }) {
15
+ return (_jsx("span", { "aria-hidden": true, className: "relative block h-1 w-full overflow-hidden bg-muted-foreground/20", children: _jsx("span", { className: cn("absolute inset-y-0 left-0 transition-[width] duration-300 motion-reduce:transition-none", barFill[status]), style: { width: `${percent}%` } }) }));
16
+ }
@@ -0,0 +1,14 @@
1
+ export type ModelSpeed = "fast" | "balanced" | "deep";
2
+ export type ModelOption = {
3
+ id: string;
4
+ name: string;
5
+ provider: string;
6
+ inputPerMillionMicroUsd?: number;
7
+ outputPerMillionMicroUsd?: number;
8
+ speed?: ModelSpeed;
9
+ contextTokens?: number;
10
+ };
11
+ export declare function modelPriceLabel(model: ModelOption): string | undefined;
12
+ export declare function ModelOptionRow({ model }: {
13
+ model: ModelOption;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Checkmark as CheckIcon } from "@carbon/icons-react";
3
+ import { DropdownMenuRadioItem } from "@locusgraph/components";
4
+ import { formatMicroUsd } from "@locusgraph/utils";
5
+ import { formatTokensShort } from "./usage-totals.js";
6
+ const speedLabel = { fast: "Fast", balanced: "Balanced", deep: "Deep" };
7
+ 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`;
17
+ }
18
+ 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");
23
+ }
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"] })] }));
28
+ }
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" })] }));
32
+ }
@@ -0,0 +1,15 @@
1
+ import type { RunUsage, StepStatus } from "../../types.js";
2
+ export type CostStepStatus = StepStatus | "retried";
3
+ export type CostStep = {
4
+ id: string;
5
+ title: string;
6
+ status: CostStepStatus;
7
+ usage: RunUsage;
8
+ durationMs?: number;
9
+ };
10
+ export declare function isWastedStep(step: CostStep): boolean;
11
+ export declare function StepCostRow({ step, maxCost, totalCost, }: {
12
+ step: CostStep;
13
+ maxCost: number;
14
+ totalCost: number;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "@locusgraph/components";
3
+ import { formatMicroUsd } from "@locusgraph/utils";
4
+ import { formatDuration } from "./usage-totals.js";
5
+ export function isWastedStep(step) {
6
+ return step.status === "failed" || step.usage.failed === true;
7
+ }
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";
16
+ }
17
+ 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" },
22
+ };
23
+ function barWidth(cost, maxCost) {
24
+ if (maxCost <= 0)
25
+ return 0;
26
+ return Math.max((cost / maxCost) * 100, cost > 0 ? 2 : 0);
27
+ }
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) })] }));
34
+ }
@@ -0,0 +1,11 @@
1
+ import type { RunUsage } from "../../types.js";
2
+ export type UsageTotals = {
3
+ inputTokens: number;
4
+ outputTokens: number;
5
+ costMicroUsd: number;
6
+ wastedMicroUsd: number;
7
+ failedAttempts: number;
8
+ };
9
+ export declare function sumUsage(attempts: RunUsage[]): UsageTotals;
10
+ export declare function formatTokensShort(tokens: number): string;
11
+ export declare function formatDuration(durationMs: number): string;
@@ -0,0 +1,26 @@
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 });
9
+ }
10
+ const compactCount = new Intl.NumberFormat("en-US", {
11
+ notation: "compact",
12
+ maximumFractionDigits: 1,
13
+ });
14
+ export function formatTokensShort(tokens) {
15
+ return compactCount.format(tokens);
16
+ }
17
+ 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`;
26
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./agent/index.js";
2
+ export * from "./approval/index.js";
3
+ export * from "./chat/index.js";
4
+ export * from "./cost/index.js";
5
+ export * from "./memory/index.js";
6
+ export * from "./thread/index.js";
7
+ export * from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./agent/index.js";
2
+ export * from "./approval/index.js";
3
+ export * from "./chat/index.js";
4
+ export * from "./cost/index.js";
5
+ export * from "./memory/index.js";
6
+ export * from "./thread/index.js";
7
+ export * from "./types.js";
@@ -0,0 +1,8 @@
1
+ import type { Citation } from "../types.js";
2
+ export type CiteProps = {
3
+ citation: Citation;
4
+ onOpen?: (citation: Citation) => void;
5
+ className?: string;
6
+ };
7
+ export declare function citationLabel(citation: Citation): string;
8
+ export declare function Cite({ citation, onOpen, className }: CiteProps): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn, HoverCard, HoverCardContent, HoverCardTrigger } from "@locusgraph/components";
3
+ import { hostLabel } from "./shared/host-label.js";
4
+ import { SourceMark } from "./shared/source-mark.js";
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
+ export function citationLabel(citation) {
7
+ return `Source ${citation.index}: ${citation.title}`;
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 }))] })] }) }));
19
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./cite.js";
2
+ export * from "./memorized.js";
3
+ export * from "./recall.js";
4
+ export type { SourceItem } from "./shared/host-label.js";
5
+ export * from "./sources.js";
@@ -0,0 +1,4 @@
1
+ export * from "./cite.js";
2
+ export * from "./memorized.js";
3
+ export * from "./recall.js";
4
+ export * from "./sources.js";
@@ -0,0 +1,14 @@
1
+ export type MemorizedStatus = "saved" | "undone";
2
+ export type MemorizedItem = {
3
+ id: string;
4
+ text: string;
5
+ kind?: string;
6
+ status: MemorizedStatus;
7
+ };
8
+ export type MemorizedProps = {
9
+ items: MemorizedItem[];
10
+ onUndo?: (id: string) => void;
11
+ className?: string;
12
+ };
13
+ export declare function memorizedSummary(items: MemorizedItem[]): string;
14
+ export declare function Memorized({ items, onUndo, className }: MemorizedProps): import("react").JSX.Element | null;
@@ -0,0 +1,19 @@
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";
3
+ import { Button, cn } from "@locusgraph/components";
4
+ import { pluralize } from "@locusgraph/utils";
5
+ import { StatusDot } from "../shared/status-dot.js";
6
+ import { eyebrowClass, ruledListClass } from "./shared/disclosure.js";
7
+ export function memorizedSummary(items) {
8
+ const saved = items.filter((item) => item.status === "saved").length;
9
+ return `Saved ${pluralize(saved, "memory", "memories")}`;
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))) })] }));
15
+ }
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"] })))] }));
19
+ }
@@ -0,0 +1,9 @@
1
+ import type { MemoryRef } from "../types.js";
2
+ export type RecallProps = {
3
+ memories: MemoryRef[];
4
+ onOpenMemory?: (id: string) => void;
5
+ defaultOpen?: boolean;
6
+ className?: string;
7
+ };
8
+ export declare function relevancePercent(relevance: number): number;
9
+ export declare function Recall({ memories, onOpenMemory, defaultOpen, className }: RecallProps): import("react").JSX.Element | null;
@@ -0,0 +1,24 @@
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";
3
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger, cn } from "@locusgraph/components";
4
+ import { pluralize } from "@locusgraph/utils";
5
+ import { chevronClass, collapsibleTriggerClass, interactiveRowClass, ruledListClass, } from "./shared/disclosure.js";
6
+ export function relevancePercent(relevance) {
7
+ return Math.round(Math.min(Math.max(relevance, 0), 1) * 100);
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))) }) })] }));
13
+ }
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, "%"] })] }));
19
+ }
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 })) }));
24
+ }
@@ -0,0 +1,6 @@
1
+ export declare const eyebrowClass = "eyebrow [&_svg]:size-3.5 [&_svg]:shrink-0";
2
+ export declare const collapsibleTriggerClass = "group inline-flex w-fit items-center gap-2 py-1 outline-none transition-colors duration-150 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-reduce:transition-none eyebrow [&_svg]:size-3.5 [&_svg]:shrink-0";
3
+ export declare const chevronClass = "opacity-70 transition-transform duration-150 group-data-[state=open]:rotate-90 motion-reduce:transition-none";
4
+ export declare const ruledRowClass = "flex w-full items-center gap-3 px-3 py-2.5 text-left text-sm";
5
+ export declare const ruledListClass = "flex flex-col divide-y divide-border bg-card ring-1 ring-border";
6
+ export declare const interactiveRowClass = "outline-none transition-colors duration-150 hover:bg-accent/50 focus-visible:bg-accent motion-reduce:transition-none";
@@ -0,0 +1,6 @@
1
+ export const eyebrowClass = "eyebrow [&_svg]:size-3.5 [&_svg]:shrink-0";
2
+ export const collapsibleTriggerClass = `group inline-flex w-fit items-center gap-2 py-1 outline-none transition-colors duration-150 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-reduce:transition-none ${eyebrowClass}`;
3
+ export const chevronClass = "opacity-70 transition-transform duration-150 group-data-[state=open]:rotate-90 motion-reduce:transition-none";
4
+ export const ruledRowClass = "flex w-full items-center gap-3 px-3 py-2.5 text-left text-sm";
5
+ export const ruledListClass = "flex flex-col divide-y divide-border bg-card ring-1 ring-border";
6
+ export const interactiveRowClass = "outline-none transition-colors duration-150 hover:bg-accent/50 focus-visible:bg-accent motion-reduce:transition-none";
@@ -0,0 +1,6 @@
1
+ import type { Citation, SourceUrlPart } from "../../types.js";
2
+ export declare function hostLabel(url: string | undefined): string | undefined;
3
+ export type SourceItem = Citation | SourceUrlPart;
4
+ export declare function toCitation(item: SourceItem, position: number): Citation;
5
+ export declare function sourceKey(item: SourceItem, position: number): string;
6
+ export declare function sourceInitial(citation: Citation): string;
@@ -0,0 +1,34 @@
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
+ }
10
+ }
11
+ function isSourceUrlPart(item) {
12
+ return "type" in item && item.type === "source-url";
13
+ }
14
+ 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
+ };
22
+ }
23
+ export function sourceKey(item, position) {
24
+ return isSourceUrlPart(item) ? item.sourceId : `${item.index}:${position}`;
25
+ }
26
+ function siteNameOf(host) {
27
+ const labels = host.split(".");
28
+ return labels.length > 2 ? labels.slice(-2).join(".") : host;
29
+ }
30
+ 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() || "?";
34
+ }
@@ -0,0 +1,5 @@
1
+ import type { Citation } from "../../types.js";
2
+ export declare function SourceMark({ citation, className }: {
3
+ citation: Citation;
4
+ className?: string;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "@locusgraph/components";
3
+ 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) }));
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { Citation } from "../types.js";
2
+ import { type SourceItem } from "./shared/host-label.js";
3
+ export type SourcesProps = {
4
+ sources: SourceItem[];
5
+ onOpen?: (citation: Citation) => void;
6
+ defaultOpen?: boolean;
7
+ className?: string;
8
+ };
9
+ export declare function Sources({ sources, onOpen, defaultOpen, className }: SourcesProps): import("react").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronRight as ChevronRightIcon } from "@carbon/icons-react";
3
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger, cn } from "@locusgraph/components";
4
+ import { pluralize } from "@locusgraph/utils";
5
+ import { chevronClass, collapsibleTriggerClass, interactiveRowClass, ruledListClass, ruledRowClass, } from "./shared/disclosure.js";
6
+ import { hostLabel, sourceKey, toCitation } from "./shared/host-label.js";
7
+ import { SourceMark } from "./shared/source-mark.js";
8
+ const stackedMarkLimit = 3;
9
+ export function Sources({ sources, onOpen, defaultOpen = false, className }) {
10
+ if (sources.length === 0)
11
+ return null;
12
+ const citations = sources.map(toCitation);
13
+ return (_jsxs(Collapsible, { "data-slot": "sources", defaultOpen: defaultOpen, className: cn("flex min-w-0 flex-col gap-2", className), children: [_jsxs(CollapsibleTrigger, { className: collapsibleTriggerClass, children: [_jsx("span", { "aria-hidden": true, className: "flex -space-x-1", children: citations.slice(0, stackedMarkLimit).map((citation, position) => (_jsx(SourceMark, { citation: citation, className: "ring-card" }, sourceKey(sources[position], position)))) }), "Used ", pluralize(sources.length, "source"), _jsx(ChevronRightIcon, { "aria-hidden": true, className: chevronClass })] }), _jsx(CollapsibleContent, { children: _jsx("ol", { className: ruledListClass, children: citations.map((citation, position) => (_jsx(SourceRow, { citation: citation, onOpen: onOpen }, sourceKey(sources[position], position)))) }) })] }));
14
+ }
15
+ function SourceRow({ citation, onOpen, }) {
16
+ const host = hostLabel(citation.url);
17
+ const showHost = host !== undefined && host !== citation.title;
18
+ const content = (_jsxs(_Fragment, { children: [_jsx("span", { className: "w-4 shrink-0 font-mono text-xs text-muted-foreground tabular-nums", children: citation.index }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: citation.title }), showHost && (_jsx("span", { className: "max-w-[40%] shrink-0 truncate text-xs text-muted-foreground", children: host }))] }));
19
+ const rowClass = ruledRowClass;
20
+ const label = `Open source ${citation.index}: ${citation.title}`;
21
+ return (_jsx("li", { "data-slot": "sources-item", "data-index": citation.index, children: onOpen ? (_jsx("button", { type: "button", "aria-label": label, onClick: () => onOpen(citation), className: cn(rowClass, interactiveRowClass), children: content })) : citation.url ? (_jsx("a", { href: citation.url, target: "_blank", rel: "noreferrer", "aria-label": label, className: cn(rowClass, interactiveRowClass), children: content })) : (_jsx("div", { className: rowClass, children: content })) }));
22
+ }
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from "react";
2
+ import type { DecidedAt } from "../approval/types.js";
3
+ export declare function toDate(value: DecidedAt): Date;
4
+ export declare function isoOf(value: DecidedAt): string | undefined;
5
+ export declare function formatDecidedAt(value: DecidedAt): string;
6
+ export type DecisionOutcome = {
7
+ approved: boolean;
8
+ by?: string;
9
+ at?: DecidedAt;
10
+ reason?: string;
11
+ };
12
+ export type DecisionSummaryProps = {
13
+ decision: DecisionOutcome;
14
+ result: ReactNode;
15
+ approvedVerb?: string;
16
+ deniedVerb?: string;
17
+ };
18
+ export declare function DecisionSummary({ decision, result, approvedVerb, deniedVerb, }: DecisionSummaryProps): import("react").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Checkmark as CheckIcon, Close as XIcon } from "@carbon/icons-react";
3
+ const decisionTimeFormat = new Intl.DateTimeFormat("en-US", {
4
+ dateStyle: "medium",
5
+ timeStyle: "short",
6
+ timeZone: "UTC",
7
+ });
8
+ export function toDate(value) {
9
+ return value instanceof Date ? value : new Date(value);
10
+ }
11
+ export function isoOf(value) {
12
+ const date = toDate(value);
13
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
14
+ }
15
+ export function formatDecidedAt(value) {
16
+ const date = toDate(value);
17
+ return Number.isNaN(date.getTime()) ? "" : `${decisionTimeFormat.format(date)} UTC`;
18
+ }
19
+ function DecisionMeta({ decision, verb }) {
20
+ return (_jsxs("p", { className: "text-xs text-muted-foreground", children: [verb, decision.by && ` by ${decision.by}`, decision.at !== undefined && (_jsxs(_Fragment, { children: [" · ", _jsx("time", { dateTime: isoOf(decision.at), className: "tabular-nums", children: formatDecidedAt(decision.at) })] }))] }));
21
+ }
22
+ export function DecisionSummary({ decision, result, approvedVerb = "Approved", deniedVerb = "Denied", }) {
23
+ const Icon = decision.approved ? CheckIcon : XIcon;
24
+ return (_jsxs("div", { "data-slot": "decision-summary", "data-approved": decision.approved, className: "flex items-start gap-2.5 text-sm", children: [_jsx(Icon, { "aria-hidden": true, className: `mt-0.5 size-4 shrink-0 ${decision.approved ? "text-good" : "text-destructive"}` }), _jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("p", { className: "font-medium", children: result }), _jsx(DecisionMeta, { decision: decision, verb: decision.approved ? approvedVerb : deniedVerb }), decision.reason && (_jsxs("p", { className: "text-xs text-muted-foreground", children: ["Reason: ", decision.reason] }))] })] }));
25
+ }
@@ -0,0 +1,8 @@
1
+ import type { ComponentProps, ReactNode } from "react";
2
+ type PanelEmptyProps = Omit<ComponentProps<"div">, "title"> & {
3
+ icon?: ReactNode;
4
+ title: string;
5
+ description?: ReactNode;
6
+ };
7
+ export declare function PanelEmpty({ icon, title, description, className, ...props }: PanelEmptyProps): import("react").JSX.Element;
8
+ export {};