@locusgraph/loop 0.1.0 → 0.2.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 (115) hide show
  1. package/README.md +2 -0
  2. package/dist/agent/pulse/gradient-label.js +86 -15
  3. package/dist/agent/pulse/marks/bars-mark.js +46 -10
  4. package/dist/agent/pulse/marks/glyph-mark.js +56 -11
  5. package/dist/agent/pulse/marks/locus-mark.js +63 -28
  6. package/dist/agent/pulse/marks/orb-mark.js +31 -8
  7. package/dist/agent/pulse/marks/spinner-mark.js +29 -1
  8. package/dist/agent/pulse/pulse.js +150 -35
  9. package/dist/agent/pulse/use-loop-animation.js +36 -17
  10. package/dist/agent/steps/step-icon.js +110 -24
  11. package/dist/agent/steps/steps.js +235 -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 +38 -11
  15. package/dist/agent/tool/tool-status.js +51 -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 +321 -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 +250 -18
  22. package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
  23. package/dist/approval/inbox/virtual-inbox-list.js +129 -0
  24. package/dist/approval/memory/memory-choices.js +27 -22
  25. package/dist/approval/memory/memory-review.js +242 -17
  26. package/dist/approval/memory/memory-row.js +215 -19
  27. package/dist/approval/plan/plan-review.js +279 -28
  28. package/dist/approval/plan/plan-step-row.js +194 -43
  29. package/dist/approval/plan/plan-steps.js +24 -23
  30. package/dist/approval/plan/question-choices.js +158 -39
  31. package/dist/approval/plan/question.d.ts +1 -1
  32. package/dist/approval/plan/question.js +223 -26
  33. package/dist/approval/run/run-bar.js +178 -22
  34. package/dist/approval/shared/decision-line.js +1 -1
  35. package/dist/approval/shared/risk-badge.js +47 -16
  36. package/dist/approval/shared/time.js +5 -8
  37. package/dist/approval/shared/use-focus-on-mount.js +23 -6
  38. package/dist/approval/spend/raise-cap-form.js +235 -17
  39. package/dist/approval/spend/spend-gate.js +239 -21
  40. package/dist/approval/spend/spend-math.js +7 -8
  41. package/dist/approval/spend/spend-meter.js +362 -34
  42. package/dist/approval/tool/approval.js +272 -27
  43. package/dist/approval/tool/args/args-editor.js +262 -26
  44. package/dist/approval/tool/args/args-field.js +259 -19
  45. package/dist/approval/tool/args/args-validation.js +38 -47
  46. package/dist/approval/tool/deny-form.js +130 -10
  47. package/dist/approval/tool/tool-inputs.js +127 -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 +123 -47
  53. package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
  54. package/dist/chat/chat/virtual-chat-items.js +153 -0
  55. package/dist/chat/composer/composer-actions.js +151 -16
  56. package/dist/chat/composer/composer.js +330 -32
  57. package/dist/chat/composer/use-auto-grow.js +24 -9
  58. package/dist/chat/files/file-meta.js +19 -19
  59. package/dist/chat/files/files.js +316 -28
  60. package/dist/chat/reply/fenced-code.js +45 -21
  61. package/dist/chat/reply/markdown-components.js +137 -17
  62. package/dist/chat/reply/reply.js +105 -10
  63. package/dist/chat/turn/group-parts.js +43 -29
  64. package/dist/chat/turn/turn.js +238 -30
  65. package/dist/cost/context.js +321 -23
  66. package/dist/cost/cost-steps.js +220 -14
  67. package/dist/cost/cost.js +521 -27
  68. package/dist/cost/model-picker.js +181 -6
  69. package/dist/cost/shared/context-breakdown.js +299 -10
  70. package/dist/cost/shared/meter-marks.js +107 -9
  71. package/dist/cost/shared/model-option-row.js +178 -21
  72. package/dist/cost/shared/step-cost-row.js +248 -20
  73. package/dist/cost/shared/usage-totals.js +22 -18
  74. package/dist/memory/cite.js +182 -11
  75. package/dist/memory/memorized.js +217 -11
  76. package/dist/memory/recall.js +296 -17
  77. package/dist/memory/shared/host-label.js +19 -22
  78. package/dist/memory/shared/source-mark.js +39 -3
  79. package/dist/memory/sources.js +255 -13
  80. package/dist/shared/decision-summary.js +133 -14
  81. package/dist/shared/panel-empty.js +78 -3
  82. package/dist/shared/panel.js +243 -13
  83. package/dist/shared/status-dot.js +38 -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 +65 -3
  87. package/dist/thread/actions/actions.js +184 -13
  88. package/dist/thread/actions/branch-switcher.js +102 -5
  89. package/dist/thread/canvas/canvas.js +205 -5
  90. package/dist/thread/canvas/version-switcher.js +149 -8
  91. package/dist/thread/code/code.js +186 -24
  92. package/dist/thread/code/copy-code-button.js +61 -13
  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 +137 -0
  100. package/dist/thread/history/row/thread-item-menu.js +84 -0
  101. package/dist/thread/history/row/thread-title-editor.js +81 -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 +107 -0
  106. package/dist/thread/index.d.ts +1 -1
  107. package/dist/thread/starters/starters.js +92 -7
  108. package/dist/thread/use-copied.js +45 -15
  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,53 +1,142 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { c as _c } from "react/compiler-runtime";
2
2
  import { cn } from "@locusgraph/components";
3
3
  import { useId, useState } from "react";
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
5
  function isPlainRecord(value) {
5
- return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
7
  }
7
8
  function isPrimitive(value) {
8
- return value === null || ["string", "number", "boolean"].includes(typeof value);
9
+ return value === null || ["string", "number", "boolean"].includes(typeof value);
9
10
  }
10
11
  export function readableValue(value) {
11
- if (value === null || value === undefined)
12
- return "None";
13
- if (typeof value === "boolean")
14
- return value ? "Yes" : "No";
15
- if (typeof value === "string" || typeof value === "number")
16
- return String(value);
17
- if (Array.isArray(value) && value.every(isPrimitive)) {
18
- return value.length === 0 ? "None" : value.map(readableValue).join(", ");
19
- }
20
- return JSON.stringify(value);
12
+ if (value === null || value === undefined) return "None";
13
+ if (typeof value === "boolean") return value ? "Yes" : "No";
14
+ if (typeof value === "string" || typeof value === "number") return String(value);
15
+ if (Array.isArray(value) && value.every(isPrimitive)) {
16
+ return value.length === 0 ? "None" : value.map(readableValue).join(", ");
17
+ }
18
+ return JSON.stringify(value);
21
19
  }
22
20
  const acronyms = {
23
- api: "API",
24
- csv: "CSV",
25
- id: "ID",
26
- ids: "IDs",
27
- json: "JSON",
28
- pdf: "PDF",
29
- sql: "SQL",
30
- url: "URL",
31
- urls: "URLs",
32
- usd: "USD",
21
+ api: "API",
22
+ csv: "CSV",
23
+ id: "ID",
24
+ ids: "IDs",
25
+ json: "JSON",
26
+ pdf: "PDF",
27
+ sql: "SQL",
28
+ url: "URL",
29
+ urls: "URLs",
30
+ usd: "USD"
33
31
  };
34
32
  export function humanizeKey(key) {
35
- const words = key
36
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
37
- .replace(/[_-]+/g, " ")
38
- .trim()
39
- .toLowerCase()
40
- .split(/\s+/)
41
- .map((word) => acronyms[word] ?? word);
42
- const sentence = words.join(" ");
43
- return sentence.charAt(0).toUpperCase() + sentence.slice(1);
33
+ const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim().toLowerCase().split(/\s+/).map(word => acronyms[word] ?? word);
34
+ const sentence = words.join(" ");
35
+ return sentence.charAt(0).toUpperCase() + sentence.slice(1);
44
36
  }
45
37
  function rawJson(input) {
46
- return JSON.stringify(input, null, 2) ?? "undefined";
38
+ return JSON.stringify(input, null, 2) ?? "undefined";
39
+ }
40
+ export function ToolInputs(t0) {
41
+ const $ = _c(22);
42
+ const {
43
+ input,
44
+ muted: t1
45
+ } = t0;
46
+ const muted = t1 === undefined ? false : t1;
47
+ const [showRaw, setShowRaw] = useState(false);
48
+ const rawId = useId();
49
+ let entries;
50
+ let t2;
51
+ let t3;
52
+ let t4;
53
+ if ($[0] !== input || $[1] !== muted || $[2] !== showRaw) {
54
+ entries = isPlainRecord(input) ? Object.entries(input) : null;
55
+ t2 = "tool-inputs";
56
+ t3 = "flex flex-col gap-2";
57
+ t4 = entries && !showRaw && /*#__PURE__*/_jsxs("dl", {
58
+ className: cn("-mx-5 flex flex-col divide-y border-y text-sm", muted && "text-muted-foreground"),
59
+ children: [entries.map(_temp), entries.length === 0 && /*#__PURE__*/_jsx("div", {
60
+ className: "px-5 py-2.5 text-xs text-muted-foreground",
61
+ children: "No inputs."
62
+ })]
63
+ });
64
+ $[0] = input;
65
+ $[1] = muted;
66
+ $[2] = showRaw;
67
+ $[3] = entries;
68
+ $[4] = t2;
69
+ $[5] = t3;
70
+ $[6] = t4;
71
+ } else {
72
+ entries = $[3];
73
+ t2 = $[4];
74
+ t3 = $[5];
75
+ t4 = $[6];
76
+ }
77
+ let t5;
78
+ if ($[7] !== entries || $[8] !== input || $[9] !== rawId || $[10] !== showRaw) {
79
+ t5 = (showRaw || !entries) && /*#__PURE__*/_jsx("pre", {
80
+ id: rawId,
81
+ className: "overflow-x-auto bg-muted/40 p-3 font-mono text-xs",
82
+ children: rawJson(input)
83
+ });
84
+ $[7] = entries;
85
+ $[8] = input;
86
+ $[9] = rawId;
87
+ $[10] = showRaw;
88
+ $[11] = t5;
89
+ } else {
90
+ t5 = $[11];
91
+ }
92
+ let t6;
93
+ if ($[12] !== entries || $[13] !== rawId || $[14] !== showRaw) {
94
+ t6 = entries && /*#__PURE__*/_jsx("button", {
95
+ type: "button",
96
+ className: "eyebrow self-start outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-safe:transition-colors",
97
+ "aria-expanded": showRaw,
98
+ "aria-controls": showRaw ? rawId : undefined,
99
+ onClick: () => setShowRaw(_temp2),
100
+ children: showRaw ? "Show fields" : "Show raw"
101
+ });
102
+ $[12] = entries;
103
+ $[13] = rawId;
104
+ $[14] = showRaw;
105
+ $[15] = t6;
106
+ } else {
107
+ t6 = $[15];
108
+ }
109
+ let t7;
110
+ if ($[16] !== t2 || $[17] !== t3 || $[18] !== t4 || $[19] !== t5 || $[20] !== t6) {
111
+ t7 = /*#__PURE__*/_jsxs("div", {
112
+ "data-slot": t2,
113
+ className: t3,
114
+ children: [t4, t5, t6]
115
+ });
116
+ $[16] = t2;
117
+ $[17] = t3;
118
+ $[18] = t4;
119
+ $[19] = t5;
120
+ $[20] = t6;
121
+ $[21] = t7;
122
+ } else {
123
+ t7 = $[21];
124
+ }
125
+ return t7;
126
+ }
127
+ function _temp2(current) {
128
+ return !current;
47
129
  }
48
- export function ToolInputs({ input, muted = false }) {
49
- const [showRaw, setShowRaw] = useState(false);
50
- const rawId = useId();
51
- const entries = isPlainRecord(input) ? Object.entries(input) : null;
52
- return (_jsxs("div", { "data-slot": "tool-inputs", className: "flex flex-col gap-2", children: [entries && !showRaw && (_jsxs("dl", { className: cn("-mx-5 flex flex-col divide-y border-y text-sm", muted && "text-muted-foreground"), children: [entries.map(([key, value]) => (_jsxs("div", { className: "grid grid-cols-[minmax(0,8.5rem)_minmax(0,1fr)] items-baseline gap-3 px-5 py-2.5", children: [_jsx("dt", { className: "text-xs text-muted-foreground", children: humanizeKey(key) }), _jsx("dd", { className: "font-mono text-sm break-words", children: readableValue(value) })] }, key))), entries.length === 0 && (_jsx("div", { className: "px-5 py-2.5 text-xs text-muted-foreground", children: "No inputs." }))] })), (showRaw || !entries) && (_jsx("pre", { id: rawId, className: "overflow-x-auto bg-muted/40 p-3 font-mono text-xs", children: rawJson(input) })), entries && (_jsx("button", { type: "button", className: "eyebrow self-start outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/70 motion-safe:transition-colors", "aria-expanded": showRaw, "aria-controls": showRaw ? rawId : undefined, onClick: () => setShowRaw((current) => !current), children: showRaw ? "Show fields" : "Show raw" }))] }));
130
+ function _temp(t0) {
131
+ const [key, value] = t0;
132
+ return /*#__PURE__*/_jsxs("div", {
133
+ className: "grid grid-cols-[minmax(0,8.5rem)_minmax(0,1fr)] items-baseline gap-3 px-5 py-2.5",
134
+ children: [/*#__PURE__*/_jsx("dt", {
135
+ className: "text-xs text-muted-foreground",
136
+ children: humanizeKey(key)
137
+ }), /*#__PURE__*/_jsx("dd", {
138
+ className: "font-mono text-sm break-words",
139
+ children: readableValue(value)
140
+ })]
141
+ }, key);
53
142
  }
@@ -0,0 +1,3 @@
1
+ import { type ReactNode } from "react";
2
+ export declare function gapBeforeItem(items: ReactNode[], index: number): number;
3
+ export declare function isPositionable(node: ReactNode): node is React.ReactElement;
@@ -0,0 +1,19 @@
1
+ import { Fragment, isValidElement } from "react";
2
+ const turnGapPx = 32;
3
+ const answerAfterQuestionGapPx = 16;
4
+ function roleOf(node) {
5
+ if (!isValidElement(node)) {
6
+ return undefined;
7
+ }
8
+ return node.props["data-role"] ?? node.props.message?.role;
9
+ }
10
+ export function gapBeforeItem(items, index) {
11
+ if (index === 0) {
12
+ return 0;
13
+ }
14
+ const answersQuestion = roleOf(items[index - 1]) === "user" && roleOf(items[index]) === "assistant";
15
+ return answersQuestion ? answerAfterQuestionGapPx : turnGapPx;
16
+ }
17
+ export function isPositionable(node) {
18
+ return isValidElement(node) && node.type !== Fragment && typeof node.type !== "string";
19
+ }
@@ -3,5 +3,6 @@ export type ChatProps = React.ComponentProps<"div"> & {
3
3
  empty?: React.ReactNode;
4
4
  label?: string;
5
5
  jumpLabel?: string;
6
+ virtualize?: boolean;
6
7
  };
7
- export declare function Chat({ children, empty, label, jumpLabel, className, ...props }: ChatProps): React.JSX.Element;
8
+ export declare function Chat({ children, empty, label, jumpLabel, virtualize, className, ...props }: ChatProps): React.JSX.Element;
@@ -1,11 +1,187 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+
3
+ import { c as _c } from "react/compiler-runtime";
3
4
  import { ArrowDown as ArrowDownIcon } from "@carbon/icons-react";
4
5
  import { Button, cn } from "@locusgraph/components";
5
6
  import * as React from "react";
7
+ import { shouldVirtualize } from "../../shared/virtual/use-list-virtualizer.js";
6
8
  import { useStickToBottom } from "./use-stick-to-bottom.js";
7
- export function Chat({ children, empty, label = "Chat", jumpLabel = "Jump to latest", className, ...props }) {
8
- const { viewportRef, contentRef, isAtBottom, handleScroll, scrollToLatest } = useStickToBottom();
9
- const isEmpty = React.Children.toArray(children).length === 0;
10
- return (_jsxs("div", { "data-slot": "chat", "data-empty": isEmpty || undefined, className: cn("relative flex min-h-0 flex-1 flex-col overflow-hidden", className), ...props, children: [_jsx("div", { ref: viewportRef, "data-slot": "chat-viewport", role: "log", "aria-label": label, tabIndex: 0, onScroll: handleScroll, className: "min-h-0 flex-1 overflow-y-auto overscroll-contain outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset", children: _jsx("div", { ref: contentRef, "data-slot": "chat-content", className: "mx-auto flex min-h-full w-full max-w-3xl flex-col gap-8 px-4 py-6 [&>[data-role=user]+[data-role=assistant]]:-mt-4", children: isEmpty ? (_jsx("div", { "data-slot": "chat-empty", className: "flex flex-1 flex-col items-center justify-center text-center", children: empty })) : (children) }) }), !isEmpty && !isAtBottom && (_jsxs(Button, { type: "button", variant: "outline", size: "sm", "data-slot": "chat-jump", onClick: scrollToLatest, className: "absolute bottom-3 left-1/2 h-7 -translate-x-1/2 bg-card px-3 text-xs text-muted-foreground shadow-none hover:text-foreground motion-safe:animate-in motion-safe:fade-in-0 dark:bg-card", children: [_jsx(ArrowDownIcon, { "aria-hidden": "true", className: "size-3.5" }), jumpLabel] }))] }));
9
+ import { VirtualChatItems } from "./virtual-chat-items.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ export function Chat(t0) {
12
+ const $ = _c(43);
13
+ let children;
14
+ let className;
15
+ let empty;
16
+ let props;
17
+ let t1;
18
+ let t2;
19
+ let t3;
20
+ if ($[0] !== t0) {
21
+ ({
22
+ children,
23
+ empty,
24
+ label: t1,
25
+ jumpLabel: t2,
26
+ virtualize: t3,
27
+ className,
28
+ ...props
29
+ } = t0);
30
+ $[0] = t0;
31
+ $[1] = children;
32
+ $[2] = className;
33
+ $[3] = empty;
34
+ $[4] = props;
35
+ $[5] = t1;
36
+ $[6] = t2;
37
+ $[7] = t3;
38
+ } else {
39
+ children = $[1];
40
+ className = $[2];
41
+ empty = $[3];
42
+ props = $[4];
43
+ t1 = $[5];
44
+ t2 = $[6];
45
+ t3 = $[7];
46
+ }
47
+ const label = t1 === undefined ? "Chat" : t1;
48
+ const jumpLabel = t2 === undefined ? "Jump to latest" : t2;
49
+ const virtualize = t3 === undefined ? true : t3;
50
+ const {
51
+ viewportRef,
52
+ contentRef,
53
+ isAtBottom,
54
+ handleScroll,
55
+ scrollToLatest
56
+ } = useStickToBottom();
57
+ const [scrolling, setScrolling] = React.useState(false);
58
+ let isEmpty;
59
+ let items;
60
+ let t4;
61
+ if ($[8] !== children || $[9] !== virtualize) {
62
+ items = React.Children.toArray(children);
63
+ isEmpty = items.length === 0;
64
+ t4 = shouldVirtualize(items.length, virtualize);
65
+ $[8] = children;
66
+ $[9] = virtualize;
67
+ $[10] = isEmpty;
68
+ $[11] = items;
69
+ $[12] = t4;
70
+ } else {
71
+ isEmpty = $[10];
72
+ items = $[11];
73
+ t4 = $[12];
74
+ }
75
+ const isVirtual = t4;
76
+ const t5 = isEmpty || undefined;
77
+ const t6 = isVirtual || undefined;
78
+ let t7;
79
+ if ($[13] !== className) {
80
+ t7 = cn("relative flex min-h-0 flex-1 flex-col overflow-hidden", className);
81
+ $[13] = className;
82
+ $[14] = t7;
83
+ } else {
84
+ t7 = $[14];
85
+ }
86
+ const t8 = isVirtual && scrolling || undefined;
87
+ let t9;
88
+ if ($[15] !== children || $[16] !== empty || $[17] !== isEmpty || $[18] !== isVirtual || $[19] !== items || $[20] !== viewportRef) {
89
+ t9 = isEmpty ? /*#__PURE__*/_jsx("div", {
90
+ "data-slot": "chat-empty",
91
+ className: "flex flex-1 flex-col items-center justify-center text-center",
92
+ children: empty
93
+ }) : isVirtual ? /*#__PURE__*/_jsx(VirtualChatItems, {
94
+ items: items,
95
+ viewportRef: viewportRef,
96
+ onScrollingChange: setScrolling
97
+ }) : children;
98
+ $[15] = children;
99
+ $[16] = empty;
100
+ $[17] = isEmpty;
101
+ $[18] = isVirtual;
102
+ $[19] = items;
103
+ $[20] = viewportRef;
104
+ $[21] = t9;
105
+ } else {
106
+ t9 = $[21];
107
+ }
108
+ let t10;
109
+ if ($[22] !== contentRef || $[23] !== t9) {
110
+ t10 = /*#__PURE__*/_jsx("div", {
111
+ ref: contentRef,
112
+ "data-slot": "chat-content",
113
+ className: "mx-auto flex min-h-full w-full max-w-3xl flex-col gap-8 px-4 py-6 [&>[data-role=user]+[data-role=assistant]]:-mt-4",
114
+ children: t9
115
+ });
116
+ $[22] = contentRef;
117
+ $[23] = t9;
118
+ $[24] = t10;
119
+ } else {
120
+ t10 = $[24];
121
+ }
122
+ let t11;
123
+ if ($[25] !== handleScroll || $[26] !== label || $[27] !== t10 || $[28] !== t8 || $[29] !== viewportRef) {
124
+ t11 = /*#__PURE__*/_jsx("div", {
125
+ ref: viewportRef,
126
+ "data-slot": "chat-viewport",
127
+ role: "log",
128
+ "aria-label": label,
129
+ "aria-busy": t8,
130
+ tabIndex: 0,
131
+ onScroll: handleScroll,
132
+ className: "min-h-0 flex-1 overflow-y-auto overscroll-contain outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-inset",
133
+ children: t10
134
+ });
135
+ $[25] = handleScroll;
136
+ $[26] = label;
137
+ $[27] = t10;
138
+ $[28] = t8;
139
+ $[29] = viewportRef;
140
+ $[30] = t11;
141
+ } else {
142
+ t11 = $[30];
143
+ }
144
+ let t12;
145
+ if ($[31] !== isAtBottom || $[32] !== isEmpty || $[33] !== jumpLabel || $[34] !== scrollToLatest) {
146
+ t12 = !isEmpty && !isAtBottom && /*#__PURE__*/_jsxs(Button, {
147
+ type: "button",
148
+ variant: "outline",
149
+ size: "sm",
150
+ "data-slot": "chat-jump",
151
+ onClick: scrollToLatest,
152
+ className: "absolute bottom-3 left-1/2 h-7 -translate-x-1/2 bg-card px-3 text-xs text-muted-foreground shadow-none hover:text-foreground motion-safe:animate-in motion-safe:fade-in-0 dark:bg-card",
153
+ children: [/*#__PURE__*/_jsx(ArrowDownIcon, {
154
+ "aria-hidden": "true",
155
+ className: "size-3.5"
156
+ }), jumpLabel]
157
+ });
158
+ $[31] = isAtBottom;
159
+ $[32] = isEmpty;
160
+ $[33] = jumpLabel;
161
+ $[34] = scrollToLatest;
162
+ $[35] = t12;
163
+ } else {
164
+ t12 = $[35];
165
+ }
166
+ let t13;
167
+ if ($[36] !== props || $[37] !== t11 || $[38] !== t12 || $[39] !== t5 || $[40] !== t6 || $[41] !== t7) {
168
+ t13 = /*#__PURE__*/_jsxs("div", {
169
+ "data-slot": "chat",
170
+ "data-empty": t5,
171
+ "data-virtual": t6,
172
+ className: t7,
173
+ ...props,
174
+ children: [t11, t12]
175
+ });
176
+ $[36] = props;
177
+ $[37] = t11;
178
+ $[38] = t12;
179
+ $[39] = t5;
180
+ $[40] = t6;
181
+ $[41] = t7;
182
+ $[42] = t13;
183
+ } else {
184
+ t13 = $[42];
185
+ }
186
+ return t13;
11
187
  }
@@ -1,57 +1,133 @@
1
+ import { c as _c } from "react/compiler-runtime";
1
2
  import { useCallback, useEffect, useRef, useState } from "react";
2
3
  const bottomThresholdPx = 48;
3
4
  function distanceFromBottom(element) {
4
- return element.scrollHeight - element.scrollTop - element.clientHeight;
5
+ return element.scrollHeight - element.scrollTop - element.clientHeight;
5
6
  }
6
7
  function prefersReducedMotion() {
7
- return (typeof window !== "undefined" &&
8
- window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true);
8
+ return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
9
+ }
10
+ function scrolledUpByReader(viewport, previous) {
11
+ return viewport.scrollTop < previous.top && viewport.scrollHeight === previous.height;
9
12
  }
10
13
  export function useStickToBottom() {
11
- const viewportRef = useRef(null);
12
- const contentRef = useRef(null);
13
- const stuckRef = useRef(true);
14
- const [isAtBottom, setIsAtBottom] = useState(true);
15
- const pinToBottom = useCallback(() => {
16
- const viewport = viewportRef.current;
17
- if (viewport) {
18
- viewport.scrollTop = viewport.scrollHeight;
19
- }
20
- }, []);
21
- const handleScroll = useCallback(() => {
22
- const viewport = viewportRef.current;
23
- if (!viewport) {
24
- return;
25
- }
26
- const atBottom = distanceFromBottom(viewport) <= bottomThresholdPx;
27
- stuckRef.current = atBottom;
28
- setIsAtBottom(atBottom);
29
- }, []);
30
- const scrollToLatest = useCallback(() => {
31
- const viewport = viewportRef.current;
32
- if (!viewport) {
33
- return;
34
- }
14
+ const $ = _c(8);
15
+ const viewportRef = useRef(null);
16
+ const contentRef = useRef(null);
17
+ const stuckRef = useRef(true);
18
+ let t0;
19
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20
+ t0 = {
21
+ top: 0,
22
+ height: 0
23
+ };
24
+ $[0] = t0;
25
+ } else {
26
+ t0 = $[0];
27
+ }
28
+ const lastScrollRef = useRef(t0);
29
+ const [isAtBottom, setIsAtBottom] = useState(true);
30
+ let t1;
31
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
32
+ t1 = () => {
33
+ const viewport = viewportRef.current;
34
+ if (viewport) {
35
+ viewport.scrollTop = viewport.scrollHeight;
36
+ }
37
+ };
38
+ $[1] = t1;
39
+ } else {
40
+ t1 = $[1];
41
+ }
42
+ const pinToBottom = t1;
43
+ let t2;
44
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
45
+ t2 = () => {
46
+ const viewport_0 = viewportRef.current;
47
+ if (!viewport_0) {
48
+ return;
49
+ }
50
+ const atBottom = distanceFromBottom(viewport_0) <= bottomThresholdPx;
51
+ const readerScrolledUp = scrolledUpByReader(viewport_0, lastScrollRef.current);
52
+ lastScrollRef.current = {
53
+ top: viewport_0.scrollTop,
54
+ height: viewport_0.scrollHeight
55
+ };
56
+ if (atBottom) {
35
57
  stuckRef.current = true;
36
- setIsAtBottom(true);
37
- viewport.scrollTo({
38
- top: viewport.scrollHeight,
39
- behavior: prefersReducedMotion() ? "auto" : "smooth",
40
- });
41
- }, []);
42
- useEffect(() => {
43
- const content = contentRef.current;
44
- if (!content || typeof ResizeObserver === "undefined") {
45
- return;
58
+ } else {
59
+ if (readerScrolledUp) {
60
+ stuckRef.current = false;
61
+ } else {
62
+ if (stuckRef.current) {
63
+ pinToBottom();
64
+ }
65
+ }
66
+ }
67
+ setIsAtBottom(stuckRef.current);
68
+ };
69
+ $[2] = t2;
70
+ } else {
71
+ t2 = $[2];
72
+ }
73
+ const handleScroll = t2;
74
+ let t3;
75
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
76
+ t3 = () => {
77
+ const viewport_1 = viewportRef.current;
78
+ if (!viewport_1) {
79
+ return;
80
+ }
81
+ stuckRef.current = true;
82
+ setIsAtBottom(true);
83
+ viewport_1.scrollTo({
84
+ top: viewport_1.scrollHeight,
85
+ behavior: prefersReducedMotion() ? "auto" : "smooth"
86
+ });
87
+ };
88
+ $[3] = t3;
89
+ } else {
90
+ t3 = $[3];
91
+ }
92
+ const scrollToLatest = t3;
93
+ let t4;
94
+ let t5;
95
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
96
+ t4 = () => {
97
+ const content = contentRef.current;
98
+ if (!content || typeof ResizeObserver === "undefined") {
99
+ return;
100
+ }
101
+ pinToBottom();
102
+ const observer = new ResizeObserver(() => {
103
+ if (stuckRef.current) {
104
+ pinToBottom();
46
105
  }
47
- pinToBottom();
48
- const observer = new ResizeObserver(() => {
49
- if (stuckRef.current) {
50
- pinToBottom();
51
- }
52
- });
53
- observer.observe(content);
54
- return () => observer.disconnect();
55
- }, [pinToBottom]);
56
- return { viewportRef, contentRef, isAtBottom, handleScroll, scrollToLatest };
106
+ });
107
+ observer.observe(content);
108
+ return () => observer.disconnect();
109
+ };
110
+ t5 = [pinToBottom];
111
+ $[4] = t4;
112
+ $[5] = t5;
113
+ } else {
114
+ t4 = $[4];
115
+ t5 = $[5];
116
+ }
117
+ useEffect(t4, t5);
118
+ let t6;
119
+ if ($[6] !== isAtBottom) {
120
+ t6 = {
121
+ viewportRef,
122
+ contentRef,
123
+ isAtBottom,
124
+ handleScroll,
125
+ scrollToLatest
126
+ };
127
+ $[6] = isAtBottom;
128
+ $[7] = t6;
129
+ } else {
130
+ t6 = $[7];
131
+ }
132
+ return t6;
57
133
  }
@@ -0,0 +1,8 @@
1
+ import { type ReactNode, type RefObject } from "react";
2
+ type VirtualChatItemsProps = {
3
+ items: ReactNode[];
4
+ viewportRef: RefObject<HTMLDivElement | null>;
5
+ onScrollingChange: (scrolling: boolean) => void;
6
+ };
7
+ export declare function VirtualChatItems({ items, viewportRef, onScrollingChange }: VirtualChatItemsProps): import("react").JSX.Element;
8
+ export {};