@poolse/react 3.1.0 → 3.2.0-dev.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.
package/dist/index.d.cts CHANGED
@@ -324,6 +324,28 @@ interface UseTypingState {
324
324
  */
325
325
  declare function useTyping(conversationId: string): UseTypingState;
326
326
 
327
+ /** An AI agent's reply that's still being written. */
328
+ interface MessageStream {
329
+ /** Becomes the finished message's id. */
330
+ id: Uuid;
331
+ conversation_id: Uuid;
332
+ sender_id: Uuid;
333
+ sender_external_id: string | null;
334
+ /** The text so far; empty until the first delta. */
335
+ text: string;
336
+ status: 'streaming' | 'failed';
337
+ error?: string;
338
+ }
339
+ /**
340
+ * AI agent replies being written in `conversationId`, oldest first.
341
+ *
342
+ * Built from `message:stream` events: `started` adds a stream, each
343
+ * `delta` appends text, `failed` marks it failed (removed after a few
344
+ * seconds). When the finished reply arrives as `message:new` with the
345
+ * same id, the stream is removed — `useMessages` shows the message.
346
+ */
347
+ declare function useMessageStreams(conversationId: string): MessageStream[];
348
+
327
349
  interface UsePresenceState {
328
350
  /**
329
351
  * Set of `external_id`s currently online in this conversation —
@@ -692,4 +714,4 @@ declare function canEditOwnMessage(args: {
692
714
  now?: number;
693
715
  }): boolean;
694
716
 
695
- export { EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
717
+ export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
package/dist/index.d.ts CHANGED
@@ -324,6 +324,28 @@ interface UseTypingState {
324
324
  */
325
325
  declare function useTyping(conversationId: string): UseTypingState;
326
326
 
327
+ /** An AI agent's reply that's still being written. */
328
+ interface MessageStream {
329
+ /** Becomes the finished message's id. */
330
+ id: Uuid;
331
+ conversation_id: Uuid;
332
+ sender_id: Uuid;
333
+ sender_external_id: string | null;
334
+ /** The text so far; empty until the first delta. */
335
+ text: string;
336
+ status: 'streaming' | 'failed';
337
+ error?: string;
338
+ }
339
+ /**
340
+ * AI agent replies being written in `conversationId`, oldest first.
341
+ *
342
+ * Built from `message:stream` events: `started` adds a stream, each
343
+ * `delta` appends text, `failed` marks it failed (removed after a few
344
+ * seconds). When the finished reply arrives as `message:new` with the
345
+ * same id, the stream is removed — `useMessages` shows the message.
346
+ */
347
+ declare function useMessageStreams(conversationId: string): MessageStream[];
348
+
327
349
  interface UsePresenceState {
328
350
  /**
329
351
  * Set of `external_id`s currently online in this conversation —
@@ -692,4 +714,4 @@ declare function canEditOwnMessage(args: {
692
714
  now?: number;
693
715
  }): boolean;
694
716
 
695
- export { EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
717
+ export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
package/dist/index.js CHANGED
@@ -853,6 +853,62 @@ function useTyping(conversationId) {
853
853
  }, [chat, conversationId]);
854
854
  return { typing, signalTyping };
855
855
  }
856
+ var FAILED_TTL_MS = 8e3;
857
+ var STALE_MS = 9e4;
858
+ function useMessageStreams(conversationId) {
859
+ const chat = usePoolse();
860
+ const [streams, setStreams] = useState([]);
861
+ useEffect(() => {
862
+ setStreams([]);
863
+ const timers = /* @__PURE__ */ new Map();
864
+ const remove = (id) => {
865
+ const t = timers.get(id);
866
+ if (t) clearTimeout(t);
867
+ timers.delete(id);
868
+ setStreams(
869
+ (prev) => prev.some((s) => s.id === id) ? prev.filter((s) => s.id !== id) : prev
870
+ );
871
+ };
872
+ const arm = (id, ms) => {
873
+ const t = timers.get(id);
874
+ if (t) clearTimeout(t);
875
+ timers.set(
876
+ id,
877
+ setTimeout(() => remove(id), ms)
878
+ );
879
+ };
880
+ const conv = chat.realtime.conversation(conversationId);
881
+ const offStream = conv.onMessageStream((evt) => {
882
+ setStreams((prev) => {
883
+ const existing = prev.find((s) => s.id === evt.id);
884
+ const base = existing ?? {
885
+ id: evt.id,
886
+ conversation_id: evt.conversation_id,
887
+ sender_id: evt.sender_id,
888
+ sender_external_id: evt.sender_external_id ?? null,
889
+ text: "",
890
+ status: "streaming"
891
+ };
892
+ let next;
893
+ if (evt.status === "delta") next = { ...base, text: base.text + (evt.delta ?? "") };
894
+ else if (evt.status === "failed")
895
+ next = { ...base, status: "failed", ...evt.error ? { error: evt.error } : {} };
896
+ else
897
+ next = { ...base, sender_external_id: evt.sender_external_id ?? base.sender_external_id };
898
+ return existing ? prev.map((s) => s.id === evt.id ? next : s) : [...prev, next];
899
+ });
900
+ arm(evt.id, evt.status === "failed" ? FAILED_TTL_MS : STALE_MS);
901
+ });
902
+ const offMessage = conv.onMessage((msg) => remove(msg.id));
903
+ return () => {
904
+ offStream();
905
+ offMessage();
906
+ timers.forEach((t) => clearTimeout(t));
907
+ timers.clear();
908
+ };
909
+ }, [chat, conversationId]);
910
+ return streams;
911
+ }
856
912
  function externalIdsFrom(state) {
857
913
  const out = [];
858
914
  for (const presence of Object.values(state)) {
@@ -1398,6 +1454,6 @@ function canEditOwnMessage(args) {
1398
1454
  return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
1399
1455
  }
1400
1456
 
1401
- export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
1457
+ export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
1402
1458
  //# sourceMappingURL=index.js.map
1403
1459
  //# sourceMappingURL=index.js.map