@poolse/react 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/CHANGELOG.md +14 -0
- package/dist/index.cjs +61 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +61 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -324,6 +324,30 @@ 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
|
+
/** The tool the agent is running right now, if any (cleared by the next text). */
|
|
338
|
+
tool?: string;
|
|
339
|
+
error?: string;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* AI agent replies being written in `conversationId`, oldest first.
|
|
343
|
+
*
|
|
344
|
+
* Built from `message:stream` events: `started` adds a stream, each
|
|
345
|
+
* `delta` appends text, `failed` marks it failed (removed after a few
|
|
346
|
+
* seconds). When the finished reply arrives as `message:new` with the
|
|
347
|
+
* same id, the stream is removed — `useMessages` shows the message.
|
|
348
|
+
*/
|
|
349
|
+
declare function useMessageStreams(conversationId: string): MessageStream[];
|
|
350
|
+
|
|
327
351
|
interface UsePresenceState {
|
|
328
352
|
/**
|
|
329
353
|
* Set of `external_id`s currently online in this conversation —
|
|
@@ -692,4 +716,4 @@ declare function canEditOwnMessage(args: {
|
|
|
692
716
|
now?: number;
|
|
693
717
|
}): boolean;
|
|
694
718
|
|
|
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 };
|
|
719
|
+
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,30 @@ 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
|
+
/** The tool the agent is running right now, if any (cleared by the next text). */
|
|
338
|
+
tool?: string;
|
|
339
|
+
error?: string;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* AI agent replies being written in `conversationId`, oldest first.
|
|
343
|
+
*
|
|
344
|
+
* Built from `message:stream` events: `started` adds a stream, each
|
|
345
|
+
* `delta` appends text, `failed` marks it failed (removed after a few
|
|
346
|
+
* seconds). When the finished reply arrives as `message:new` with the
|
|
347
|
+
* same id, the stream is removed — `useMessages` shows the message.
|
|
348
|
+
*/
|
|
349
|
+
declare function useMessageStreams(conversationId: string): MessageStream[];
|
|
350
|
+
|
|
327
351
|
interface UsePresenceState {
|
|
328
352
|
/**
|
|
329
353
|
* Set of `external_id`s currently online in this conversation —
|
|
@@ -692,4 +716,4 @@ declare function canEditOwnMessage(args: {
|
|
|
692
716
|
now?: number;
|
|
693
717
|
}): boolean;
|
|
694
718
|
|
|
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 };
|
|
719
|
+
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,66 @@ 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") {
|
|
894
|
+
const { tool: _done, ...rest } = base;
|
|
895
|
+
next = { ...rest, text: base.text + (evt.delta ?? "") };
|
|
896
|
+
} else if (evt.status === "tool")
|
|
897
|
+
next = { ...base, ...evt.tool ? { tool: evt.tool } : {} };
|
|
898
|
+
else if (evt.status === "failed")
|
|
899
|
+
next = { ...base, status: "failed", ...evt.error ? { error: evt.error } : {} };
|
|
900
|
+
else
|
|
901
|
+
next = { ...base, sender_external_id: evt.sender_external_id ?? base.sender_external_id };
|
|
902
|
+
return existing ? prev.map((s) => s.id === evt.id ? next : s) : [...prev, next];
|
|
903
|
+
});
|
|
904
|
+
arm(evt.id, evt.status === "failed" ? FAILED_TTL_MS : STALE_MS);
|
|
905
|
+
});
|
|
906
|
+
const offMessage = conv.onMessage((msg) => remove(msg.id));
|
|
907
|
+
return () => {
|
|
908
|
+
offStream();
|
|
909
|
+
offMessage();
|
|
910
|
+
timers.forEach((t) => clearTimeout(t));
|
|
911
|
+
timers.clear();
|
|
912
|
+
};
|
|
913
|
+
}, [chat, conversationId]);
|
|
914
|
+
return streams;
|
|
915
|
+
}
|
|
856
916
|
function externalIdsFrom(state) {
|
|
857
917
|
const out = [];
|
|
858
918
|
for (const presence of Object.values(state)) {
|
|
@@ -1398,6 +1458,6 @@ function canEditOwnMessage(args) {
|
|
|
1398
1458
|
return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
|
|
1399
1459
|
}
|
|
1400
1460
|
|
|
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 };
|
|
1461
|
+
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
1462
|
//# sourceMappingURL=index.js.map
|
|
1403
1463
|
//# sourceMappingURL=index.js.map
|