@poolse/react-ui 3.1.0 → 3.2.0-dev.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffect, useMemo, Fragment as Fragment$1 } from 'react';
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
- import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel, canEditOwnMessage, formatCallLogPreview, useLiveCall, callLogDisplayFor, useThread, useReactions, useAttachmentUrl } from '@poolse/react';
4
+ import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useMessageStreams, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel, canEditOwnMessage, formatCallLogPreview, useLiveCall, callLogDisplayFor, useThread, useReactions, useAttachmentUrl } from '@poolse/react';
5
5
  import ReactMarkdown from 'react-markdown';
6
6
  import remarkGfm from 'remark-gfm';
7
7
 
@@ -2397,7 +2397,16 @@ function ConversationView({
2397
2397
  delete: deleteMsg,
2398
2398
  markReadUpTo
2399
2399
  } = useMessages(conversationId);
2400
- const { typing, signalTyping } = useTyping(conversationId);
2400
+ const { typing: typingPeople, signalTyping } = useTyping(conversationId);
2401
+ const streams = useMessageStreams(conversationId);
2402
+ const typing = useMemo(() => {
2403
+ const thinking = streams.filter((s) => s.status === "streaming" && !s.text);
2404
+ if (thinking.length === 0) return typingPeople;
2405
+ const next = new Set(typingPeople);
2406
+ for (const s of thinking) if (s.sender_external_id) next.add(s.sender_external_id);
2407
+ return next;
2408
+ }, [typingPeople, streams]);
2409
+ const visibleStreams = streams.filter((s) => s.text || s.status === "failed");
2401
2410
  const status = useRealtimeStatus();
2402
2411
  const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
2403
2412
  const membersOn = mentions || readReceipts || wantsMemberCount;
@@ -2465,6 +2474,12 @@ function ConversationView({
2465
2474
  setNewCountWhileAway((n) => n + 1);
2466
2475
  }
2467
2476
  }, [messages, atBottom, me]);
2477
+ const streamedChars = visibleStreams.reduce((n, s) => n + s.text.length, 0);
2478
+ useEffect(() => {
2479
+ if (!atBottom || streamedChars === 0) return;
2480
+ const el = listRef.current;
2481
+ if (el) el.scrollTop = el.scrollHeight;
2482
+ }, [streamedChars, atBottom]);
2468
2483
  const lastMarkedReadRef = useRef(null);
2469
2484
  useEffect(() => {
2470
2485
  if (!atBottom) return;
@@ -2703,6 +2718,23 @@ function ConversationView({
2703
2718
  )
2704
2719
  ] }, msg.id);
2705
2720
  }),
2721
+ visibleStreams.map(
2722
+ (stream) => stream.status === "failed" ? /* @__PURE__ */ jsx("div", { className: "poolse-stream-failed", role: "status", children: stream.error ? `The agent couldn't reply: ${stream.error}` : "The agent couldn't reply." }, stream.id) : /* @__PURE__ */ jsx("div", { className: "poolse-stream", "aria-busy": "true", children: /* @__PURE__ */ jsx(
2723
+ MessageRow,
2724
+ {
2725
+ msg: streamingMessage(stream),
2726
+ meId: me?.id ?? null,
2727
+ reactions: false,
2728
+ actions: false,
2729
+ threads: false,
2730
+ quotations: false,
2731
+ markdown,
2732
+ showSenderName: showSenderLabelsResolved,
2733
+ showAvatar: showAvatarsResolved,
2734
+ ...labelFor ? { labelFor } : {}
2735
+ }
2736
+ ) }, stream.id)
2737
+ ),
2706
2738
  error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
2707
2739
  "Failed to load: ",
2708
2740
  error.message
@@ -2756,6 +2788,27 @@ function JoinBanner({
2756
2788
  if (meId !== null && participantIds.includes(meId)) return null;
2757
2789
  return /* @__PURE__ */ jsx(LiveCallBanner, { call, inCall: participantIds.length, onJoin });
2758
2790
  }
2791
+ function streamingMessage(stream) {
2792
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2793
+ return {
2794
+ id: stream.id,
2795
+ tenant_id: "",
2796
+ conversation_id: stream.conversation_id,
2797
+ sender_id: stream.sender_id,
2798
+ sender_external_id: stream.sender_external_id,
2799
+ type: "text",
2800
+ body: stream.text,
2801
+ reply_to_id: null,
2802
+ thread_root_id: null,
2803
+ mentions: [],
2804
+ reactions: {},
2805
+ edited_at: null,
2806
+ deleted_at: null,
2807
+ sequence: Number.MAX_SAFE_INTEGER,
2808
+ inserted_at: now,
2809
+ updated_at: now
2810
+ };
2811
+ }
2759
2812
  function ChatHeader({
2760
2813
  conversationId,
2761
2814
  labelFor,