@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
@@ -0,0 +1,23 @@
1
+ export function historyListRows(groups) {
2
+ return groups.flatMap(group => [{
3
+ kind: "group",
4
+ key: `group:${group.key}`,
5
+ groupKey: group.key,
6
+ label: group.label
7
+ }, ...group.threads.map((thread, index) => ({
8
+ kind: "thread",
9
+ key: thread.id,
10
+ thread,
11
+ position: index + 1,
12
+ groupSize: group.threads.length
13
+ }))]);
14
+ }
15
+ const groupLabelHeightPx = 24;
16
+ const groupGapPx = 16;
17
+ const threadRowHeightPx = 32;
18
+ export function estimatedRowHeight(row, index) {
19
+ if (row.kind === "thread") {
20
+ return threadRowHeightPx;
21
+ }
22
+ return index === 0 ? groupLabelHeightPx : groupLabelHeightPx + groupGapPx;
23
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ComponentProps } from "react";
2
- import { type HistoryItem } from "./history-row.js";
2
+ import { type HistoryItem } from "./row/history-row.js";
3
3
  type HistoryProps = Omit<ComponentProps<"nav">, "onSelect"> & {
4
4
  threads: HistoryItem[];
5
5
  activeId?: string | null;
@@ -10,6 +10,7 @@ type HistoryProps = Omit<ComponentProps<"nav">, "onSelect"> & {
10
10
  label?: string;
11
11
  emptyText?: string;
12
12
  now?: Date | string;
13
+ virtualize?: boolean;
13
14
  };
14
- export declare function History({ threads, activeId, onSelect, onNew, onRename, onArchive, label, emptyText, now, className, ...props }: HistoryProps): import("react").JSX.Element;
15
+ export declare function History({ threads, activeId, onSelect, onNew, onRename, onArchive, label, emptyText, now, virtualize, className, ...props }: HistoryProps): import("react").JSX.Element;
15
16
  export {};
@@ -1,10 +1,179 @@
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 { Add as PlusIcon } from "@carbon/icons-react";
4
5
  import { Button, cn, ScrollArea } from "@locusgraph/components";
5
- import { HistoryRow } from "./history-row.js";
6
+ import { shouldVirtualize } from "../../shared/virtual/use-list-virtualizer.js";
7
+ import { HistoryRow } from "./row/history-row.js";
6
8
  import { groupThreadsByDay } from "./thread-groups.js";
7
- export function History({ threads, activeId = null, onSelect, onNew, onRename, onArchive, label = "Conversations", emptyText = "No conversations yet.", now = new Date(), className, ...props }) {
8
- const groups = groupThreadsByDay(threads, now);
9
- return (_jsxs("nav", { "data-slot": "history", "aria-label": label, className: cn("flex min-h-0 flex-col gap-2", className), ...props, children: [_jsxs("div", { className: "flex h-7 items-center justify-between gap-2 px-2", children: [_jsx("span", { className: "text-sm font-medium text-foreground", children: label }), onNew && (_jsxs(Button, { type: "button", variant: "outline", size: "xs", onClick: onNew, children: [_jsx(PlusIcon, {}), "New chat"] }))] }), threads.length === 0 ? (_jsx("p", { className: "px-2 py-6 text-sm text-muted-foreground", children: emptyText })) : (_jsx(ScrollArea, { className: "min-h-0 flex-1", children: _jsx("div", { className: "flex flex-col gap-4 pr-2.5 pb-2", children: groups.map((group) => (_jsxs("section", { "aria-labelledby": `thread-group-${group.key}`, children: [_jsx("h3", { id: `thread-group-${group.key}`, className: "eyebrow px-2 pb-1", suppressHydrationWarning: true, children: group.label }), _jsx("ul", { className: "flex flex-col", children: group.threads.map((thread) => (_jsx(HistoryRow, { thread: thread, active: thread.id === activeId, onSelect: onSelect, onRename: onRename, onArchive: onArchive }, thread.id))) })] }, group.key))) }) }))] }));
9
+ import { VirtualHistoryList } from "./virtual-history-list.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ export function History(t0) {
12
+ const $ = _c(35);
13
+ let className;
14
+ let now;
15
+ let onArchive;
16
+ let onNew;
17
+ let onRename;
18
+ let onSelect;
19
+ let props;
20
+ let t1;
21
+ let t2;
22
+ let t3;
23
+ let t4;
24
+ let threads;
25
+ if ($[0] !== t0) {
26
+ ({
27
+ threads,
28
+ activeId: t1,
29
+ onSelect,
30
+ onNew,
31
+ onRename,
32
+ onArchive,
33
+ label: t2,
34
+ emptyText: t3,
35
+ now,
36
+ virtualize: t4,
37
+ className,
38
+ ...props
39
+ } = t0);
40
+ $[0] = t0;
41
+ $[1] = className;
42
+ $[2] = now;
43
+ $[3] = onArchive;
44
+ $[4] = onNew;
45
+ $[5] = onRename;
46
+ $[6] = onSelect;
47
+ $[7] = props;
48
+ $[8] = t1;
49
+ $[9] = t2;
50
+ $[10] = t3;
51
+ $[11] = t4;
52
+ $[12] = threads;
53
+ } else {
54
+ className = $[1];
55
+ now = $[2];
56
+ onArchive = $[3];
57
+ onNew = $[4];
58
+ onRename = $[5];
59
+ onSelect = $[6];
60
+ props = $[7];
61
+ t1 = $[8];
62
+ t2 = $[9];
63
+ t3 = $[10];
64
+ t4 = $[11];
65
+ threads = $[12];
66
+ }
67
+ const activeId = t1 === undefined ? null : t1;
68
+ const label = t2 === undefined ? "Conversations" : t2;
69
+ const emptyText = t3 === undefined ? "No conversations yet." : t3;
70
+ const virtualize = t4 === undefined ? true : t4;
71
+ let t5;
72
+ if ($[13] !== activeId || $[14] !== className || $[15] !== emptyText || $[16] !== label || $[17] !== now || $[18] !== onArchive || $[19] !== onNew || $[20] !== onRename || $[21] !== onSelect || $[22] !== props || $[23] !== threads || $[24] !== virtualize) {
73
+ const groups = groupThreadsByDay(threads, now ?? new Date());
74
+ let t6;
75
+ if ($[26] !== className) {
76
+ t6 = cn("flex min-h-0 flex-col gap-2", className);
77
+ $[26] = className;
78
+ $[27] = t6;
79
+ } else {
80
+ t6 = $[27];
81
+ }
82
+ let t7;
83
+ if ($[28] !== label) {
84
+ t7 = /*#__PURE__*/_jsx("span", {
85
+ className: "text-sm font-medium text-foreground",
86
+ children: label
87
+ });
88
+ $[28] = label;
89
+ $[29] = t7;
90
+ } else {
91
+ t7 = $[29];
92
+ }
93
+ let t8;
94
+ if ($[30] !== onNew) {
95
+ t8 = onNew && /*#__PURE__*/_jsxs(Button, {
96
+ type: "button",
97
+ variant: "outline",
98
+ size: "xs",
99
+ onClick: onNew,
100
+ children: [/*#__PURE__*/_jsx(PlusIcon, {}), "New chat"]
101
+ });
102
+ $[30] = onNew;
103
+ $[31] = t8;
104
+ } else {
105
+ t8 = $[31];
106
+ }
107
+ let t9;
108
+ if ($[32] !== t7 || $[33] !== t8) {
109
+ t9 = /*#__PURE__*/_jsxs("div", {
110
+ className: "flex h-7 items-center justify-between gap-2 px-2",
111
+ children: [t7, t8]
112
+ });
113
+ $[32] = t7;
114
+ $[33] = t8;
115
+ $[34] = t9;
116
+ } else {
117
+ t9 = $[34];
118
+ }
119
+ t5 = /*#__PURE__*/_jsxs("nav", {
120
+ "data-slot": "history",
121
+ "aria-label": label,
122
+ className: t6,
123
+ ...props,
124
+ children: [t9, threads.length === 0 ? /*#__PURE__*/_jsx("p", {
125
+ className: "px-2 py-6 text-sm text-muted-foreground",
126
+ children: emptyText
127
+ }) : /*#__PURE__*/_jsx(ScrollArea, {
128
+ className: "min-h-0 flex-1",
129
+ children: shouldVirtualize(threads.length, virtualize) ? /*#__PURE__*/_jsx("div", {
130
+ className: "pr-2.5 pb-2",
131
+ children: /*#__PURE__*/_jsx(VirtualHistoryList, {
132
+ groups: groups,
133
+ label: label,
134
+ activeId: activeId,
135
+ onSelect: onSelect,
136
+ onRename: onRename,
137
+ onArchive: onArchive
138
+ })
139
+ }) : /*#__PURE__*/_jsx("div", {
140
+ className: "flex flex-col gap-4 pr-2.5 pb-2",
141
+ children: groups.map(group => /*#__PURE__*/_jsxs("section", {
142
+ "aria-labelledby": `thread-group-${group.key}`,
143
+ children: [/*#__PURE__*/_jsx("h3", {
144
+ id: `thread-group-${group.key}`,
145
+ className: "eyebrow px-2 pb-1",
146
+ suppressHydrationWarning: true,
147
+ children: group.label
148
+ }), /*#__PURE__*/_jsx("ul", {
149
+ className: "flex flex-col",
150
+ children: group.threads.map(thread => /*#__PURE__*/_jsx(HistoryRow, {
151
+ thread: thread,
152
+ active: thread.id === activeId,
153
+ onSelect: onSelect,
154
+ onRename: onRename,
155
+ onArchive: onArchive
156
+ }, thread.id))
157
+ })]
158
+ }, group.key))
159
+ })
160
+ })]
161
+ });
162
+ $[13] = activeId;
163
+ $[14] = className;
164
+ $[15] = emptyText;
165
+ $[16] = label;
166
+ $[17] = now;
167
+ $[18] = onArchive;
168
+ $[19] = onNew;
169
+ $[20] = onRename;
170
+ $[21] = onSelect;
171
+ $[22] = props;
172
+ $[23] = threads;
173
+ $[24] = virtualize;
174
+ $[25] = t5;
175
+ } else {
176
+ t5 = $[25];
177
+ }
178
+ return t5;
10
179
  }
@@ -1,14 +1,15 @@
1
+ import { type ComponentProps } from "react";
1
2
  export type HistoryItem = {
2
3
  id: string;
3
4
  title: string;
4
5
  updatedAt: string;
5
6
  };
6
- type HistoryRowProps = {
7
+ type HistoryRowProps = Omit<ComponentProps<"li">, "onSelect"> & {
7
8
  thread: HistoryItem;
8
9
  active: boolean;
9
10
  onSelect: (id: string) => void;
10
11
  onRename?: (id: string, title: string) => void;
11
12
  onArchive?: (id: string) => void;
12
13
  };
13
- export declare function HistoryRow({ thread, active, onSelect, onRename, onArchive }: HistoryRowProps): import("react").JSX.Element;
14
+ export declare function HistoryRow({ thread, active, onSelect, onRename, onArchive, className, ...props }: HistoryRowProps): import("react").JSX.Element;
14
15
  export {};
@@ -0,0 +1,58 @@
1
+ import { cn } from "@locusgraph/components";
2
+ import { useState } from "react";
3
+ import { formatTimeOfDay } from "../thread-groups.js";
4
+ import { ThreadItemMenu } from "./thread-item-menu.js";
5
+ import { ThreadTitleEditor } from "./thread-title-editor.js";
6
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
+ const timeHiddenByMenuClass = "max-sm:hidden sm:group-focus-within:invisible sm:group-hover:invisible sm:group-has-[[data-state=open]]:invisible";
8
+ export function HistoryRow({
9
+ thread,
10
+ active,
11
+ onSelect,
12
+ onRename,
13
+ onArchive,
14
+ className,
15
+ ...props
16
+ }) {
17
+ const [editing, setEditing] = useState(false);
18
+ const hasMenu = onRename !== undefined || onArchive !== undefined;
19
+ return /*#__PURE__*/_jsxs("li", {
20
+ "data-slot": "history-item",
21
+ "data-active": active || undefined,
22
+ className: cn("group relative flex items-center motion-safe:transition-colors", active ? "bg-accent text-accent-foreground before:absolute before:inset-y-0 before:left-0 before:w-0.5 before:bg-foreground" : "text-foreground/85 hover:bg-accent/40", className),
23
+ ...props,
24
+ children: [editing && onRename ? /*#__PURE__*/_jsx("div", {
25
+ className: "flex-1 px-1 py-0.5",
26
+ children: /*#__PURE__*/_jsx(ThreadTitleEditor, {
27
+ title: thread.title,
28
+ onCommit: title => {
29
+ onRename(thread.id, title);
30
+ setEditing(false);
31
+ },
32
+ onCancel: () => setEditing(false)
33
+ })
34
+ }) : /*#__PURE__*/_jsxs("button", {
35
+ type: "button",
36
+ "aria-current": active ? "page" : undefined,
37
+ onClick: () => onSelect(thread.id),
38
+ onDoubleClick: onRename ? () => setEditing(true) : undefined,
39
+ className: cn("flex min-w-0 flex-1 items-center gap-3 py-1.5 pl-2 text-left text-sm outline-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring", hasMenu ? "pr-8 sm:pr-2" : "pr-2", active && "font-medium"),
40
+ children: [/*#__PURE__*/_jsx("span", {
41
+ className: "min-w-0 flex-1 truncate",
42
+ children: thread.title
43
+ }), /*#__PURE__*/_jsx("time", {
44
+ dateTime: thread.updatedAt,
45
+ suppressHydrationWarning: true,
46
+ className: cn("shrink-0 font-mono text-[11px] font-normal text-muted-foreground tabular-nums", hasMenu && timeHiddenByMenuClass),
47
+ children: formatTimeOfDay(thread.updatedAt)
48
+ })]
49
+ }), hasMenu && !editing && /*#__PURE__*/_jsx("div", {
50
+ className: "absolute top-1/2 right-1 -translate-y-1/2",
51
+ children: /*#__PURE__*/_jsx(ThreadItemMenu, {
52
+ title: thread.title,
53
+ onRename: onRename ? () => setEditing(true) : undefined,
54
+ onArchive: onArchive ? () => onArchive(thread.id) : undefined
55
+ })
56
+ })]
57
+ });
58
+ }
@@ -0,0 +1,31 @@
1
+ import { Archive as ArchiveIcon, OverflowMenuHorizontal as EllipsisIcon, Edit as PencilIcon } from "@carbon/icons-react";
2
+ import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@locusgraph/components";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ export function ThreadItemMenu({
5
+ title,
6
+ onRename,
7
+ onArchive
8
+ }) {
9
+ return /*#__PURE__*/_jsxs(DropdownMenu, {
10
+ children: [/*#__PURE__*/_jsx(DropdownMenuTrigger, {
11
+ asChild: true,
12
+ children: /*#__PURE__*/_jsx(Button, {
13
+ type: "button",
14
+ variant: "ghost",
15
+ size: "icon-xs",
16
+ "aria-label": `Options for ${title}`,
17
+ className: "shrink-0 text-muted-foreground sm:opacity-0 sm:group-focus-within:opacity-100 sm:group-hover:opacity-100 sm:data-[state=open]:opacity-100",
18
+ children: /*#__PURE__*/_jsx(EllipsisIcon, {})
19
+ })
20
+ }), /*#__PURE__*/_jsxs(DropdownMenuContent, {
21
+ align: "end",
22
+ children: [onRename && /*#__PURE__*/_jsxs(DropdownMenuItem, {
23
+ onSelect: onRename,
24
+ children: [/*#__PURE__*/_jsx(PencilIcon, {}), "Rename"]
25
+ }), onArchive && /*#__PURE__*/_jsxs(DropdownMenuItem, {
26
+ onSelect: onArchive,
27
+ children: [/*#__PURE__*/_jsx(ArchiveIcon, {}), "Archive"]
28
+ })]
29
+ })]
30
+ });
31
+ }
@@ -0,0 +1,38 @@
1
+ import { Input } from "@locusgraph/components";
2
+ import { useState } from "react";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export function ThreadTitleEditor({
5
+ title,
6
+ onCommit,
7
+ onCancel
8
+ }) {
9
+ const [draft, setDraft] = useState(title);
10
+ const commit = () => {
11
+ const trimmed = draft.trim();
12
+ if (trimmed && trimmed !== title) {
13
+ onCommit(trimmed);
14
+ } else {
15
+ onCancel();
16
+ }
17
+ };
18
+ return /*#__PURE__*/_jsx(Input, {
19
+ "data-slot": "thread-title-editor",
20
+ "aria-label": "Chat title",
21
+ autoFocus: true,
22
+ value: draft,
23
+ className: "h-7 text-sm",
24
+ onChange: event => setDraft(event.target.value),
25
+ onFocus: event => event.target.select(),
26
+ onBlur: commit,
27
+ onKeyDown: event => {
28
+ if (event.key === "Enter") {
29
+ event.preventDefault();
30
+ commit();
31
+ }
32
+ if (event.key === "Escape") {
33
+ event.preventDefault();
34
+ onCancel();
35
+ }
36
+ }
37
+ });
38
+ }
@@ -1,4 +1,4 @@
1
- import type { HistoryItem } from "./history-row.js";
1
+ import type { HistoryItem } from "./row/history-row.js";
2
2
  export type ThreadGroup = {
3
3
  key: string;
4
4
  label: string;
@@ -1,46 +1,52 @@
1
1
  const timeOfDay = new Intl.DateTimeFormat("en-US", {
2
- hour: "2-digit",
3
- minute: "2-digit",
4
- hourCycle: "h23",
2
+ hour: "2-digit",
3
+ minute: "2-digit",
4
+ hourCycle: "h23"
5
+ });
6
+ const calendarDate = new Intl.DateTimeFormat("en-US", {
7
+ dateStyle: "medium"
5
8
  });
6
- const calendarDate = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" });
7
9
  function localDayStart(value) {
8
- const date = new Date(value);
9
- if (Number.isNaN(date.getTime())) {
10
- return undefined;
11
- }
12
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
10
+ const date = new Date(value);
11
+ if (Number.isNaN(date.getTime())) {
12
+ return undefined;
13
+ }
14
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
13
15
  }
14
16
  function daysBetween(earlier, later) {
15
- const utcOf = (date) => Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
16
- return Math.round((utcOf(later) - utcOf(earlier)) / 86_400_000);
17
+ const utcOf = date => Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
18
+ return Math.round((utcOf(later) - utcOf(earlier)) / 86_400_000);
17
19
  }
18
20
  function dayLabel(day, today) {
19
- if (!day) {
20
- return "Earlier";
21
- }
22
- const daysAgo = today ? daysBetween(day, today) : Number.NaN;
23
- if (daysAgo === 0) {
24
- return "Today";
25
- }
26
- if (daysAgo === 1) {
27
- return "Yesterday";
28
- }
29
- return calendarDate.format(day);
21
+ if (!day) {
22
+ return "Earlier";
23
+ }
24
+ const daysAgo = today ? daysBetween(day, today) : Number.NaN;
25
+ if (daysAgo === 0) {
26
+ return "Today";
27
+ }
28
+ if (daysAgo === 1) {
29
+ return "Yesterday";
30
+ }
31
+ return calendarDate.format(day);
30
32
  }
31
33
  export function formatTimeOfDay(value) {
32
- const date = new Date(value);
33
- return Number.isNaN(date.getTime()) ? "" : timeOfDay.format(date);
34
+ const date = new Date(value);
35
+ return Number.isNaN(date.getTime()) ? "" : timeOfDay.format(date);
34
36
  }
35
37
  export function groupThreadsByDay(threads, now) {
36
- const today = localDayStart(now);
37
- const groups = new Map();
38
- for (const thread of threads) {
39
- const day = localDayStart(thread.updatedAt);
40
- const key = day ? String(day.getTime()) : "earlier";
41
- const group = groups.get(key) ?? { key, label: dayLabel(day, today), threads: [] };
42
- group.threads.push(thread);
43
- groups.set(key, group);
44
- }
45
- return [...groups.values()];
38
+ const today = localDayStart(now);
39
+ const groups = new Map();
40
+ for (const thread of threads) {
41
+ const day = localDayStart(thread.updatedAt);
42
+ const key = day ? String(day.getTime()) : "earlier";
43
+ const group = groups.get(key) ?? {
44
+ key,
45
+ label: dayLabel(day, today),
46
+ threads: []
47
+ };
48
+ group.threads.push(thread);
49
+ groups.set(key, group);
50
+ }
51
+ return [...groups.values()];
46
52
  }
@@ -0,0 +1,11 @@
1
+ import type { ThreadGroup } from "./thread-groups.js";
2
+ type VirtualHistoryListProps = {
3
+ groups: ThreadGroup[];
4
+ label: string;
5
+ activeId: string | null;
6
+ onSelect: (id: string) => void;
7
+ onRename?: (id: string, title: string) => void;
8
+ onArchive?: (id: string) => void;
9
+ };
10
+ export declare function VirtualHistoryList({ groups, label, activeId, onSelect, onRename, onArchive, }: VirtualHistoryListProps): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,71 @@
1
+ import { cn } from "@locusgraph/components";
2
+ import { useRef } from "react";
3
+ import { rowOffsetStyle, useListVirtualizer, virtualRowClassName } from "../../shared/virtual/use-list-virtualizer.js";
4
+ import { estimatedRowHeight, historyListRows } from "./history-rows.js";
5
+ import { HistoryRow } from "./row/history-row.js";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ function scrollAreaViewportOf(element) {
8
+ return element?.closest("[data-slot=scroll-area-viewport]") ?? null;
9
+ }
10
+ export function VirtualHistoryList({
11
+ groups,
12
+ label,
13
+ activeId,
14
+ onSelect,
15
+ onRename,
16
+ onArchive
17
+ }) {
18
+ const listRef = useRef(null);
19
+ const rows = historyListRows(groups);
20
+ const {
21
+ rows: visibleRows,
22
+ totalSize,
23
+ itemProps
24
+ } = useListVirtualizer({
25
+ count: rows.length,
26
+ getScrollElement: () => scrollAreaViewportOf(listRef.current),
27
+ estimateSize: index => estimatedRowHeight(rows[index], index),
28
+ getItemKey: index => rows[index].key
29
+ });
30
+ const threadRowProps = thread => ({
31
+ thread,
32
+ active: thread.id === activeId,
33
+ onSelect,
34
+ onRename,
35
+ onArchive
36
+ });
37
+ return /*#__PURE__*/_jsx("ul", {
38
+ ref: listRef,
39
+ "data-slot": "history-list",
40
+ "aria-label": label,
41
+ className: "relative",
42
+ style: {
43
+ height: totalSize
44
+ },
45
+ children: visibleRows.map(virtualRow => {
46
+ const row = rows[virtualRow.index];
47
+ if (row.kind === "group") {
48
+ return /*#__PURE__*/_jsx("li", {
49
+ role: "presentation",
50
+ ...itemProps(virtualRow.index),
51
+ className: cn(virtualRowClassName, virtualRow.index > 0 && "pt-4"),
52
+ style: rowOffsetStyle(virtualRow.start),
53
+ children: /*#__PURE__*/_jsx("h3", {
54
+ id: `thread-group-${row.groupKey}`,
55
+ className: "eyebrow px-2 pb-1",
56
+ suppressHydrationWarning: true,
57
+ children: row.label
58
+ })
59
+ }, virtualRow.key);
60
+ }
61
+ return /*#__PURE__*/_jsx(HistoryRow, {
62
+ ...threadRowProps(row.thread),
63
+ ...itemProps(virtualRow.index),
64
+ "aria-posinset": row.position,
65
+ "aria-setsize": row.groupSize,
66
+ className: virtualRowClassName,
67
+ style: rowOffsetStyle(virtualRow.start)
68
+ }, virtualRow.key);
69
+ })
70
+ });
71
+ }
@@ -4,5 +4,5 @@ export * from "./canvas/canvas.js";
4
4
  export type { CanvasVersion } from "./canvas/version-switcher.js";
5
5
  export * from "./code/code.js";
6
6
  export * from "./history/history.js";
7
- export type { HistoryItem } from "./history/history-row.js";
7
+ export type { HistoryItem } from "./history/row/history-row.js";
8
8
  export * from "./starters/starters.js";
@@ -1,15 +1,40 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { ArrowUpRight as ArrowUpRightIcon } from "@carbon/icons-react";
3
2
  import { cn } from "@locusgraph/components";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  function textOf(suggestion) {
5
- return typeof suggestion === "string" ? suggestion : suggestion.text;
5
+ return typeof suggestion === "string" ? suggestion : suggestion.text;
6
6
  }
7
7
  function labelOf(suggestion) {
8
- return typeof suggestion === "string" ? suggestion : (suggestion.label ?? suggestion.text);
8
+ return typeof suggestion === "string" ? suggestion : suggestion.label ?? suggestion.text;
9
9
  }
10
- export function Starters({ suggestions, onSelect, disabled = false, className, ...props }) {
11
- if (suggestions.length === 0) {
12
- return null;
13
- }
14
- return (_jsx("div", { "data-slot": "starters", role: "group", "aria-label": "Suggested prompts", className: cn("flex flex-col divide-y bg-card ring-1 ring-border", className), ...props, children: suggestions.map((suggestion) => (_jsxs("button", { type: "button", disabled: disabled, onClick: () => onSelect(textOf(suggestion)), className: "group flex w-full items-center gap-3 px-3 py-2.5 text-left text-sm outline-none hover:bg-accent/50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 motion-safe:transition-colors", children: [_jsx("span", { className: "min-w-0 flex-1 text-pretty", children: labelOf(suggestion) }), _jsx(ArrowUpRightIcon, { "aria-hidden": true, className: "size-3.5 shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100 motion-safe:transition-opacity" })] }, textOf(suggestion)))) }));
10
+ export function Starters({
11
+ suggestions,
12
+ onSelect,
13
+ disabled = false,
14
+ className,
15
+ ...props
16
+ }) {
17
+ if (suggestions.length === 0) {
18
+ return null;
19
+ }
20
+ return /*#__PURE__*/_jsx("div", {
21
+ "data-slot": "starters",
22
+ role: "group",
23
+ "aria-label": "Suggested prompts",
24
+ className: cn("flex flex-col divide-y bg-card ring-1 ring-border", className),
25
+ ...props,
26
+ children: suggestions.map(suggestion => /*#__PURE__*/_jsxs("button", {
27
+ type: "button",
28
+ disabled: disabled,
29
+ onClick: () => onSelect(textOf(suggestion)),
30
+ className: "group flex w-full items-center gap-3 px-3 py-2.5 text-left text-sm outline-none hover:bg-accent/50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 motion-safe:transition-colors",
31
+ children: [/*#__PURE__*/_jsx("span", {
32
+ className: "min-w-0 flex-1 text-pretty",
33
+ children: labelOf(suggestion)
34
+ }), /*#__PURE__*/_jsx(ArrowUpRightIcon, {
35
+ "aria-hidden": true,
36
+ className: "size-3.5 shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100 motion-safe:transition-opacity"
37
+ })]
38
+ }, textOf(suggestion)))
39
+ });
15
40
  }
@@ -1,22 +1,24 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
2
  const copiedDurationMs = 1500;
3
3
  export function useCopied() {
4
- const [copied, setCopied] = useState(false);
5
- const timer = useRef(undefined);
6
- useEffect(() => () => clearTimeout(timer.current), []);
7
- const markCopied = () => {
8
- setCopied(true);
9
- clearTimeout(timer.current);
10
- timer.current = setTimeout(() => setCopied(false), copiedDurationMs);
11
- };
12
- return { copied, markCopied };
4
+ const [copied, setCopied] = useState(false);
5
+ const timer = useRef(undefined);
6
+ useEffect(() => () => clearTimeout(timer.current), []);
7
+ const markCopied = () => {
8
+ setCopied(true);
9
+ clearTimeout(timer.current);
10
+ timer.current = setTimeout(() => setCopied(false), copiedDurationMs);
11
+ };
12
+ return {
13
+ copied,
14
+ markCopied
15
+ };
13
16
  }
14
17
  export async function writeToClipboard(text) {
15
- try {
16
- await navigator.clipboard.writeText(text);
17
- return true;
18
- }
19
- catch {
20
- return false;
21
- }
18
+ try {
19
+ await navigator.clipboard.writeText(text);
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
22
24
  }
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export function toolNameOf(part) {
2
- return part.toolName ?? part.type.replace(/^tool-/, "");
2
+ return part.toolName ?? part.type.replace(/^tool-/, "");
3
3
  }