nucleus-core-ts 0.9.169 → 0.9.171

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.
@@ -100,7 +100,7 @@ export function ChatPanel(props) {
100
100
  ]
101
101
  }),
102
102
  /*#__PURE__*/ _jsxs("div", {
103
- className: "flex flex-1 flex-col",
103
+ className: "flex min-h-0 flex-1 flex-col",
104
104
  children: [
105
105
  /*#__PURE__*/ _jsx(MessageThread, {
106
106
  conversation: active,
@@ -19,7 +19,8 @@ function previewFor(message) {
19
19
  export function useChat(props) {
20
20
  const { currentUserId, actions, topic = 'chat', wsUrl, wsPath } = props;
21
21
  const store = useChatStore();
22
- const processedRef = useRef(0);
22
+ const lastSeenEventIdRef = useRef(null);
23
+ const eventsInitializedRef = useRef(false);
23
24
  const typingSentAtRef = useRef(0);
24
25
  const pubsub = usePubSub({
25
26
  userId: currentUserId,
@@ -244,17 +245,29 @@ export function useChat(props) {
244
245
  useEffect(()=>{
245
246
  loadConversations();
246
247
  }, []);
248
+ // The pubsub store PREPENDS events (newest at index 0) and caps the buffer,
249
+ // so index/count tracking is unsafe. Track the last-seen event id instead:
250
+ // collect everything newer than it (newest-first), then replay oldest-first.
251
+ // The initial mount skips the existing backlog — history loads via REST.
247
252
  useEffect(()=>{
248
253
  const events = pubsub.events;
249
- for(let i = processedRef.current; i < events.length; i++){
250
- const event = events[i];
251
- if (event && event.topic === topic) {
252
- handleRealtime(event.data);
253
- }
254
+ if (!eventsInitializedRef.current) {
255
+ eventsInitializedRef.current = true;
256
+ lastSeenEventIdRef.current = events[0]?.id ?? null;
257
+ return;
258
+ }
259
+ const fresh = [];
260
+ for (const event of events){
261
+ if (event.id === lastSeenEventIdRef.current) break;
262
+ fresh.push(event);
263
+ }
264
+ lastSeenEventIdRef.current = events[0]?.id ?? lastSeenEventIdRef.current;
265
+ for(let i = fresh.length - 1; i >= 0; i--){
266
+ const event = fresh[i];
267
+ if (event.topic === topic) handleRealtime(event.data);
254
268
  }
255
- processedRef.current = events.length;
256
269
  }, [
257
- pubsub.events.length
270
+ pubsub.events[0]?.id
258
271
  ]);
259
272
  return {
260
273
  store,
@@ -21,11 +21,11 @@ export declare const chatPanelTheme: {
21
21
  readonly badge: "ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-emerald-500 px-1.5 text-[11px] font-semibold text-white";
22
22
  };
23
23
  readonly thread: {
24
- readonly base: "flex flex-1 flex-col";
24
+ readonly base: "flex min-h-0 flex-1 flex-col";
25
25
  readonly header: "flex items-center gap-3 border-b border-zinc-200 px-5 py-3 dark:border-zinc-800";
26
26
  readonly headerTitle: "text-sm font-semibold";
27
27
  readonly headerSubtitle: "text-xs text-zinc-400";
28
- readonly messages: "flex flex-1 flex-col gap-2 overflow-y-auto px-5 py-4";
28
+ readonly messages: "flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-5 py-4";
29
29
  readonly loadMore: "mx-auto mb-2 rounded-full border border-zinc-200 px-3 py-1 text-xs text-zinc-500 transition hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900";
30
30
  readonly empty: "flex flex-1 items-center justify-center text-sm text-zinc-400";
31
31
  readonly placeholder: "flex flex-1 items-center justify-center px-6 text-center text-sm text-zinc-400";
@@ -20,11 +20,11 @@ export const chatPanelTheme = {
20
20
  badge: 'ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-emerald-500 px-1.5 text-[11px] font-semibold text-white'
21
21
  },
22
22
  thread: {
23
- base: 'flex flex-1 flex-col',
23
+ base: 'flex min-h-0 flex-1 flex-col',
24
24
  header: 'flex items-center gap-3 border-b border-zinc-200 px-5 py-3 dark:border-zinc-800',
25
25
  headerTitle: 'text-sm font-semibold',
26
26
  headerSubtitle: 'text-xs text-zinc-400',
27
- messages: 'flex flex-1 flex-col gap-2 overflow-y-auto px-5 py-4',
27
+ messages: 'flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-5 py-4',
28
28
  loadMore: 'mx-auto mb-2 rounded-full border border-zinc-200 px-3 py-1 text-xs text-zinc-500 transition hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900',
29
29
  empty: 'flex flex-1 items-center justify-center text-sm text-zinc-400',
30
30
  placeholder: 'flex flex-1 items-center justify-center px-6 text-center text-sm text-zinc-400'