@cossistant/react 0.0.19 → 0.0.22

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 (101) hide show
  1. package/conversation.d.ts +28 -0
  2. package/conversation.d.ts.map +1 -1
  3. package/hooks/index.d.ts +4 -1
  4. package/hooks/index.js +4 -1
  5. package/hooks/private/use-default-messages.js +1 -1
  6. package/hooks/private/use-default-messages.js.map +1 -1
  7. package/hooks/private/use-grouped-messages.d.ts.map +1 -1
  8. package/hooks/private/use-grouped-messages.js +4 -18
  9. package/hooks/private/use-grouped-messages.js.map +1 -1
  10. package/hooks/private/use-rest-client.js +1 -1
  11. package/hooks/private/use-rest-client.js.map +1 -1
  12. package/hooks/private/use-visitor-typing-reporter.js +3 -3
  13. package/hooks/private/use-visitor-typing-reporter.js.map +1 -1
  14. package/hooks/use-conversation-auto-seen.d.ts +1 -1
  15. package/hooks/use-conversation-auto-seen.js +30 -46
  16. package/hooks/use-conversation-auto-seen.js.map +1 -1
  17. package/hooks/use-conversation-page.js +1 -1
  18. package/hooks/use-conversation-page.js.map +1 -1
  19. package/hooks/use-conversation-seen.d.ts.map +1 -1
  20. package/hooks/use-conversation-seen.js +7 -3
  21. package/hooks/use-conversation-seen.js.map +1 -1
  22. package/hooks/use-new-message-sound.d.ts +23 -0
  23. package/hooks/use-new-message-sound.d.ts.map +1 -0
  24. package/hooks/use-new-message-sound.js +34 -0
  25. package/hooks/use-new-message-sound.js.map +1 -0
  26. package/hooks/use-send-message.js +1 -1
  27. package/hooks/use-send-message.js.map +1 -1
  28. package/hooks/use-sound-effect.d.ts +30 -0
  29. package/hooks/use-sound-effect.d.ts.map +1 -0
  30. package/hooks/use-sound-effect.js +104 -0
  31. package/hooks/use-sound-effect.js.map +1 -0
  32. package/hooks/use-typing-sound.d.ts +18 -0
  33. package/hooks/use-typing-sound.d.ts.map +1 -0
  34. package/hooks/use-typing-sound.js +38 -0
  35. package/hooks/use-typing-sound.js.map +1 -0
  36. package/index.d.ts +5 -2
  37. package/index.js +8 -6
  38. package/package.json +3 -3
  39. package/primitives/avatar/image.d.ts +1 -1
  40. package/primitives/bubble.js +1 -1
  41. package/primitives/index.d.ts +3 -5
  42. package/primitives/index.js +3 -9
  43. package/primitives/index.parts.d.ts +2 -4
  44. package/primitives/index.parts.js +2 -4
  45. package/primitives/router.d.ts +19 -20
  46. package/primitives/router.d.ts.map +1 -1
  47. package/primitives/router.js +17 -11
  48. package/primitives/router.js.map +1 -1
  49. package/realtime/index.js +1 -1
  50. package/realtime/provider.d.ts +1 -0
  51. package/realtime/provider.d.ts.map +1 -1
  52. package/realtime/provider.js +59 -10
  53. package/realtime/provider.js.map +1 -1
  54. package/realtime-events.d.ts +14 -0
  55. package/realtime-events.d.ts.map +1 -1
  56. package/schemas3.d.ts +7 -0
  57. package/schemas3.d.ts.map +1 -1
  58. package/support/components/bubble.d.ts.map +1 -1
  59. package/support/components/bubble.js +27 -4
  60. package/support/components/bubble.js.map +1 -1
  61. package/support/components/conversation-event.js +1 -1
  62. package/support/components/conversation-event.js.map +1 -1
  63. package/support/components/conversation-timeline.d.ts.map +1 -1
  64. package/support/components/conversation-timeline.js +5 -0
  65. package/support/components/conversation-timeline.js.map +1 -1
  66. package/support/components/support-content.d.ts +2 -0
  67. package/support/components/support-content.d.ts.map +1 -1
  68. package/support/components/support-content.js +5 -2
  69. package/support/components/support-content.js.map +1 -1
  70. package/support/components/timeline-message-group.js +2 -2
  71. package/support/components/timeline-message-group.js.map +1 -1
  72. package/support/components/timeline-message-item.js +2 -2
  73. package/support/components/timeline-message-item.js.map +1 -1
  74. package/support/components/typing-indicator.d.ts.map +1 -1
  75. package/support/index.d.ts +12 -7
  76. package/support/index.d.ts.map +1 -1
  77. package/support/index.js +28 -29
  78. package/support/index.js.map +1 -1
  79. package/support/pages/conversation.d.ts.map +1 -1
  80. package/support/pages/conversation.js +19 -1
  81. package/support/pages/conversation.js.map +1 -1
  82. package/support/router.d.ts +19 -9
  83. package/support/router.d.ts.map +1 -1
  84. package/support/router.js +31 -30
  85. package/support/router.js.map +1 -1
  86. package/support/text/runtime.js +1 -1
  87. package/support/text/runtime.js.map +1 -1
  88. package/support/utils/time.d.ts +1 -0
  89. package/support/utils/time.d.ts.map +1 -1
  90. package/support/utils/time.js +2 -0
  91. package/support/utils/time.js.map +1 -1
  92. package/timeline-item.d.ts +14 -0
  93. package/timeline-item.d.ts.map +1 -1
  94. package/primitives/page-registry.d.ts +0 -30
  95. package/primitives/page-registry.d.ts.map +0 -1
  96. package/primitives/page-registry.js +0 -45
  97. package/primitives/page-registry.js.map +0 -1
  98. package/primitives/page.d.ts +0 -21
  99. package/primitives/page.d.ts.map +0 -1
  100. package/primitives/page.js +0 -18
  101. package/primitives/page.js.map +0 -1
package/conversation.d.ts CHANGED
@@ -62,6 +62,13 @@ declare const createConversationResponseSchema: ZodObject<{
62
62
  mediaType: ZodString;
63
63
  fileName: ZodOptional<ZodString>;
64
64
  size: ZodOptional<ZodNumber>;
65
+ }, $strip>, ZodObject<{
66
+ type: ZodLiteral<"metadata">;
67
+ source: ZodEnum<{
68
+ email: "email";
69
+ widget: "widget";
70
+ api: "api";
71
+ }>;
65
72
  }, $strip>]>>;
66
73
  userId: ZodNullable<ZodString>;
67
74
  aiAgentId: ZodNullable<ZodString>;
@@ -137,6 +144,13 @@ declare const createConversationResponseSchema: ZodObject<{
137
144
  mediaType: ZodString;
138
145
  fileName: ZodOptional<ZodString>;
139
146
  size: ZodOptional<ZodNumber>;
147
+ }, $strip>, ZodObject<{
148
+ type: ZodLiteral<"metadata">;
149
+ source: ZodEnum<{
150
+ email: "email";
151
+ widget: "widget";
152
+ api: "api";
153
+ }>;
140
154
  }, $strip>]>>;
141
155
  userId: ZodNullable<ZodString>;
142
156
  aiAgentId: ZodNullable<ZodString>;
@@ -234,6 +248,13 @@ declare const listConversationsResponseSchema: ZodObject<{
234
248
  mediaType: ZodString;
235
249
  fileName: ZodOptional<ZodString>;
236
250
  size: ZodOptional<ZodNumber>;
251
+ }, $strip>, ZodObject<{
252
+ type: ZodLiteral<"metadata">;
253
+ source: ZodEnum<{
254
+ email: "email";
255
+ widget: "widget";
256
+ api: "api";
257
+ }>;
237
258
  }, $strip>]>>;
238
259
  userId: ZodNullable<ZodString>;
239
260
  aiAgentId: ZodNullable<ZodString>;
@@ -324,6 +345,13 @@ declare const getConversationResponseSchema: ZodObject<{
324
345
  mediaType: ZodString;
325
346
  fileName: ZodOptional<ZodString>;
326
347
  size: ZodOptional<ZodNumber>;
348
+ }, $strip>, ZodObject<{
349
+ type: ZodLiteral<"metadata">;
350
+ source: ZodEnum<{
351
+ email: "email";
352
+ widget: "widget";
353
+ api: "api";
354
+ }>;
327
355
  }, $strip>]>>;
328
356
  userId: ZodNullable<ZodString>;
329
357
  aiAgentId: ZodNullable<ZodString>;
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","names":[],"sources":["../../types/src/api/conversation.ts"],"sourcesContent":[],"mappings":";;;;;;;;cA8Ba,kCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA,CAAA,CAAA;MAAA,IAAA,aAAA,UAAA,CAAA;MASjC,IAAA,aAAA,YAA8B,UAClC,CAAA,CAAA;MAGK,KAAA,UAAA,SA2BV,CAAA,SAAA,UAAA,CAAA;;;;;;;;;;;;;;UA3BwC,WAAA,EAAA,aAAA;UAAA,QAAA,EAAA,UAAA;UA6B/B,QAAA,EAAA,UAAwB;UAIvB,eAAA,EAAA,iBAaV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAlDS,8BAAA,GAAiC,cACrC;cAGK,gCAA8B;;;;;;;;;;;;;;;;;KA6B/B,wBAAA,GAA2B,cAC/B;cAGK,iCAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAAA,cAAA,EAAA,gBAAA;UAAA,gBAAA,EAAA,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BAAA,EAAA,uBAAA;UAAA,kBAAA,EAAA,oBAAA;UAU7B,gBAAsB,EAAA,kBAC1B;UAGK,cAAA,EAMV,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAxBS,yBAAA,GAA4B,cAChC;cAGK,8BAA4B;;;KAU7B,sBAAA,GAAyB,cAC7B;cAGK,+BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAAA,IAAA,YAAA,CAAA,MAAA,CAAA;QAAA,IAAA,WAAA;MAQ9B,CAAA,QAAA,CAAA,WAAuB,CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KADI,uBAAA,GAA0B,cAC9B"}
package/hooks/index.d.ts CHANGED
@@ -18,9 +18,12 @@ import { UseConversationsOptions, UseConversationsResult, useConversations } fro
18
18
  import { CreateConversationVariables, UseCreateConversationOptions, UseCreateConversationResult, useCreateConversation } from "./use-create-conversation.js";
19
19
  import { UseHomePageOptions, UseHomePageReturn, useHomePage } from "./use-home-page.js";
20
20
  import { UseMessageComposerOptions, UseMessageComposerReturn, useMessageComposer } from "./use-message-composer.js";
21
+ import { useNewMessageSound } from "./use-new-message-sound.js";
21
22
  import { UseRealtimeSupportOptions, UseRealtimeSupportResult, useRealtimeSupport } from "./use-realtime-support.js";
22
23
  import { UseScrollMaskOptions, UseScrollMaskReturn, useScrollMask } from "./use-scroll-mask.js";
23
24
  import { SendMessageOptions, SendMessageResult, UseSendMessageOptions, UseSendMessageResult, useSendMessage } from "./use-send-message.js";
25
+ import { UseSoundEffectOptions, UseSoundEffectReturn, useSoundEffect } from "./use-sound-effect.js";
26
+ import { useTypingSound } from "./use-typing-sound.js";
24
27
  import { UseVisitorReturn, useVisitor } from "./use-visitor.js";
25
28
  import { WindowVisibilityFocusState, useWindowVisibilityFocus } from "./use-window-visibility-focus.js";
26
- export { CONVERSATION_AUTO_SEEN_DELAY_MS, ConversationItem, ConversationLifecycleState, ConversationPreviewAssignedAgent, ConversationPreviewLastMessage, ConversationPreviewTypingParticipant, ConversationPreviewTypingState, ConversationTimelineTypingParticipant, ConversationTypingParticipant, CreateConversationVariables, GroupedMessage, SendMessageOptions, SendMessageResult, TimelineEventItem, TimelineToolItem, UseClientResult, UseComposerRefocusOptions, UseComposerRefocusReturn, UseConversationAutoSeenOptions, UseConversationHistoryPageOptions, UseConversationHistoryPageReturn, UseConversationLifecycleOptions, UseConversationLifecycleReturn, UseConversationOptions, UseConversationPageOptions, UseConversationPageReturn, UseConversationPreviewOptions, UseConversationPreviewReturn, UseConversationResult, UseConversationTimelineItemsOptions, UseConversationTimelineItemsResult, UseConversationTimelineOptions, UseConversationTimelineReturn, UseConversationsOptions, UseConversationsResult, UseCreateConversationOptions, UseCreateConversationResult, UseGroupedMessagesOptions, UseGroupedMessagesProps, UseHomePageOptions, UseHomePageReturn, UseMessageComposerOptions, UseMessageComposerReturn, UseMultimodalInputOptions, UseMultimodalInputReturn, UseRealtimeSupportOptions, UseRealtimeSupportResult, UseScrollMaskOptions, UseScrollMaskReturn, UseSendMessageOptions, UseSendMessageResult, UseVisitorReturn, WindowVisibilityFocusState, useClient, useClientQuery, useComposerRefocus, useConversation, useConversationAutoSeen, useConversationHistoryPage, useConversationLifecycle, useConversationPage, useConversationPreview, useConversationSeen, useConversationTimeline, useConversationTimelineItems, useConversationTyping, useConversations, useCreateConversation, useDebouncedConversationSeen, useDefaultMessages, useGroupedMessages, useHomePage, useMessageComposer, useMultimodalInput, useRealtimeSupport, useScrollMask, useSendMessage, useVisitor, useWindowVisibilityFocus };
29
+ export { CONVERSATION_AUTO_SEEN_DELAY_MS, ConversationItem, ConversationLifecycleState, ConversationPreviewAssignedAgent, ConversationPreviewLastMessage, ConversationPreviewTypingParticipant, ConversationPreviewTypingState, ConversationTimelineTypingParticipant, ConversationTypingParticipant, CreateConversationVariables, GroupedMessage, SendMessageOptions, SendMessageResult, TimelineEventItem, TimelineToolItem, UseClientResult, UseComposerRefocusOptions, UseComposerRefocusReturn, UseConversationAutoSeenOptions, UseConversationHistoryPageOptions, UseConversationHistoryPageReturn, UseConversationLifecycleOptions, UseConversationLifecycleReturn, UseConversationOptions, UseConversationPageOptions, UseConversationPageReturn, UseConversationPreviewOptions, UseConversationPreviewReturn, UseConversationResult, UseConversationTimelineItemsOptions, UseConversationTimelineItemsResult, UseConversationTimelineOptions, UseConversationTimelineReturn, UseConversationsOptions, UseConversationsResult, UseCreateConversationOptions, UseCreateConversationResult, UseGroupedMessagesOptions, UseGroupedMessagesProps, UseHomePageOptions, UseHomePageReturn, UseMessageComposerOptions, UseMessageComposerReturn, UseMultimodalInputOptions, UseMultimodalInputReturn, UseRealtimeSupportOptions, UseRealtimeSupportResult, UseScrollMaskOptions, UseScrollMaskReturn, UseSendMessageOptions, UseSendMessageResult, UseSoundEffectOptions, UseSoundEffectReturn, UseVisitorReturn, WindowVisibilityFocusState, useClient, useClientQuery, useComposerRefocus, useConversation, useConversationAutoSeen, useConversationHistoryPage, useConversationLifecycle, useConversationPage, useConversationPreview, useConversationSeen, useConversationTimeline, useConversationTimelineItems, useConversationTyping, useConversations, useCreateConversation, useDebouncedConversationSeen, useDefaultMessages, useGroupedMessages, useHomePage, useMessageComposer, useMultimodalInput, useNewMessageSound, useRealtimeSupport, useScrollMask, useSendMessage, useSoundEffect, useTypingSound, useVisitor, useWindowVisibilityFocus };
package/hooks/index.js CHANGED
@@ -10,10 +10,13 @@ import { useMultimodalInput } from "./private/use-multimodal-input.js";
10
10
  import { useSendMessage } from "./use-send-message.js";
11
11
  import { useMessageComposer } from "./use-message-composer.js";
12
12
  import { useConversationPage } from "./use-conversation-page.js";
13
+ import { useSoundEffect } from "./use-sound-effect.js";
14
+ import { useNewMessageSound } from "./use-new-message-sound.js";
13
15
  import { useGroupedMessages } from "./private/use-grouped-messages.js";
14
16
  import { useConversationSeen, useDebouncedConversationSeen } from "./use-conversation-seen.js";
15
17
  import { useConversationTyping } from "./use-conversation-typing.js";
16
18
  import { useConversationTimeline } from "./use-conversation-timeline.js";
19
+ import { useTypingSound } from "./use-typing-sound.js";
17
20
  import { useComposerRefocus } from "./use-composer-refocus.js";
18
21
  import { useVisitor } from "./use-visitor.js";
19
22
  import { useConversations } from "./use-conversations.js";
@@ -24,4 +27,4 @@ import { useDefaultMessages } from "./private/use-default-messages.js";
24
27
  import { useCreateConversation } from "./use-create-conversation.js";
25
28
  import { useRealtimeSupport } from "./use-realtime-support.js";
26
29
 
27
- export { CONVERSATION_AUTO_SEEN_DELAY_MS, useClient, useClientQuery, useComposerRefocus, useConversation, useConversationAutoSeen, useConversationHistoryPage, useConversationLifecycle, useConversationPage, useConversationPreview, useConversationSeen, useConversationTimeline, useConversationTimelineItems, useConversationTyping, useConversations, useCreateConversation, useDebouncedConversationSeen, useDefaultMessages, useGroupedMessages, useHomePage, useMessageComposer, useMultimodalInput, useRealtimeSupport, useScrollMask, useSendMessage, useVisitor, useWindowVisibilityFocus };
30
+ export { CONVERSATION_AUTO_SEEN_DELAY_MS, useClient, useClientQuery, useComposerRefocus, useConversation, useConversationAutoSeen, useConversationHistoryPage, useConversationLifecycle, useConversationPage, useConversationPreview, useConversationSeen, useConversationTimeline, useConversationTimelineItems, useConversationTyping, useConversations, useCreateConversation, useDebouncedConversationSeen, useDefaultMessages, useGroupedMessages, useHomePage, useMessageComposer, useMultimodalInput, useNewMessageSound, useRealtimeSupport, useScrollMask, useSendMessage, useSoundEffect, useTypingSound, useVisitor, useWindowVisibilityFocus };
@@ -14,7 +14,7 @@ function useDefaultMessages({ conversationId }) {
14
14
  const { defaultMessages, availableAIAgents, availableHumanAgents } = useSupport();
15
15
  return useMemo(() => defaultMessages.map((message, index) => {
16
16
  const messageId = generateMessageId();
17
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
17
+ const timestamp = typeof window !== "undefined" ? (/* @__PURE__ */ new Date()).toISOString() : "";
18
18
  return {
19
19
  id: messageId,
20
20
  conversationId,
@@ -1 +1 @@
1
- {"version":3,"file":"use-default-messages.js","names":[],"sources":["../../../src/hooks/private/use-default-messages.ts"],"sourcesContent":["import { generateMessageId } from \"@cossistant/core\";\nimport { SenderType } from \"@cossistant/types\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport { useMemo } from \"react\";\nimport { useSupport } from \"../../provider\";\n\ntype UseDefaultMessagesParams = {\n\tconversationId: string;\n};\n\n/**\n * Mirrors the provider-configured default messages into timeline items so\n * that welcome content renders immediately while the backend conversation is\n * still being created. Agent fallbacks are resolved against available humans\n * and AI agents exposed by the provider context.\n */\nexport function useDefaultMessages({\n\tconversationId,\n}: UseDefaultMessagesParams): TimelineItem[] {\n\tconst { defaultMessages, availableAIAgents, availableHumanAgents } =\n\t\tuseSupport();\n\n\tconst memoisedDefaultTimelineItems = useMemo(\n\t\t() =>\n\t\t\tdefaultMessages.map((message, index) => {\n\t\t\t\tconst messageId = generateMessageId();\n\t\t\t\tconst timestamp = new Date().toISOString();\n\n\t\t\t\treturn {\n\t\t\t\t\tid: messageId,\n\t\t\t\t\tconversationId,\n\t\t\t\t\torganizationId: \"\", // Not available for default messages\n\t\t\t\t\ttype: \"message\" as const,\n\t\t\t\t\ttext: message.content,\n\t\t\t\t\tparts: [{ type: \"text\" as const, text: message.content }],\n\t\t\t\t\tvisibility: \"public\" as const,\n\t\t\t\t\tuserId:\n\t\t\t\t\t\tmessage.senderType === SenderType.TEAM_MEMBER\n\t\t\t\t\t\t\t? message.senderId || availableHumanAgents[0]?.id || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\taiAgentId:\n\t\t\t\t\t\tmessage.senderType === SenderType.AI\n\t\t\t\t\t\t\t? message.senderId || availableAIAgents[0]?.id || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\tvisitorId:\n\t\t\t\t\t\tmessage.senderType === SenderType.VISITOR\n\t\t\t\t\t\t\t? message.senderId || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\tcreatedAt: timestamp,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t} satisfies TimelineItem;\n\t\t\t}),\n\t\t[\n\t\t\tdefaultMessages,\n\t\t\tavailableHumanAgents[0]?.id,\n\t\t\tavailableAIAgents[0]?.id,\n\t\t\tconversationId,\n\t\t]\n\t);\n\n\treturn memoisedDefaultTimelineItems;\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,EAClC,kBAC4C;CAC5C,MAAM,EAAE,iBAAiB,mBAAmB,yBAC3C,YAAY;AAwCb,QAtCqC,cAEnC,gBAAgB,KAAK,SAAS,UAAU;EACvC,MAAM,YAAY,mBAAmB;EACrC,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;AAE1C,SAAO;GACN,IAAI;GACJ;GACA,gBAAgB;GAChB,MAAM;GACN,MAAM,QAAQ;GACd,OAAO,CAAC;IAAE,MAAM;IAAiB,MAAM,QAAQ;IAAS,CAAC;GACzD,YAAY;GACZ,QACC,QAAQ,eAAe,WAAW,cAC/B,QAAQ,YAAY,qBAAqB,IAAI,MAAM,OACnD;GACJ,WACC,QAAQ,eAAe,WAAW,KAC/B,QAAQ,YAAY,kBAAkB,IAAI,MAAM,OAChD;GACJ,WACC,QAAQ,eAAe,WAAW,UAC/B,QAAQ,YAAY,OACpB;GACJ,WAAW;GACX,WAAW;GACX;GACA,EACH;EACC;EACA,qBAAqB,IAAI;EACzB,kBAAkB,IAAI;EACtB;EACA,CACD"}
1
+ {"version":3,"file":"use-default-messages.js","names":[],"sources":["../../../src/hooks/private/use-default-messages.ts"],"sourcesContent":["import { generateMessageId } from \"@cossistant/core\";\nimport { SenderType } from \"@cossistant/types\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport { useMemo } from \"react\";\nimport { useSupport } from \"../../provider\";\n\ntype UseDefaultMessagesParams = {\n\tconversationId: string;\n};\n\n/**\n * Mirrors the provider-configured default messages into timeline items so\n * that welcome content renders immediately while the backend conversation is\n * still being created. Agent fallbacks are resolved against available humans\n * and AI agents exposed by the provider context.\n */\nexport function useDefaultMessages({\n\tconversationId,\n}: UseDefaultMessagesParams): TimelineItem[] {\n\tconst { defaultMessages, availableAIAgents, availableHumanAgents } =\n\t\tuseSupport();\n\n\tconst memoisedDefaultTimelineItems = useMemo(\n\t\t() =>\n\t\t\tdefaultMessages.map((message, index) => {\n\t\t\t\tconst messageId = generateMessageId();\n\t\t\t\tconst timestamp =\n\t\t\t\t\ttypeof window !== \"undefined\" ? new Date().toISOString() : \"\";\n\n\t\t\t\treturn {\n\t\t\t\t\tid: messageId,\n\t\t\t\t\tconversationId,\n\t\t\t\t\torganizationId: \"\", // Not available for default messages\n\t\t\t\t\ttype: \"message\" as const,\n\t\t\t\t\ttext: message.content,\n\t\t\t\t\tparts: [{ type: \"text\" as const, text: message.content }],\n\t\t\t\t\tvisibility: \"public\" as const,\n\t\t\t\t\tuserId:\n\t\t\t\t\t\tmessage.senderType === SenderType.TEAM_MEMBER\n\t\t\t\t\t\t\t? message.senderId || availableHumanAgents[0]?.id || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\taiAgentId:\n\t\t\t\t\t\tmessage.senderType === SenderType.AI\n\t\t\t\t\t\t\t? message.senderId || availableAIAgents[0]?.id || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\tvisitorId:\n\t\t\t\t\t\tmessage.senderType === SenderType.VISITOR\n\t\t\t\t\t\t\t? message.senderId || null\n\t\t\t\t\t\t\t: null,\n\t\t\t\t\tcreatedAt: timestamp,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t} satisfies TimelineItem;\n\t\t\t}),\n\t\t[\n\t\t\tdefaultMessages,\n\t\t\tavailableHumanAgents[0]?.id,\n\t\t\tavailableAIAgents[0]?.id,\n\t\t\tconversationId,\n\t\t]\n\t);\n\n\treturn memoisedDefaultTimelineItems;\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,EAClC,kBAC4C;CAC5C,MAAM,EAAE,iBAAiB,mBAAmB,yBAC3C,YAAY;AAyCb,QAvCqC,cAEnC,gBAAgB,KAAK,SAAS,UAAU;EACvC,MAAM,YAAY,mBAAmB;EACrC,MAAM,YACL,OAAO,WAAW,+BAAc,IAAI,MAAM,EAAC,aAAa,GAAG;AAE5D,SAAO;GACN,IAAI;GACJ;GACA,gBAAgB;GAChB,MAAM;GACN,MAAM,QAAQ;GACd,OAAO,CAAC;IAAE,MAAM;IAAiB,MAAM,QAAQ;IAAS,CAAC;GACzD,YAAY;GACZ,QACC,QAAQ,eAAe,WAAW,cAC/B,QAAQ,YAAY,qBAAqB,IAAI,MAAM,OACnD;GACJ,WACC,QAAQ,eAAe,WAAW,KAC/B,QAAQ,YAAY,kBAAkB,IAAI,MAAM,OAChD;GACJ,WACC,QAAQ,eAAe,WAAW,UAC/B,QAAQ,YAAY,OACpB;GACJ,WAAW;GACX,WAAW;GACX;GACA,EACH;EACC;EACA,qBAAqB,IAAI;EACzB,kBAAkB,IAAI;EACtB;EACA,CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-grouped-messages.d.ts","names":[],"sources":["../../../src/hooks/private/use-grouped-messages.ts"],"sourcesContent":[],"mappings":";;;;;KAKY,cAAA;;EAAA,QAAA,EAAA,MAAA;EAGC,UAAA,EAAA,UAAA;EACL,KAAA,EAAA,YAAA,EAAA;EAGW,cAAA,EAAA,MAAA;EACD,aAAA,EAAA,MAAA;EAAI,gBAAA,EADH,IACG;EAGV,eAAA,EAHM,IAGW;AAM7B,CAAA;AAOY,KAbA,iBAAA,GAagB;EACzB,IAAA,EAAA,gBAAA;EACA,IAAA,EAbI,YAaJ;EACA,SAAA,EAbS,IAaT;CAAgB;AAEP,KAZA,gBAAA,GAYA;EACJ,IAAA,EAAA,eAAA;EACI,IAAA,EAZL,YAYK;EAEE,IAAA,EAAA,MAAA,GAAA,IAAA;EAAU,SAAA,EAZZ,IAYY;AAGxB,CAAA;AAwNa,KApOD,gBAAA,GACT,cAuSF,GAtSE,iBAsSF,GArSE,gBAqSF;AApEkC,KA/NvB,yBAAA,GA+NuB;EAAA,KAAA,EA9N3B,YA8N2B,EAAA;EAAA,QAAA,CAAA,EA7NvB,gBA6NuB,EAAA;EAAA,eAAA,CAAA,EAAA,MAAA;EAKhC,UAAA,CAAA,EAhOW,UAgOX;;KA7NS,uBAAA,GAA0B;;;;;;;cAwNzB;;;;;GAKV"}
1
+ {"version":3,"file":"use-grouped-messages.d.ts","names":[],"sources":["../../../src/hooks/private/use-grouped-messages.ts"],"sourcesContent":[],"mappings":";;;;;KAKY,cAAA;;EAAA,QAAA,EAAA,MAAA;EAGC,UAAA,EAAA,UAAA;EACL,KAAA,EAAA,YAAA,EAAA;EAGW,cAAA,EAAA,MAAA;EACD,aAAA,EAAA,MAAA;EAAI,gBAAA,EADH,IACG;EAGV,eAAA,EAHM,IAGW;AAM7B,CAAA;AAOY,KAbA,iBAAA,GAagB;EACzB,IAAA,EAAA,gBAAA;EACA,IAAA,EAbI,YAaJ;EACA,SAAA,EAbS,IAaT;CAAgB;AAEP,KAZA,gBAAA,GAYA;EACJ,IAAA,EAAA,eAAA;EACI,IAAA,EAZL,YAYK;EAEE,IAAA,EAAA,MAAA,GAAA,IAAA;EAAU,SAAA,EAZZ,IAYY;AAGxB,CAAA;AA+La,KA3MD,gBAAA,GACT,cA8QF,GA7QE,iBA6QF,GA5QE,gBA4QF;AApEkC,KAtMvB,yBAAA,GAsMuB;EAAA,KAAA,EArM3B,YAqM2B,EAAA;EAAA,QAAA,CAAA,EApMvB,gBAoMuB,EAAA;EAAA,eAAA,CAAA,EAAA,MAAA;EAKhC,UAAA,CAAA,EAvMW,UAuMX;;KApMS,uBAAA,GAA0B;;;;;;;cA+LzB;;;;;GAKV"}
@@ -8,7 +8,7 @@ const getTimestamp = (date) => {
8
8
  return date.getTime();
9
9
  };
10
10
  const toDate = (date) => {
11
- if (!date) return /* @__PURE__ */ new Date();
11
+ if (!date) return typeof window !== "undefined" ? /* @__PURE__ */ new Date() : /* @__PURE__ */ new Date(0);
12
12
  if (typeof date === "string") return new Date(date);
13
13
  return date;
14
14
  };
@@ -89,32 +89,18 @@ const buildTimelineReadReceiptData = (seenData, items) => {
89
89
  for (const item of items) if (item.type === "message" && item.id) seenByMap.set(item.id, /* @__PURE__ */ new Set());
90
90
  const sortedItems = [...items].filter((item) => item.type === "message").sort((a, b) => getTimestamp(a.createdAt) - getTimestamp(b.createdAt));
91
91
  for (const seen of seenData) {
92
- let seenTime = getTimestamp(seen.updatedAt);
92
+ const seenTime = getTimestamp(seen.lastSeenAt);
93
93
  const viewerId = seen.userId || seen.visitorId || seen.aiAgentId;
94
94
  if (!viewerId) continue;
95
- const lastItemByViewer = sortedItems.filter((item) => {
96
- if (seen.userId) return item.userId === viewerId;
97
- if (seen.visitorId) return item.visitorId === viewerId;
98
- if (seen.aiAgentId) return item.aiAgentId === viewerId;
99
- return false;
100
- }).at(-1);
101
- if (lastItemByViewer) {
102
- const lastItemTime = getTimestamp(lastItemByViewer.createdAt);
103
- if (lastItemTime > seenTime) seenTime = lastItemTime;
104
- }
105
95
  let lastReadItem = null;
106
96
  let unreadCount = 0;
107
- let hasPassedLastSeen = false;
108
- for (const item of sortedItems) if (getTimestamp(item.createdAt) <= seenTime && !hasPassedLastSeen) {
97
+ for (const item of sortedItems) if (getTimestamp(item.createdAt) <= seenTime) {
109
98
  if (item.id) {
110
99
  const seenBy = seenByMap.get(item.id);
111
100
  if (seenBy) seenBy.add(viewerId);
112
101
  }
113
102
  lastReadItem = item;
114
- } else {
115
- hasPassedLastSeen = true;
116
- unreadCount++;
117
- }
103
+ } else unreadCount++;
118
104
  if (lastReadItem?.id) lastReadMessageMap.set(viewerId, lastReadItem.id);
119
105
  unreadCountMap.set(viewerId, unreadCount);
120
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-grouped-messages.js","names":["EMPTY_STRING_ARRAY: readonly string[]","result: ConversationItem[]","currentGroup: GroupedMessage | null","lastReadItem: TimelineItem | null"],"sources":["../../../src/hooks/private/use-grouped-messages.ts"],"sourcesContent":["import { SenderType } from \"@cossistant/types\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport type { ConversationSeen } from \"@cossistant/types/schemas\";\nimport { useMemo } from \"react\";\n\nexport type GroupedMessage = {\n\ttype: \"message_group\";\n\tsenderId: string;\n\tsenderType: SenderType;\n\titems: TimelineItem[];\n\tfirstMessageId: string;\n\tlastMessageId: string;\n\tfirstMessageTime: Date;\n\tlastMessageTime: Date;\n};\n\nexport type TimelineEventItem = {\n\ttype: \"timeline_event\";\n\titem: TimelineItem;\n\ttimestamp: Date;\n};\n\nexport type TimelineToolItem = {\n\ttype: \"timeline_tool\";\n\titem: TimelineItem;\n\ttool: string | null;\n\ttimestamp: Date;\n};\n\nexport type ConversationItem =\n\t| GroupedMessage\n\t| TimelineEventItem\n\t| TimelineToolItem;\n\nexport type UseGroupedMessagesOptions = {\n\titems: TimelineItem[];\n\tseenData?: ConversationSeen[];\n\tcurrentViewerId?: string; // The ID of the current viewer (visitor, user, or AI agent)\n\tviewerType?: SenderType; // Type of the current viewer\n};\n\nexport type UseGroupedMessagesProps = UseGroupedMessagesOptions;\n\n// Helper function to safely get timestamp from Date or string\nconst getTimestamp = (date: Date | string | null | undefined): number => {\n\tif (!date) {\n\t\treturn 0;\n\t}\n\tif (typeof date === \"string\") {\n\t\treturn new Date(date).getTime();\n\t}\n\treturn date.getTime();\n};\n\n// Helper function to safely convert to Date\nconst toDate = (date: Date | string | null | undefined): Date => {\n\tif (!date) {\n\t\treturn new Date();\n\t}\n\tif (typeof date === \"string\") {\n\t\treturn new Date(date);\n\t}\n\treturn date;\n};\n\n// Helper to determine sender ID and type from a timeline item\nconst getSenderIdAndTypeFromTimelineItem = (\n\titem: TimelineItem\n): { senderId: string; senderType: SenderType } => {\n\tif (item.visitorId) {\n\t\treturn { senderId: item.visitorId, senderType: SenderType.VISITOR };\n\t}\n\tif (item.aiAgentId) {\n\t\treturn { senderId: item.aiAgentId, senderType: SenderType.AI };\n\t}\n\tif (item.userId) {\n\t\treturn { senderId: item.userId, senderType: SenderType.TEAM_MEMBER };\n\t}\n\n\t// Fallback\n\treturn {\n\t\tsenderId: item.id || \"default-sender\",\n\t\tsenderType: SenderType.TEAM_MEMBER,\n\t};\n};\n\nconst EMPTY_STRING_ARRAY: readonly string[] = Object.freeze([]);\n\n// Helper function to group timeline items (messages only, events stay separate)\nconst groupTimelineItems = (items: TimelineItem[]): ConversationItem[] => {\n\tconst result: ConversationItem[] = [];\n\tlet currentGroup: GroupedMessage | null = null;\n\n\tfor (const item of items) {\n\t\t// Events don't get grouped\n\t\tif (item.type === \"event\") {\n\t\t\t// Finalize any existing group\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t\tcurrentGroup = null;\n\t\t\t}\n\n\t\t\t// Add event as standalone item\n\t\t\tresult.push({\n\t\t\t\ttype: \"timeline_event\",\n\t\t\t\titem,\n\t\t\t\ttimestamp: toDate(item.createdAt),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (item.type === \"identification\") {\n\t\t\t// Finalize any existing group\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t\tcurrentGroup = null;\n\t\t\t}\n\n\t\t\t// Add tool item as standalone entry\n\t\t\tresult.push({\n\t\t\t\ttype: \"timeline_tool\",\n\t\t\t\titem,\n\t\t\t\ttool: item.tool ?? null,\n\t\t\t\ttimestamp: toDate(item.createdAt),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Group messages by sender\n\t\tconst { senderId, senderType } = getSenderIdAndTypeFromTimelineItem(item);\n\n\t\tif (currentGroup && currentGroup.senderId === senderId) {\n\t\t\t// Add to existing group\n\t\t\tcurrentGroup.items.push(item);\n\t\t\tcurrentGroup.lastMessageId = item.id || currentGroup.lastMessageId;\n\t\t\tcurrentGroup.lastMessageTime = toDate(item.createdAt);\n\t\t} else {\n\t\t\t// Finalize previous group if exists\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t}\n\n\t\t\t// Start new group\n\t\t\tcurrentGroup = {\n\t\t\t\ttype: \"message_group\",\n\t\t\t\tsenderId,\n\t\t\t\tsenderType,\n\t\t\t\titems: [item],\n\t\t\t\tfirstMessageId: item.id || \"\",\n\t\t\t\tlastMessageId: item.id || \"\",\n\t\t\t\tfirstMessageTime: toDate(item.createdAt),\n\t\t\t\tlastMessageTime: toDate(item.createdAt),\n\t\t\t};\n\t\t}\n\t}\n\n\tif (currentGroup) {\n\t\tresult.push(currentGroup);\n\t}\n\n\treturn result;\n};\n\n// Build read receipt data for timeline items\nconst buildTimelineReadReceiptData = (\n\tseenData: ConversationSeen[],\n\titems: TimelineItem[]\n) => {\n\tconst seenByMap = new Map<string, Set<string>>();\n\tconst lastReadMessageMap = new Map<string, string>();\n\tconst unreadCountMap = new Map<string, number>();\n\n\t// Initialize map for all message-type timeline items\n\tfor (const item of items) {\n\t\tif (item.type === \"message\" && item.id) {\n\t\t\tseenByMap.set(item.id, new Set());\n\t\t}\n\t}\n\n\t// Sort items by time to process in order\n\tconst sortedItems = [...items]\n\t\t.filter((item) => item.type === \"message\")\n\t\t.sort((a, b) => getTimestamp(a.createdAt) - getTimestamp(b.createdAt));\n\n\t// Process seen data for each viewer\n\tfor (const seen of seenData) {\n\t\tlet seenTime = getTimestamp(seen.updatedAt);\n\t\tconst viewerId = seen.userId || seen.visitorId || seen.aiAgentId;\n\t\tif (!viewerId) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Find the last message sent by this viewer\n\t\tconst lastItemByViewer = sortedItems\n\t\t\t.filter((item) => {\n\t\t\t\tif (seen.userId) {\n\t\t\t\t\treturn item.userId === viewerId;\n\t\t\t\t}\n\t\t\t\tif (seen.visitorId) {\n\t\t\t\t\treturn item.visitorId === viewerId;\n\t\t\t\t}\n\t\t\t\tif (seen.aiAgentId) {\n\t\t\t\t\treturn item.aiAgentId === viewerId;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t})\n\t\t\t.at(-1);\n\n\t\tif (lastItemByViewer) {\n\t\t\tconst lastItemTime = getTimestamp(lastItemByViewer.createdAt);\n\t\t\tif (lastItemTime > seenTime) {\n\t\t\t\tseenTime = lastItemTime;\n\t\t\t}\n\t\t}\n\n\t\tlet lastReadItem: TimelineItem | null = null;\n\t\tlet unreadCount = 0;\n\t\tlet hasPassedLastSeen = false;\n\n\t\t// Process items in chronological order\n\t\tfor (const item of sortedItems) {\n\t\t\tconst itemTime = getTimestamp(item.createdAt);\n\n\t\t\tif (itemTime <= seenTime && !hasPassedLastSeen) {\n\t\t\t\t// This item has been seen\n\t\t\t\tif (item.id) {\n\t\t\t\t\tconst seenBy = seenByMap.get(item.id);\n\t\t\t\t\tif (seenBy) {\n\t\t\t\t\t\tseenBy.add(viewerId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlastReadItem = item;\n\t\t\t} else {\n\t\t\t\t// This item is unread\n\t\t\t\thasPassedLastSeen = true;\n\t\t\t\tunreadCount++;\n\t\t\t}\n\t\t}\n\n\t\t// Store the last read item for this viewer\n\t\tif (lastReadItem?.id) {\n\t\t\tlastReadMessageMap.set(viewerId, lastReadItem.id);\n\t\t}\n\n\t\t// Store unread count\n\t\tunreadCountMap.set(viewerId, unreadCount);\n\t}\n\n\treturn { seenByMap, lastReadMessageMap, unreadCountMap };\n};\n\n/**\n * Batches sequential timeline items from the same sender into groups and enriches\n * them with read-receipt helpers so UIs can render conversation timelines with\n * minimal effort. Seen data is normalised into quick lookup maps for unread\n * indicators.\n */\nexport const useGroupedMessages = ({\n\titems,\n\tseenData = [],\n\tcurrentViewerId,\n\tviewerType,\n}: UseGroupedMessagesOptions) => {\n\treturn useMemo(() => {\n\t\tconst groupedItems = groupTimelineItems(items);\n\n\t\t// Build read receipt data\n\t\tconst { seenByMap, lastReadMessageMap, unreadCountMap } =\n\t\t\tbuildTimelineReadReceiptData(seenData, items);\n\n\t\t// Cache for turning seen sets into stable arrays across renders\n\t\tconst seenByArrayCache = new Map<string, readonly string[]>();\n\n\t\treturn {\n\t\t\titems: groupedItems,\n\t\t\tseenByMap,\n\t\t\tlastReadMessageMap,\n\t\t\tunreadCountMap,\n\n\t\t\tisMessageSeenByViewer: (messageId: string): boolean => {\n\t\t\t\tif (!currentViewerId) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tconst seenBy = seenByMap.get(messageId);\n\t\t\t\treturn seenBy ? seenBy.has(currentViewerId) : false;\n\t\t\t},\n\n\t\t\tgetMessageSeenBy: (messageId: string): readonly string[] => {\n\t\t\t\tif (seenByArrayCache.has(messageId)) {\n\t\t\t\t\treturn seenByArrayCache.get(messageId) ?? EMPTY_STRING_ARRAY;\n\t\t\t\t}\n\n\t\t\t\tconst seenBy = seenByMap.get(messageId);\n\t\t\t\tif (!seenBy || seenBy.size === 0) {\n\t\t\t\t\tseenByArrayCache.set(messageId, EMPTY_STRING_ARRAY);\n\t\t\t\t\treturn EMPTY_STRING_ARRAY;\n\t\t\t\t}\n\n\t\t\t\tconst result = Object.freeze(Array.from(seenBy)) as readonly string[];\n\t\t\t\tseenByArrayCache.set(messageId, result);\n\t\t\t\treturn result;\n\t\t\t},\n\n\t\t\tgetLastReadMessageId: (userId: string): string | undefined =>\n\t\t\t\tlastReadMessageMap.get(userId),\n\n\t\t\tisLastReadMessage: (messageId: string, userId: string): boolean =>\n\t\t\t\tlastReadMessageMap.get(userId) === messageId,\n\n\t\t\tgetUnreadCount: (userId: string): number =>\n\t\t\t\tunreadCountMap.get(userId) || 0,\n\n\t\t\thasUnreadAfter: (messageId: string, userId: string): boolean => {\n\t\t\t\tconst lastRead = lastReadMessageMap.get(userId);\n\t\t\t\tif (!lastRead) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst messageIndex = items.findIndex((item) => item.id === messageId);\n\t\t\t\tconst lastReadIndex = items.findIndex((item) => item.id === lastRead);\n\n\t\t\t\treturn messageIndex < lastReadIndex;\n\t\t\t},\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AChB,eAAe,IAAI,OAAO,IAAI;GAE/B,iBAAiB,WAAmB,WAA4B;IAC/D,MAAM,WAAW,mBAAmB,IAAI,OAAO;AAC/C,QAAI,CAAC,SACJ,QAAO;AAMR,WAHqB,MAAM,WAAW,SAAS,KAAK,OAAO,UAAU,GAC/C,MAAM,WAAW,SAAS,KAAK,OAAO,SAAS;;GAItE;IACC;EAAC;EAAO;EAAU;EAAgB,CAAC"}
1
+ {"version":3,"file":"use-grouped-messages.js","names":["EMPTY_STRING_ARRAY: readonly string[]","result: ConversationItem[]","currentGroup: GroupedMessage | null","lastReadItem: TimelineItem | null"],"sources":["../../../src/hooks/private/use-grouped-messages.ts"],"sourcesContent":["import { SenderType } from \"@cossistant/types\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport type { ConversationSeen } from \"@cossistant/types/schemas\";\nimport { useMemo } from \"react\";\n\nexport type GroupedMessage = {\n\ttype: \"message_group\";\n\tsenderId: string;\n\tsenderType: SenderType;\n\titems: TimelineItem[];\n\tfirstMessageId: string;\n\tlastMessageId: string;\n\tfirstMessageTime: Date;\n\tlastMessageTime: Date;\n};\n\nexport type TimelineEventItem = {\n\ttype: \"timeline_event\";\n\titem: TimelineItem;\n\ttimestamp: Date;\n};\n\nexport type TimelineToolItem = {\n\ttype: \"timeline_tool\";\n\titem: TimelineItem;\n\ttool: string | null;\n\ttimestamp: Date;\n};\n\nexport type ConversationItem =\n\t| GroupedMessage\n\t| TimelineEventItem\n\t| TimelineToolItem;\n\nexport type UseGroupedMessagesOptions = {\n\titems: TimelineItem[];\n\tseenData?: ConversationSeen[];\n\tcurrentViewerId?: string; // The ID of the current viewer (visitor, user, or AI agent)\n\tviewerType?: SenderType; // Type of the current viewer\n};\n\nexport type UseGroupedMessagesProps = UseGroupedMessagesOptions;\n\n// Helper function to safely get timestamp from Date or string\nconst getTimestamp = (date: Date | string | null | undefined): number => {\n\tif (!date) {\n\t\treturn 0;\n\t}\n\tif (typeof date === \"string\") {\n\t\treturn new Date(date).getTime();\n\t}\n\treturn date.getTime();\n};\n\n// Helper function to safely convert to Date\nconst toDate = (date: Date | string | null | undefined): Date => {\n\tif (!date) {\n\t\treturn typeof window !== \"undefined\" ? new Date() : new Date(0);\n\t}\n\tif (typeof date === \"string\") {\n\t\treturn new Date(date);\n\t}\n\treturn date;\n};\n\n// Helper to determine sender ID and type from a timeline item\nconst getSenderIdAndTypeFromTimelineItem = (\n\titem: TimelineItem\n): { senderId: string; senderType: SenderType } => {\n\tif (item.visitorId) {\n\t\treturn { senderId: item.visitorId, senderType: SenderType.VISITOR };\n\t}\n\tif (item.aiAgentId) {\n\t\treturn { senderId: item.aiAgentId, senderType: SenderType.AI };\n\t}\n\tif (item.userId) {\n\t\treturn { senderId: item.userId, senderType: SenderType.TEAM_MEMBER };\n\t}\n\n\t// Fallback\n\treturn {\n\t\tsenderId: item.id || \"default-sender\",\n\t\tsenderType: SenderType.TEAM_MEMBER,\n\t};\n};\n\nconst EMPTY_STRING_ARRAY: readonly string[] = Object.freeze([]);\n\n// Helper function to group timeline items (messages only, events stay separate)\nconst groupTimelineItems = (items: TimelineItem[]): ConversationItem[] => {\n\tconst result: ConversationItem[] = [];\n\tlet currentGroup: GroupedMessage | null = null;\n\n\tfor (const item of items) {\n\t\t// Events don't get grouped\n\t\tif (item.type === \"event\") {\n\t\t\t// Finalize any existing group\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t\tcurrentGroup = null;\n\t\t\t}\n\n\t\t\t// Add event as standalone item\n\t\t\tresult.push({\n\t\t\t\ttype: \"timeline_event\",\n\t\t\t\titem,\n\t\t\t\ttimestamp: toDate(item.createdAt),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (item.type === \"identification\") {\n\t\t\t// Finalize any existing group\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t\tcurrentGroup = null;\n\t\t\t}\n\n\t\t\t// Add tool item as standalone entry\n\t\t\tresult.push({\n\t\t\t\ttype: \"timeline_tool\",\n\t\t\t\titem,\n\t\t\t\ttool: item.tool ?? null,\n\t\t\t\ttimestamp: toDate(item.createdAt),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Group messages by sender\n\t\tconst { senderId, senderType } = getSenderIdAndTypeFromTimelineItem(item);\n\n\t\tif (currentGroup && currentGroup.senderId === senderId) {\n\t\t\t// Add to existing group\n\t\t\tcurrentGroup.items.push(item);\n\t\t\tcurrentGroup.lastMessageId = item.id || currentGroup.lastMessageId;\n\t\t\tcurrentGroup.lastMessageTime = toDate(item.createdAt);\n\t\t} else {\n\t\t\t// Finalize previous group if exists\n\t\t\tif (currentGroup) {\n\t\t\t\tresult.push(currentGroup);\n\t\t\t}\n\n\t\t\t// Start new group\n\t\t\tcurrentGroup = {\n\t\t\t\ttype: \"message_group\",\n\t\t\t\tsenderId,\n\t\t\t\tsenderType,\n\t\t\t\titems: [item],\n\t\t\t\tfirstMessageId: item.id || \"\",\n\t\t\t\tlastMessageId: item.id || \"\",\n\t\t\t\tfirstMessageTime: toDate(item.createdAt),\n\t\t\t\tlastMessageTime: toDate(item.createdAt),\n\t\t\t};\n\t\t}\n\t}\n\n\tif (currentGroup) {\n\t\tresult.push(currentGroup);\n\t}\n\n\treturn result;\n};\n\n// Build read receipt data for timeline items\nconst buildTimelineReadReceiptData = (\n\tseenData: ConversationSeen[],\n\titems: TimelineItem[]\n) => {\n\tconst seenByMap = new Map<string, Set<string>>();\n\tconst lastReadMessageMap = new Map<string, string>();\n\tconst unreadCountMap = new Map<string, number>();\n\n\t// Initialize map for all message-type timeline items\n\tfor (const item of items) {\n\t\tif (item.type === \"message\" && item.id) {\n\t\t\tseenByMap.set(item.id, new Set());\n\t\t}\n\t}\n\n\t// Sort items by time to process in order\n\tconst sortedItems = [...items]\n\t\t.filter((item) => item.type === \"message\")\n\t\t.sort((a, b) => getTimestamp(a.createdAt) - getTimestamp(b.createdAt));\n\n\t// Process seen data for each viewer\n\tfor (const seen of seenData) {\n\t\tconst seenTime = getTimestamp(seen.lastSeenAt);\n\t\tconst viewerId = seen.userId || seen.visitorId || seen.aiAgentId;\n\t\tif (!viewerId) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet lastReadItem: TimelineItem | null = null;\n\t\tlet unreadCount = 0;\n\n\t\t// Process items in chronological order\n\t\tfor (const item of sortedItems) {\n\t\t\tconst itemTime = getTimestamp(item.createdAt);\n\n\t\t\tif (itemTime <= seenTime) {\n\t\t\t\t// This item has been seen\n\t\t\t\tif (item.id) {\n\t\t\t\t\tconst seenBy = seenByMap.get(item.id);\n\t\t\t\t\tif (seenBy) {\n\t\t\t\t\t\tseenBy.add(viewerId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlastReadItem = item;\n\t\t\t} else {\n\t\t\t\t// This item is unread\n\t\t\t\tunreadCount++;\n\t\t\t}\n\t\t}\n\n\t\t// Store the last read item for this viewer\n\t\tif (lastReadItem?.id) {\n\t\t\tlastReadMessageMap.set(viewerId, lastReadItem.id);\n\t\t}\n\n\t\t// Store unread count\n\t\tunreadCountMap.set(viewerId, unreadCount);\n\t}\n\n\treturn { seenByMap, lastReadMessageMap, unreadCountMap };\n};\n\n/**\n * Batches sequential timeline items from the same sender into groups and enriches\n * them with read-receipt helpers so UIs can render conversation timelines with\n * minimal effort. Seen data is normalised into quick lookup maps for unread\n * indicators.\n */\nexport const useGroupedMessages = ({\n\titems,\n\tseenData = [],\n\tcurrentViewerId,\n\tviewerType,\n}: UseGroupedMessagesOptions) => {\n\treturn useMemo(() => {\n\t\tconst groupedItems = groupTimelineItems(items);\n\n\t\t// Build read receipt data\n\t\tconst { seenByMap, lastReadMessageMap, unreadCountMap } =\n\t\t\tbuildTimelineReadReceiptData(seenData, items);\n\n\t\t// Cache for turning seen sets into stable arrays across renders\n\t\tconst seenByArrayCache = new Map<string, readonly string[]>();\n\n\t\treturn {\n\t\t\titems: groupedItems,\n\t\t\tseenByMap,\n\t\t\tlastReadMessageMap,\n\t\t\tunreadCountMap,\n\n\t\t\tisMessageSeenByViewer: (messageId: string): boolean => {\n\t\t\t\tif (!currentViewerId) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tconst seenBy = seenByMap.get(messageId);\n\t\t\t\treturn seenBy ? seenBy.has(currentViewerId) : false;\n\t\t\t},\n\n\t\t\tgetMessageSeenBy: (messageId: string): readonly string[] => {\n\t\t\t\tif (seenByArrayCache.has(messageId)) {\n\t\t\t\t\treturn seenByArrayCache.get(messageId) ?? EMPTY_STRING_ARRAY;\n\t\t\t\t}\n\n\t\t\t\tconst seenBy = seenByMap.get(messageId);\n\t\t\t\tif (!seenBy || seenBy.size === 0) {\n\t\t\t\t\tseenByArrayCache.set(messageId, EMPTY_STRING_ARRAY);\n\t\t\t\t\treturn EMPTY_STRING_ARRAY;\n\t\t\t\t}\n\n\t\t\t\tconst result = Object.freeze(Array.from(seenBy)) as readonly string[];\n\t\t\t\tseenByArrayCache.set(messageId, result);\n\t\t\t\treturn result;\n\t\t\t},\n\n\t\t\tgetLastReadMessageId: (userId: string): string | undefined =>\n\t\t\t\tlastReadMessageMap.get(userId),\n\n\t\t\tisLastReadMessage: (messageId: string, userId: string): boolean =>\n\t\t\t\tlastReadMessageMap.get(userId) === messageId,\n\n\t\t\tgetUnreadCount: (userId: string): number =>\n\t\t\t\tunreadCountMap.get(userId) || 0,\n\n\t\t\thasUnreadAfter: (messageId: string, userId: string): boolean => {\n\t\t\t\tconst lastRead = lastReadMessageMap.get(userId);\n\t\t\t\tif (!lastRead) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst messageIndex = items.findIndex((item) => item.id === messageId);\n\t\t\t\tconst lastReadIndex = items.findIndex((item) => item.id === lastRead);\n\n\t\t\t\treturn messageIndex < lastReadIndex;\n\t\t\t},\n\t\t};\n\t}, [items, seenData, currentViewerId]);\n};\n"],"mappings":";;;;AA4CA,MAAM,gBAAgB,SAAmD;AACxE,KA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EAAW;EAAoB;EAAgB;;;;;;;;AASzD,MAAa,sBAAsB,EAClC,OACA,WAAW,EAAE,EACb,iBACA,iBACgC;AAChC,QAAO,cAAc;EACpB,MAAM,eAAe,mBAAmB,MAAM;EAG9C,MAAM,EAAE,WAAW,oBAAoB,mBACtC,6BAA6B,UAAU,MAAM;EAG9C,MAAM,mCAAmB,IAAI,KAAgC;AAE7D,SAAO;GACN,OAAO;GACP;GACA;GACA;GAEA,wBAAwB,cAA+B;AACtD,QAAI,CAAC,gBACJ,QAAO;IAER,MAAM,SAAS,UAAU,IAAI,UAAU;AACvC,WAAO,SAAS,OAAO,IAAI,gBAAgB,GAAG;;GAG/C,mBAAmB,cAAyC;AAC3D,QAAI,iBAAiB,IAAI,UAAU,CAClC,QAAO,iBAAiB,IAAI,UAAU,IAAI;IAG3C,MAAM,SAAS,UAAU,IAAI,UAAU;AACvC,QAAI,CAAC,UAAU,OAAO,SAAS,GAAG;AACjC,sBAAiB,IAAI,WAAW,mBAAmB;AACnD,YAAO;;IAGR,MAAM,SAAS,OAAO,OAAO,MAAM,KAAK,OAAO,CAAC;AAChD,qBAAiB,IAAI,WAAW,OAAO;AACvC,WAAO;;GAGR,uBAAuB,WACtB,mBAAmB,IAAI,OAAO;GAE/B,oBAAoB,WAAmB,WACtC,mBAAmB,IAAI,OAAO,KAAK;GAEpC,iBAAiB,WAChB,eAAe,IAAI,OAAO,IAAI;GAE/B,iBAAiB,WAAmB,WAA4B;IAC/D,MAAM,WAAW,mBAAmB,IAAI,OAAO;AAC/C,QAAI,CAAC,SACJ,QAAO;AAMR,WAHqB,MAAM,WAAW,SAAS,KAAK,OAAO,UAAU,GAC/C,MAAM,WAAW,SAAS,KAAK,OAAO,SAAS;;GAItE;IACC;EAAC;EAAO;EAAU;EAAgB,CAAC"}
@@ -14,7 +14,7 @@ import { CossistantClient } from "@cossistant/core";
14
14
  function useClient(publicKey, apiUrl = "https://api.cossistant.com/v1", wsUrl = "wss://api.cossistant.com/ws") {
15
15
  return {
16
16
  client: useMemo(() => {
17
- const keyFromEnv = process.env.NEXT_PUBLIC_COSSISTANT_API_KEY || process.env.COSSISTANT_PUBLIC_KEY;
17
+ const keyFromEnv = process.env.NEXT_PUBLIC_COSSISTANT_API_KEY || process.env.NEXT_PUBLIC_COSSISTANT_KEY || process.env.COSSISTANT_API_KEY;
18
18
  const keyToUse = publicKey ?? keyFromEnv;
19
19
  if (!keyToUse) throw new Error("Public key is required. Please provide it as a prop or set NEXT_PUBLIC_COSSISTANT_API_KEY environment variable.");
20
20
  const config = {
@@ -1 +1 @@
1
- {"version":3,"file":"use-rest-client.js","names":["config: CossistantConfig","err: unknown"],"sources":["../../../src/hooks/private/use-rest-client.ts"],"sourcesContent":["\"use client\";\n\nimport { CossistantClient } from \"@cossistant/core\";\nimport type { CossistantConfig } from \"@cossistant/types\";\nimport { useMemo } from \"react\";\n\nexport type UseClientResult = {\n\tclient: CossistantClient;\n\terror: Error | null;\n};\n\n/**\n * Creates a memoised `CossistantClient` instance using the provided endpoints\n * and public key. When no key is passed the hook falls back to environment\n * variables and surfaces missing configuration errors through the returned\n * `error` field.\n */\nexport function useClient(\n\tpublicKey: string | undefined,\n\tapiUrl = \"https://api.cossistant.com/v1\",\n\twsUrl = \"wss://api.cossistant.com/ws\"\n): UseClientResult {\n\tconst client = useMemo(() => {\n\t\tconst keyFromEnv =\n\t\t\tprocess.env.NEXT_PUBLIC_COSSISTANT_API_KEY ||\n\t\t\tprocess.env.COSSISTANT_PUBLIC_KEY;\n\t\tconst keyToUse = publicKey ?? keyFromEnv;\n\n\t\tif (!keyToUse) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Public key is required. Please provide it as a prop or set NEXT_PUBLIC_COSSISTANT_API_KEY environment variable.\"\n\t\t\t);\n\t\t}\n\n\t\tconst config: CossistantConfig = {\n\t\t\tapiUrl,\n\t\t\twsUrl,\n\t\t\tpublicKey: keyToUse,\n\t\t};\n\n\t\ttry {\n\t\t\treturn new CossistantClient(config);\n\t\t} catch (err: unknown) {\n\t\t\tthrow err instanceof Error\n\t\t\t\t? err\n\t\t\t\t: new Error(\"Failed to initialize Cossistant client\");\n\t\t}\n\t}, [publicKey, apiUrl, wsUrl]);\n\n\treturn { client, error: null };\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAgB,UACf,WACA,SAAS,iCACT,QAAQ,+BACU;AA4BlB,QAAO;EAAE,QA3BM,cAAc;GAC5B,MAAM,aACL,QAAQ,IAAI,kCACZ,QAAQ,IAAI;GACb,MAAM,WAAW,aAAa;AAE9B,OAAI,CAAC,SACJ,OAAM,IAAI,MACT,kHACA;GAGF,MAAMA,SAA2B;IAChC;IACA;IACA,WAAW;IACX;AAED,OAAI;AACH,WAAO,IAAI,iBAAiB,OAAO;YAC3BC,KAAc;AACtB,UAAM,eAAe,QAClB,sBACA,IAAI,MAAM,yCAAyC;;KAErD;GAAC;GAAW;GAAQ;GAAM,CAAC;EAEb,OAAO;EAAM"}
1
+ {"version":3,"file":"use-rest-client.js","names":["config: CossistantConfig","err: unknown"],"sources":["../../../src/hooks/private/use-rest-client.ts"],"sourcesContent":["\"use client\";\n\nimport { CossistantClient } from \"@cossistant/core\";\nimport type { CossistantConfig } from \"@cossistant/types\";\nimport { useMemo } from \"react\";\n\nexport type UseClientResult = {\n\tclient: CossistantClient;\n\terror: Error | null;\n};\n\n/**\n * Creates a memoised `CossistantClient` instance using the provided endpoints\n * and public key. When no key is passed the hook falls back to environment\n * variables and surfaces missing configuration errors through the returned\n * `error` field.\n */\nexport function useClient(\n\tpublicKey: string | undefined,\n\tapiUrl = \"https://api.cossistant.com/v1\",\n\twsUrl = \"wss://api.cossistant.com/ws\"\n): UseClientResult {\n\tconst client = useMemo(() => {\n\t\tconst keyFromEnv =\n\t\t\tprocess.env.NEXT_PUBLIC_COSSISTANT_API_KEY ||\n\t\t\tprocess.env.NEXT_PUBLIC_COSSISTANT_KEY ||\n\t\t\tprocess.env.COSSISTANT_API_KEY;\n\t\tconst keyToUse = publicKey ?? keyFromEnv;\n\n\t\tif (!keyToUse) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Public key is required. Please provide it as a prop or set NEXT_PUBLIC_COSSISTANT_API_KEY environment variable.\"\n\t\t\t);\n\t\t}\n\n\t\tconst config: CossistantConfig = {\n\t\t\tapiUrl,\n\t\t\twsUrl,\n\t\t\tpublicKey: keyToUse,\n\t\t};\n\n\t\ttry {\n\t\t\treturn new CossistantClient(config);\n\t\t} catch (err: unknown) {\n\t\t\tthrow err instanceof Error\n\t\t\t\t? err\n\t\t\t\t: new Error(\"Failed to initialize Cossistant client\");\n\t\t}\n\t}, [publicKey, apiUrl, wsUrl]);\n\n\treturn { client, error: null };\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAgB,UACf,WACA,SAAS,iCACT,QAAQ,+BACU;AA6BlB,QAAO;EAAE,QA5BM,cAAc;GAC5B,MAAM,aACL,QAAQ,IAAI,kCACZ,QAAQ,IAAI,8BACZ,QAAQ,IAAI;GACb,MAAM,WAAW,aAAa;AAE9B,OAAI,CAAC,SACJ,OAAM,IAAI,MACT,kHACA;GAGF,MAAMA,SAA2B;IAChC;IACA;IACA,WAAW;IACX;AAED,OAAI;AACH,WAAO,IAAI,iBAAiB,OAAO;YAC3BC,KAAc;AACtB,UAAM,eAAe,QAClB,sBACA,IAAI,MAAM,yCAAyC;;KAErD;GAAC;GAAW;GAAQ;GAAM,CAAC;EAEb,OAAO;EAAM"}
@@ -68,7 +68,7 @@ function useVisitorTypingReporter({ client, conversationId }) {
68
68
  if (!(client && conversationId)) return;
69
69
  const trimmed = value.trim();
70
70
  latestPreviewRef.current = trimmed.slice(0, PREVIEW_MAX_LENGTH);
71
- const now = Date.now();
71
+ const now = typeof window !== "undefined" ? Date.now() : 0;
72
72
  if (trimmed.length === 0) {
73
73
  if (typingActiveRef.current) {
74
74
  typingActiveRef.current = false;
@@ -104,7 +104,7 @@ function useVisitorTypingReporter({ client, conversationId }) {
104
104
  const handleSubmit = useCallback(() => {
105
105
  if (!typingActiveRef.current) return;
106
106
  typingActiveRef.current = false;
107
- lastSentAtRef.current = Date.now();
107
+ lastSentAtRef.current = typeof window !== "undefined" ? Date.now() : 0;
108
108
  clearKeepAlive();
109
109
  clearStopTypingTimeout();
110
110
  sendTyping(false);
@@ -116,7 +116,7 @@ function useVisitorTypingReporter({ client, conversationId }) {
116
116
  const stop = useCallback(() => {
117
117
  if (!typingActiveRef.current) return;
118
118
  typingActiveRef.current = false;
119
- lastSentAtRef.current = Date.now();
119
+ lastSentAtRef.current = typeof window !== "undefined" ? Date.now() : 0;
120
120
  clearKeepAlive();
121
121
  clearStopTypingTimeout();
122
122
  sendTyping(false);
@@ -1 +1 @@
1
- {"version":3,"file":"use-visitor-typing-reporter.js","names":[],"sources":["../../../src/hooks/private/use-visitor-typing-reporter.ts"],"sourcesContent":["import type { CossistantClient } from \"@cossistant/core\";\nimport { useCallback, useEffect, useRef } from \"react\";\n\nconst PREVIEW_MAX_LENGTH = 2000;\nconst SEND_INTERVAL_MS = 800;\nconst KEEP_ALIVE_MS = 4000;\nconst STOP_TYPING_DELAY_MS = 2000; // Send isTyping: false after 2 seconds of inactivity\n\ntype UseVisitorTypingReporterOptions = {\n\tclient: CossistantClient | null;\n\tconversationId: string | null;\n};\n\ntype UseVisitorTypingReporterResult = {\n\thandleInputChange: (value: string) => void;\n\thandleSubmit: () => void;\n\tstop: () => void;\n};\n\n/**\n * Tracks visitor composer activity and reports typing previews to the backend.\n *\n * Handles throttling, keep-alive pings, inactivity fallbacks and ensures a\n * `stop` event is emitted when the component unmounts.\n */\nexport function useVisitorTypingReporter({\n\tclient,\n\tconversationId,\n}: UseVisitorTypingReporterOptions): UseVisitorTypingReporterResult {\n\tconst typingActiveRef = useRef(false);\n\tconst lastSentAtRef = useRef(0);\n\tconst latestPreviewRef = useRef<string>(\"\");\n\tconst keepAliveTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\tnull\n\t);\n\tconst stopTypingTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\tnull\n\t);\n\n\tconst clearKeepAlive = useCallback(() => {\n\t\tif (keepAliveTimeoutRef.current) {\n\t\t\tclearTimeout(keepAliveTimeoutRef.current);\n\t\t\tkeepAliveTimeoutRef.current = null;\n\t\t}\n\t}, []);\n\n\tconst clearStopTypingTimeout = useCallback(() => {\n\t\tif (stopTypingTimeoutRef.current) {\n\t\t\tclearTimeout(stopTypingTimeoutRef.current);\n\t\t\tstopTypingTimeoutRef.current = null;\n\t\t}\n\t}, []);\n\n\tconst sendTyping = useCallback(\n\t\tasync (isTyping: boolean, preview?: string | null) => {\n\t\t\tif (!(client && conversationId)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait client.setVisitorTyping({\n\t\t\t\t\tconversationId,\n\t\t\t\t\tisTyping,\n\t\t\t\t\tvisitorPreview: preview ?? undefined,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"[Support] Failed to send typing event\", error);\n\t\t\t}\n\t\t},\n\t\t[client, conversationId]\n\t);\n\n\tconst scheduleKeepAlive = useCallback(() => {\n\t\tclearKeepAlive();\n\t\tkeepAliveTimeoutRef.current = setTimeout(() => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t}\n\t\t}, KEEP_ALIVE_MS);\n\t}, [clearKeepAlive, sendTyping]);\n\n\tconst scheduleStopTyping = useCallback(() => {\n\t\tclearStopTypingTimeout();\n\t\tstopTypingTimeoutRef.current = setTimeout(() => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\ttypingActiveRef.current = false;\n\t\t\t\tclearKeepAlive();\n\t\t\t\tvoid sendTyping(false);\n\t\t\t}\n\t\t}, STOP_TYPING_DELAY_MS);\n\t}, [clearStopTypingTimeout, clearKeepAlive, sendTyping]);\n\n\tconst handleInputChange = useCallback(\n\t\t(value: string) => {\n\t\t\tif (!(client && conversationId)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmed = value.trim();\n\t\t\tlatestPreviewRef.current = trimmed.slice(0, PREVIEW_MAX_LENGTH);\n\t\t\tconst now = Date.now();\n\n\t\t\tif (trimmed.length === 0) {\n\t\t\t\tif (typingActiveRef.current) {\n\t\t\t\t\ttypingActiveRef.current = false;\n\t\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\t\tclearKeepAlive();\n\t\t\t\t\tclearStopTypingTimeout();\n\t\t\t\t\tvoid sendTyping(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Schedule auto-stop after inactivity\n\t\t\tscheduleStopTyping();\n\n\t\t\tif (!typingActiveRef.current) {\n\t\t\t\ttypingActiveRef.current = true;\n\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (now - lastSentAtRef.current >= SEND_INTERVAL_MS) {\n\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tclient,\n\t\t\tconversationId,\n\t\t\tsendTyping,\n\t\t\tscheduleKeepAlive,\n\t\t\tscheduleStopTyping,\n\t\t\tclearKeepAlive,\n\t\t\tclearStopTypingTimeout,\n\t\t]\n\t);\n\n\tconst handleSubmit = useCallback(() => {\n\t\tif (!typingActiveRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\ttypingActiveRef.current = false;\n\t\tlastSentAtRef.current = Date.now();\n\t\tclearKeepAlive();\n\t\tclearStopTypingTimeout();\n\t\tvoid sendTyping(false);\n\t}, [clearKeepAlive, clearStopTypingTimeout, sendTyping]);\n\n\tconst stop = useCallback(() => {\n\t\tif (!typingActiveRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\ttypingActiveRef.current = false;\n\t\tlastSentAtRef.current = Date.now();\n\t\tclearKeepAlive();\n\t\tclearStopTypingTimeout();\n\t\tvoid sendTyping(false);\n\t}, [clearKeepAlive, clearStopTypingTimeout, sendTyping]);\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\tvoid sendTyping(false);\n\t\t\t}\n\t\t\tclearKeepAlive();\n\t\t\tclearStopTypingTimeout();\n\t\t},\n\t\t[clearKeepAlive, clearStopTypingTimeout, sendTyping]\n\t);\n\n\treturn {\n\t\thandleInputChange,\n\t\thandleSubmit,\n\t\tstop,\n\t};\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AACzB,MAAM,gBAAgB;AACtB,MAAM,uBAAuB;;;;;;;AAmB7B,SAAgB,yBAAyB,EACxC,QACA,kBACmE;CACnE,MAAM,kBAAkB,OAAO,MAAM;CACrC,MAAM,gBAAgB,OAAO,EAAE;CAC/B,MAAM,mBAAmB,OAAe,GAAG;CAC3C,MAAM,sBAAsB,OAC3B,KACA;CACD,MAAM,uBAAuB,OAC5B,KACA;CAED,MAAM,iBAAiB,kBAAkB;AACxC,MAAI,oBAAoB,SAAS;AAChC,gBAAa,oBAAoB,QAAQ;AACzC,uBAAoB,UAAU;;IAE7B,EAAE,CAAC;CAEN,MAAM,yBAAyB,kBAAkB;AAChD,MAAI,qBAAqB,SAAS;AACjC,gBAAa,qBAAqB,QAAQ;AAC1C,wBAAqB,UAAU;;IAE9B,EAAE,CAAC;CAEN,MAAM,aAAa,YAClB,OAAO,UAAmB,YAA4B;AACrD,MAAI,EAAE,UAAU,gBACf;AAGD,MAAI;AACH,SAAM,OAAO,iBAAiB;IAC7B;IACA;IACA,gBAAgB,WAAW;IAC3B,CAAC;WACM,OAAO;AACf,WAAQ,MAAM,yCAAyC,MAAM;;IAG/D,CAAC,QAAQ,eAAe,CACxB;CAED,MAAM,oBAAoB,kBAAkB;AAC3C,kBA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AAC;CAExD,MAAM,OAAO,kBAAkB;AAC9B,MAAI,CAAC,gBAAgB,QACpB;AAGD,kBAAgB,UAAU;AAC1B,gBAAc,UAAU,KAAK,KAAK;AAClC,kBAAgB;AAChB,0BAAwB;AACxB,EAAK,WAAW,MAAM;IACpB;EAAC;EAAgB;EAAwB;EAAW,CAAC;AAExD,uBACa;AACX,MAAI,gBAAgB,QACnB,CAAK,WAAW,MAAM;AAEvB,kBAAgB;AAChB,0BAAwB;IAEzB;EAAC;EAAgB;EAAwB;EAAW,CACpD;AAED,QAAO;EACN;EACA;EACA;EACA"}
1
+ {"version":3,"file":"use-visitor-typing-reporter.js","names":[],"sources":["../../../src/hooks/private/use-visitor-typing-reporter.ts"],"sourcesContent":["import type { CossistantClient } from \"@cossistant/core\";\nimport { useCallback, useEffect, useRef } from \"react\";\n\nconst PREVIEW_MAX_LENGTH = 2000;\nconst SEND_INTERVAL_MS = 800;\nconst KEEP_ALIVE_MS = 4000;\nconst STOP_TYPING_DELAY_MS = 2000; // Send isTyping: false after 2 seconds of inactivity\n\ntype UseVisitorTypingReporterOptions = {\n\tclient: CossistantClient | null;\n\tconversationId: string | null;\n};\n\ntype UseVisitorTypingReporterResult = {\n\thandleInputChange: (value: string) => void;\n\thandleSubmit: () => void;\n\tstop: () => void;\n};\n\n/**\n * Tracks visitor composer activity and reports typing previews to the backend.\n *\n * Handles throttling, keep-alive pings, inactivity fallbacks and ensures a\n * `stop` event is emitted when the component unmounts.\n */\nexport function useVisitorTypingReporter({\n\tclient,\n\tconversationId,\n}: UseVisitorTypingReporterOptions): UseVisitorTypingReporterResult {\n\tconst typingActiveRef = useRef(false);\n\tconst lastSentAtRef = useRef(0);\n\tconst latestPreviewRef = useRef<string>(\"\");\n\tconst keepAliveTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\tnull\n\t);\n\tconst stopTypingTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(\n\t\tnull\n\t);\n\n\tconst clearKeepAlive = useCallback(() => {\n\t\tif (keepAliveTimeoutRef.current) {\n\t\t\tclearTimeout(keepAliveTimeoutRef.current);\n\t\t\tkeepAliveTimeoutRef.current = null;\n\t\t}\n\t}, []);\n\n\tconst clearStopTypingTimeout = useCallback(() => {\n\t\tif (stopTypingTimeoutRef.current) {\n\t\t\tclearTimeout(stopTypingTimeoutRef.current);\n\t\t\tstopTypingTimeoutRef.current = null;\n\t\t}\n\t}, []);\n\n\tconst sendTyping = useCallback(\n\t\tasync (isTyping: boolean, preview?: string | null) => {\n\t\t\tif (!(client && conversationId)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait client.setVisitorTyping({\n\t\t\t\t\tconversationId,\n\t\t\t\t\tisTyping,\n\t\t\t\t\tvisitorPreview: preview ?? undefined,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\"[Support] Failed to send typing event\", error);\n\t\t\t}\n\t\t},\n\t\t[client, conversationId]\n\t);\n\n\tconst scheduleKeepAlive = useCallback(() => {\n\t\tclearKeepAlive();\n\t\tkeepAliveTimeoutRef.current = setTimeout(() => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t}\n\t\t}, KEEP_ALIVE_MS);\n\t}, [clearKeepAlive, sendTyping]);\n\n\tconst scheduleStopTyping = useCallback(() => {\n\t\tclearStopTypingTimeout();\n\t\tstopTypingTimeoutRef.current = setTimeout(() => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\ttypingActiveRef.current = false;\n\t\t\t\tclearKeepAlive();\n\t\t\t\tvoid sendTyping(false);\n\t\t\t}\n\t\t}, STOP_TYPING_DELAY_MS);\n\t}, [clearStopTypingTimeout, clearKeepAlive, sendTyping]);\n\n\tconst handleInputChange = useCallback(\n\t\t(value: string) => {\n\t\t\tif (!(client && conversationId)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmed = value.trim();\n\t\t\tlatestPreviewRef.current = trimmed.slice(0, PREVIEW_MAX_LENGTH);\n\t\t\tconst now = typeof window !== \"undefined\" ? Date.now() : 0;\n\n\t\t\tif (trimmed.length === 0) {\n\t\t\t\tif (typingActiveRef.current) {\n\t\t\t\t\ttypingActiveRef.current = false;\n\t\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\t\tclearKeepAlive();\n\t\t\t\t\tclearStopTypingTimeout();\n\t\t\t\t\tvoid sendTyping(false);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Schedule auto-stop after inactivity\n\t\t\tscheduleStopTyping();\n\n\t\t\tif (!typingActiveRef.current) {\n\t\t\t\ttypingActiveRef.current = true;\n\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (now - lastSentAtRef.current >= SEND_INTERVAL_MS) {\n\t\t\t\tlastSentAtRef.current = now;\n\t\t\t\tvoid sendTyping(true, latestPreviewRef.current);\n\t\t\t\tscheduleKeepAlive();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tclient,\n\t\t\tconversationId,\n\t\t\tsendTyping,\n\t\t\tscheduleKeepAlive,\n\t\t\tscheduleStopTyping,\n\t\t\tclearKeepAlive,\n\t\t\tclearStopTypingTimeout,\n\t\t]\n\t);\n\n\tconst handleSubmit = useCallback(() => {\n\t\tif (!typingActiveRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\ttypingActiveRef.current = false;\n\t\tlastSentAtRef.current = typeof window !== \"undefined\" ? Date.now() : 0;\n\t\tclearKeepAlive();\n\t\tclearStopTypingTimeout();\n\t\tvoid sendTyping(false);\n\t}, [clearKeepAlive, clearStopTypingTimeout, sendTyping]);\n\n\tconst stop = useCallback(() => {\n\t\tif (!typingActiveRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\ttypingActiveRef.current = false;\n\t\tlastSentAtRef.current = typeof window !== \"undefined\" ? Date.now() : 0;\n\t\tclearKeepAlive();\n\t\tclearStopTypingTimeout();\n\t\tvoid sendTyping(false);\n\t}, [clearKeepAlive, clearStopTypingTimeout, sendTyping]);\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (typingActiveRef.current) {\n\t\t\t\tvoid sendTyping(false);\n\t\t\t}\n\t\t\tclearKeepAlive();\n\t\t\tclearStopTypingTimeout();\n\t\t},\n\t\t[clearKeepAlive, clearStopTypingTimeout, sendTyping]\n\t);\n\n\treturn {\n\t\thandleInputChange,\n\t\thandleSubmit,\n\t\tstop,\n\t};\n}\n"],"mappings":";;;AAGA,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AACzB,MAAM,gBAAgB;AACtB,MAAM,uBAAuB;;;;;;;AAmB7B,SAAgB,yBAAyB,EACxC,QACA,kBACmE;CACnE,MAAM,kBAAkB,OAAO,MAAM;CACrC,MAAM,gBAAgB,OAAO,EAAE;CAC/B,MAAM,mBAAmB,OAAe,GAAG;CAC3C,MAAM,sBAAsB,OAC3B,KACA;CACD,MAAM,uBAAuB,OAC5B,KACA;CAED,MAAM,iBAAiB,kBAAkB;AACxC,MAAI,oBAAoB,SAAS;AAChC,gBAAa,oBAAoB,QAAQ;AACzC,uBAAoB,UAAU;;IAE7B,EAAE,CAAC;CAEN,MAAM,yBAAyB,kBAAkB;AAChD,MAAI,qBAAqB,SAAS;AACjC,gBAAa,qBAAqB,QAAQ;AAC1C,wBAAqB,UAAU;;IAE9B,EAAE,CAAC;CAEN,MAAM,aAAa,YAClB,OAAO,UAAmB,YAA4B;AACrD,MAAI,EAAE,UAAU,gBACf;AAGD,MAAI;AACH,SAAM,OAAO,iBAAiB;IAC7B;IACA;IACA,gBAAgB,WAAW;IAC3B,CAAC;WACM,OAAO;AACf,WAAQ,MAAM,yCAAyC,MAAM;;IAG/D,CAAC,QAAQ,eAAe,CACxB;CAED,MAAM,oBAAoB,kBAAkB;AAC3C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,EAAK,WAAW,MAAM;IACpB;EAAC;EAAgB;EAAwB;EAAW,CAAC;CAExD,MAAM,OAAO,kBAAkB;AAC9B,MAAI,CAAC,gBAAgB,QACpB;AAGD,kBAAgB,UAAU;AAC1B,gBAAc,UAAU,OAAO,WAAW,cAAc,KAAK,KAAK,GAAG;AACrE,kBAAgB;AAChB,0BAAwB;AACxB,EAAK,WAAW,MAAM;IACpB;EAAC;EAAgB;EAAwB;EAAW,CAAC;AAExD,uBACa;AACX,MAAI,gBAAgB,QACnB,CAAK,WAAW,MAAM;AAEvB,kBAAgB;AAChB,0BAAwB;IAEzB;EAAC;EAAgB;EAAwB;EAAW,CACpD;AAED,QAAO;EACN;EACA;EACA;EACA"}
@@ -37,7 +37,7 @@ type UseConversationAutoSeenOptions = {
37
37
  /**
38
38
  * Automatically marks timeline items as seen when:
39
39
  * - A new timeline item arrives from someone else
40
- * - The page is visible/focused
40
+ * - The page is visible
41
41
  * - The support widget is open/visible
42
42
  * - The visitor is the current user
43
43
  *
@@ -7,7 +7,7 @@ const CONVERSATION_AUTO_SEEN_DELAY_MS = 2e3;
7
7
  /**
8
8
  * Automatically marks timeline items as seen when:
9
9
  * - A new timeline item arrives from someone else
10
- * - The page is visible/focused
10
+ * - The page is visible
11
11
  * - The support widget is open/visible
12
12
  * - The visitor is the current user
13
13
  *
@@ -32,26 +32,7 @@ function useConversationAutoSeen(options) {
32
32
  const lastSeenItemIdRef = useRef(null);
33
33
  const markSeenInFlightRef = useRef(false);
34
34
  const markSeenTimeoutRef = useRef(null);
35
- const { isPageVisible, hasWindowFocus } = useWindowVisibilityFocus();
36
- const latestStateRef = useRef({
37
- enabled,
38
- isWidgetOpen,
39
- isPageVisible,
40
- hasWindowFocus
41
- });
42
- useEffect(() => {
43
- latestStateRef.current = {
44
- enabled,
45
- isWidgetOpen,
46
- isPageVisible,
47
- hasWindowFocus
48
- };
49
- }, [
50
- enabled,
51
- isWidgetOpen,
52
- hasWindowFocus,
53
- isPageVisible
54
- ]);
35
+ const { isPageVisible } = useWindowVisibilityFocus();
55
36
  useEffect(() => {
56
37
  lastSeenItemIdRef.current = null;
57
38
  markSeenInFlightRef.current = false;
@@ -82,7 +63,7 @@ function useConversationAutoSeen(options) {
82
63
  conversationId
83
64
  ]);
84
65
  useEffect(() => {
85
- if (!(isWidgetOpen && enabled)) {
66
+ if (!(enabled && isWidgetOpen && client && conversationId && visitorId && lastTimelineItem && isPageVisible)) {
86
67
  if (markSeenTimeoutRef.current) {
87
68
  clearTimeout(markSeenTimeoutRef.current);
88
69
  markSeenTimeoutRef.current = null;
@@ -93,36 +74,40 @@ function useConversationAutoSeen(options) {
93
74
  clearTimeout(markSeenTimeoutRef.current);
94
75
  markSeenTimeoutRef.current = null;
95
76
  }
96
- if (!(client && conversationId && visitorId && lastTimelineItem && isPageVisible && hasWindowFocus)) return;
97
77
  if (lastTimelineItem.visitorId === visitorId) {
98
78
  lastSeenItemIdRef.current = lastTimelineItem.id || null;
99
79
  return;
100
80
  }
101
81
  if (lastSeenItemIdRef.current === lastTimelineItem.id) return;
102
- if (markSeenInFlightRef.current) return;
103
82
  const pendingItemId = lastTimelineItem.id || null;
104
83
  markSeenTimeoutRef.current = setTimeout(() => {
105
- const { enabled: latestEnabled, isWidgetOpen: latestIsWidgetOpen, isPageVisible: latestPageVisible, hasWindowFocus: latestHasFocus } = latestStateRef.current;
106
- if (!(client && conversationId && latestEnabled && latestIsWidgetOpen && latestPageVisible && latestHasFocus)) {
107
- markSeenInFlightRef.current = false;
108
- markSeenTimeoutRef.current = null;
109
- return;
110
- }
111
- markSeenInFlightRef.current = true;
112
- client.markConversationSeen({ conversationId }).then((response) => {
113
- lastSeenItemIdRef.current = pendingItemId;
114
- upsertConversationSeen({
115
- conversationId,
116
- actorType: "visitor",
117
- actorId: visitorId,
118
- lastSeenAt: new Date(response.lastSeenAt)
84
+ const attemptMarkSeen = () => {
85
+ if (!(enabled && isWidgetOpen && client && conversationId && visitorId && isPageVisible)) {
86
+ markSeenInFlightRef.current = false;
87
+ markSeenTimeoutRef.current = null;
88
+ return;
89
+ }
90
+ if (markSeenInFlightRef.current) {
91
+ markSeenTimeoutRef.current = setTimeout(attemptMarkSeen, 100);
92
+ return;
93
+ }
94
+ markSeenInFlightRef.current = true;
95
+ client.markConversationSeen({ conversationId }).then((response) => {
96
+ lastSeenItemIdRef.current = pendingItemId;
97
+ upsertConversationSeen({
98
+ conversationId,
99
+ actorType: "visitor",
100
+ actorId: visitorId,
101
+ lastSeenAt: new Date(response.lastSeenAt)
102
+ });
103
+ }).catch((err) => {
104
+ console.error("Failed to mark conversation as seen:", err);
105
+ }).finally(() => {
106
+ markSeenInFlightRef.current = false;
107
+ markSeenTimeoutRef.current = null;
119
108
  });
120
- }).catch((err) => {
121
- console.error("Failed to mark conversation as seen:", err);
122
- }).finally(() => {
123
- markSeenInFlightRef.current = false;
124
- markSeenTimeoutRef.current = null;
125
- });
109
+ };
110
+ attemptMarkSeen();
126
111
  }, CONVERSATION_AUTO_SEEN_DELAY_MS);
127
112
  return () => {
128
113
  if (markSeenTimeoutRef.current) {
@@ -137,8 +122,7 @@ function useConversationAutoSeen(options) {
137
122
  conversationId,
138
123
  visitorId,
139
124
  lastTimelineItem,
140
- isPageVisible,
141
- hasWindowFocus
125
+ isPageVisible
142
126
  ]);
143
127
  }
144
128
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-conversation-auto-seen.js","names":[],"sources":["../../src/hooks/use-conversation-auto-seen.ts"],"sourcesContent":["import type { CossistantClient } from \"@cossistant/core\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport { useEffect, useRef } from \"react\";\nimport {\n\thydrateConversationSeen,\n\tupsertConversationSeen,\n} from \"../realtime/seen-store\";\nimport { useWindowVisibilityFocus } from \"./use-window-visibility-focus\";\n\nexport const CONVERSATION_AUTO_SEEN_DELAY_MS = 2000;\n\nexport type UseConversationAutoSeenOptions = {\n\t/**\n\t * The Cossistant client instance.\n\t */\n\tclient: CossistantClient | null;\n\n\t/**\n\t * The real conversation ID. Pass null if no conversation exists yet.\n\t */\n\tconversationId: string | null;\n\n\t/**\n\t * Current visitor ID.\n\t */\n\tvisitorId?: string;\n\n\t/**\n\t * The last timeline item in the conversation.\n\t * Used to determine if we should mark as seen.\n\t */\n\tlastTimelineItem: TimelineItem | null;\n\n\t/**\n\t * Whether to enable auto-seen tracking.\n\t * Default: true\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Whether the support widget is currently open/visible.\n\t * This is required to ensure we only mark conversations as seen when\n\t * the widget is actually visible to the user.\n\t * Default: true\n\t */\n\tisWidgetOpen?: boolean;\n};\n\n/**\n * Automatically marks timeline items as seen when:\n * - A new timeline item arrives from someone else\n * - The page is visible/focused\n * - The support widget is open/visible\n * - The visitor is the current user\n *\n * Also handles:\n * - Fetching and hydrating initial seen data\n * - Preventing duplicate API calls\n * - Page visibility tracking\n * - Widget visibility tracking\n *\n * @example\n * ```tsx\n * useConversationAutoSeen({\n * client,\n * conversationId: realConversationId,\n * visitorId: visitor?.id,\n * lastTimelineItem: items[items.length - 1] ?? null,\n * });\n * ```\n */\nexport function useConversationAutoSeen(\n\toptions: UseConversationAutoSeenOptions\n): void {\n\tconst {\n\t\tclient,\n\t\tconversationId,\n\t\tvisitorId,\n\t\tlastTimelineItem,\n\t\tenabled = true,\n\t\tisWidgetOpen = true,\n\t} = options;\n\n\tconst lastSeenItemIdRef = useRef<string | null>(null);\n\tconst markSeenInFlightRef = useRef(false);\n\tconst markSeenTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst { isPageVisible, hasWindowFocus } = useWindowVisibilityFocus();\n\tconst latestStateRef = useRef({\n\t\tenabled,\n\t\tisWidgetOpen,\n\t\tisPageVisible,\n\t\thasWindowFocus,\n\t});\n\n\tuseEffect(() => {\n\t\tlatestStateRef.current = {\n\t\t\tenabled,\n\t\t\tisWidgetOpen,\n\t\t\tisPageVisible,\n\t\t\thasWindowFocus,\n\t\t};\n\t}, [enabled, isWidgetOpen, hasWindowFocus, isPageVisible]);\n\n\t// Reset seen tracking when conversation changes\n\tuseEffect(() => {\n\t\tlastSeenItemIdRef.current = null;\n\t\tmarkSeenInFlightRef.current = false;\n\t\tif (markSeenTimeoutRef.current) {\n\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t}\n\t}, [conversationId]);\n\n\t// Clear timeout immediately when widget closes and reset tracking\n\tuseEffect(() => {\n\t\tif (!isWidgetOpen) {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t// Reset last seen item ID so we don't skip marking when widget reopens\n\t\t\t// This ensures we check again when the widget is reopened\n\t\t\tlastSeenItemIdRef.current = null;\n\t\t}\n\t}, [isWidgetOpen]);\n\n\t// Fetch and hydrate initial seen data when conversation loads\n\tuseEffect(() => {\n\t\tif (enabled && client && conversationId) {\n\t\t\tvoid client\n\t\t\t\t.getConversationSeenData({ conversationId })\n\t\t\t\t.then((response) => {\n\t\t\t\t\tif (response.seenData.length > 0) {\n\t\t\t\t\t\thydrateConversationSeen(conversationId, response.seenData);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to fetch conversation seen data:\", err);\n\t\t\t\t});\n\t\t}\n\t}, [enabled, client, conversationId]);\n\n\t// Auto-mark timeline items as seen\n\tuseEffect(() => {\n\t\t// Early return if widget is closed - don't process any seen updates\n\t\tif (!(isWidgetOpen && enabled)) {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (markSeenTimeoutRef.current) {\n\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t}\n\n\t\tconst shouldMark =\n\t\t\tclient &&\n\t\t\tconversationId &&\n\t\t\tvisitorId &&\n\t\t\tlastTimelineItem &&\n\t\t\tisPageVisible &&\n\t\t\thasWindowFocus;\n\n\t\tif (!shouldMark) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Don't mark our own timeline items as seen via API (we already know we saw them)\n\t\tif (lastTimelineItem.visitorId === visitorId) {\n\t\t\tlastSeenItemIdRef.current = lastTimelineItem.id || null;\n\t\t\treturn;\n\t\t}\n\n\t\t// Already marked this item\n\t\tif (lastSeenItemIdRef.current === lastTimelineItem.id) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Already in flight\n\t\tif (markSeenInFlightRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst pendingItemId = lastTimelineItem.id || null;\n\n\t\tmarkSeenTimeoutRef.current = setTimeout(() => {\n\t\t\tconst {\n\t\t\t\tenabled: latestEnabled,\n\t\t\t\tisWidgetOpen: latestIsWidgetOpen,\n\t\t\t\tisPageVisible: latestPageVisible,\n\t\t\t\thasWindowFocus: latestHasFocus,\n\t\t\t} = latestStateRef.current;\n\n\t\t\tif (\n\t\t\t\t!(\n\t\t\t\t\tclient &&\n\t\t\t\t\tconversationId &&\n\t\t\t\t\tlatestEnabled &&\n\t\t\t\t\tlatestIsWidgetOpen &&\n\t\t\t\t\tlatestPageVisible &&\n\t\t\t\t\tlatestHasFocus\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tmarkSeenInFlightRef.current = true;\n\n\t\t\tclient\n\t\t\t\t.markConversationSeen({ conversationId })\n\t\t\t\t.then((response) => {\n\t\t\t\t\tlastSeenItemIdRef.current = pendingItemId;\n\n\t\t\t\t\t// Optimistically update local seen store\n\t\t\t\t\tupsertConversationSeen({\n\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\tactorType: \"visitor\",\n\t\t\t\t\t\tactorId: visitorId,\n\t\t\t\t\t\tlastSeenAt: new Date(response.lastSeenAt),\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to mark conversation as seen:\", err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t\t});\n\t\t}, CONVERSATION_AUTO_SEEN_DELAY_MS);\n\n\t\treturn () => {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t};\n\t}, [\n\t\tenabled,\n\t\tisWidgetOpen,\n\t\tclient,\n\t\tconversationId,\n\t\tvisitorId,\n\t\tlastTimelineItem,\n\t\tisPageVisible,\n\t\thasWindowFocus,\n\t]);\n}\n"],"mappings":";;;;;AASA,MAAa,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;AA8D/C,SAAgB,wBACf,SACO;CACP,MAAM,EACL,QACA,gBACA,WACA,kBACA,UAAU,MACV,eAAe,SACZ;CAEJ,MAAM,oBAAoB,OAAsB,KAAK;CACrD,MAAM,sBAAsB,OAAO,MAAM;CACzC,MAAM,qBAAqB,OAA6C,KAAK;CAC7E,MAAM,EAAE,eAAe,mBAAmB,0BAA0B;CACpE,MAAM,iBAAiB,OAAO;EAC7B;EACA;EACA;EACA;EACA,CAAC;AAEF,iBAAgB;AACf,iBAAe,UAAU;GACxB;GACA;GACA;GACA;GACA;IACC;EAAC;EAAS;EAAc;EAAgB;EAAc,CAAC;AAG1D,iBAAgB;AACf,oBAAkB,UAAU;AAC5B,sBAAoB,UAAU;AAC9B,MAAI,mBAAmB,SAAS;AAC/B,gBAAa,mBAAmB,QAAQ;AACxC,sBAAmB,UAAU;;IAE5B,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2BAAuB;KACtB;KACA,WAAW;KACX,SAAS;KACT,YAAY,IAAI,KAAK,SAAS,WAAW;KACzC,CAAC;KACD,CACD,OAAO,QAAQ;AACf,YAAQ,MAAM,wCAAwC,IAAI;KACzD,CACD,cAAc;AACd,wBAAoB,UAAU;AAC9B,uBAAmB,UAAU;KAC5B;KACD,gCAAgC;AAEnC,eAAa;AACZ,OAAI,mBAAmB,SAAS;AAC/B,iBAAa,mBAAmB,QAAQ;AACxC,uBAAmB,UAAU;;;IAG7B;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,CAAC"}
1
+ {"version":3,"file":"use-conversation-auto-seen.js","names":[],"sources":["../../src/hooks/use-conversation-auto-seen.ts"],"sourcesContent":["import type { CossistantClient } from \"@cossistant/core\";\nimport type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport { useEffect, useRef } from \"react\";\nimport {\n\thydrateConversationSeen,\n\tupsertConversationSeen,\n} from \"../realtime/seen-store\";\nimport { useWindowVisibilityFocus } from \"./use-window-visibility-focus\";\n\nexport const CONVERSATION_AUTO_SEEN_DELAY_MS = 2000;\n\nexport type UseConversationAutoSeenOptions = {\n\t/**\n\t * The Cossistant client instance.\n\t */\n\tclient: CossistantClient | null;\n\n\t/**\n\t * The real conversation ID. Pass null if no conversation exists yet.\n\t */\n\tconversationId: string | null;\n\n\t/**\n\t * Current visitor ID.\n\t */\n\tvisitorId?: string;\n\n\t/**\n\t * The last timeline item in the conversation.\n\t * Used to determine if we should mark as seen.\n\t */\n\tlastTimelineItem: TimelineItem | null;\n\n\t/**\n\t * Whether to enable auto-seen tracking.\n\t * Default: true\n\t */\n\tenabled?: boolean;\n\n\t/**\n\t * Whether the support widget is currently open/visible.\n\t * This is required to ensure we only mark conversations as seen when\n\t * the widget is actually visible to the user.\n\t * Default: true\n\t */\n\tisWidgetOpen?: boolean;\n};\n\n/**\n * Automatically marks timeline items as seen when:\n * - A new timeline item arrives from someone else\n * - The page is visible\n * - The support widget is open/visible\n * - The visitor is the current user\n *\n * Also handles:\n * - Fetching and hydrating initial seen data\n * - Preventing duplicate API calls\n * - Page visibility tracking\n * - Widget visibility tracking\n *\n * @example\n * ```tsx\n * useConversationAutoSeen({\n * client,\n * conversationId: realConversationId,\n * visitorId: visitor?.id,\n * lastTimelineItem: items[items.length - 1] ?? null,\n * });\n * ```\n */\nexport function useConversationAutoSeen(\n\toptions: UseConversationAutoSeenOptions\n): void {\n\tconst {\n\t\tclient,\n\t\tconversationId,\n\t\tvisitorId,\n\t\tlastTimelineItem,\n\t\tenabled = true,\n\t\tisWidgetOpen = true,\n\t} = options;\n\n\tconst lastSeenItemIdRef = useRef<string | null>(null);\n\tconst markSeenInFlightRef = useRef(false);\n\tconst markSeenTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\tconst { isPageVisible } = useWindowVisibilityFocus();\n\n\t// Reset seen tracking when conversation changes\n\tuseEffect(() => {\n\t\tlastSeenItemIdRef.current = null;\n\t\tmarkSeenInFlightRef.current = false;\n\t\tif (markSeenTimeoutRef.current) {\n\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t}\n\t}, [conversationId]);\n\n\t// Clear timeout immediately when widget closes and reset tracking\n\tuseEffect(() => {\n\t\tif (!isWidgetOpen) {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t// Reset last seen item ID so we don't skip marking when widget reopens\n\t\t\t// This ensures we check again when the widget is reopened\n\t\t\tlastSeenItemIdRef.current = null;\n\t\t}\n\t}, [isWidgetOpen]);\n\n\t// Fetch and hydrate initial seen data when conversation loads\n\tuseEffect(() => {\n\t\tif (enabled && client && conversationId) {\n\t\t\tvoid client\n\t\t\t\t.getConversationSeenData({ conversationId })\n\t\t\t\t.then((response) => {\n\t\t\t\t\tif (response.seenData.length > 0) {\n\t\t\t\t\t\thydrateConversationSeen(conversationId, response.seenData);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error(\"Failed to fetch conversation seen data:\", err);\n\t\t\t\t});\n\t\t}\n\t}, [enabled, client, conversationId]);\n\n\t// Auto-mark timeline items as seen\n\tuseEffect(() => {\n\t\tconst canMarkSeen =\n\t\t\tenabled &&\n\t\t\tisWidgetOpen &&\n\t\t\tclient &&\n\t\t\tconversationId &&\n\t\t\tvisitorId &&\n\t\t\tlastTimelineItem &&\n\t\t\tisPageVisible;\n\n\t\tif (!canMarkSeen) {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (markSeenTimeoutRef.current) {\n\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t}\n\n\t\t// Don't mark our own timeline items as seen via API (we already know we saw them)\n\t\tif (lastTimelineItem.visitorId === visitorId) {\n\t\t\tlastSeenItemIdRef.current = lastTimelineItem.id || null;\n\t\t\treturn;\n\t\t}\n\n\t\t// Already marked this item\n\t\tif (lastSeenItemIdRef.current === lastTimelineItem.id) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst pendingItemId = lastTimelineItem.id || null;\n\n\t\tmarkSeenTimeoutRef.current = setTimeout(() => {\n\t\t\tconst attemptMarkSeen = () => {\n\t\t\t\tconst stillCanMark =\n\t\t\t\t\tenabled &&\n\t\t\t\t\tisWidgetOpen &&\n\t\t\t\t\tclient &&\n\t\t\t\t\tconversationId &&\n\t\t\t\t\tvisitorId &&\n\t\t\t\t\tisPageVisible;\n\n\t\t\t\tif (!stillCanMark) {\n\t\t\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (markSeenInFlightRef.current) {\n\t\t\t\t\tmarkSeenTimeoutRef.current = setTimeout(attemptMarkSeen, 100);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tmarkSeenInFlightRef.current = true;\n\n\t\t\t\tclient\n\t\t\t\t\t.markConversationSeen({ conversationId })\n\t\t\t\t\t.then((response) => {\n\t\t\t\t\t\tlastSeenItemIdRef.current = pendingItemId;\n\n\t\t\t\t\t\t// Optimistically update local seen store\n\t\t\t\t\t\tupsertConversationSeen({\n\t\t\t\t\t\t\tconversationId,\n\t\t\t\t\t\t\tactorType: \"visitor\",\n\t\t\t\t\t\t\tactorId: visitorId,\n\t\t\t\t\t\t\tlastSeenAt: new Date(response.lastSeenAt),\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.catch((err) => {\n\t\t\t\t\t\tconsole.error(\"Failed to mark conversation as seen:\", err);\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tmarkSeenInFlightRef.current = false;\n\t\t\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t\t\t});\n\t\t\t};\n\n\t\t\tattemptMarkSeen();\n\t\t}, CONVERSATION_AUTO_SEEN_DELAY_MS);\n\n\t\treturn () => {\n\t\t\tif (markSeenTimeoutRef.current) {\n\t\t\t\tclearTimeout(markSeenTimeoutRef.current);\n\t\t\t\tmarkSeenTimeoutRef.current = null;\n\t\t\t}\n\t\t};\n\t}, [\n\t\tenabled,\n\t\tisWidgetOpen,\n\t\tclient,\n\t\tconversationId,\n\t\tvisitorId,\n\t\tlastTimelineItem,\n\t\tisPageVisible,\n\t]);\n}\n"],"mappings":";;;;;AASA,MAAa,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;AA8D/C,SAAgB,wBACf,SACO;CACP,MAAM,EACL,QACA,gBACA,WACA,kBACA,UAAU,MACV,eAAe,SACZ;CAEJ,MAAM,oBAAoB,OAA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,yBAAoB,UAAU;AAC9B,wBAAmB,UAAU;AAC7B;;AAGD,QAAI,oBAAoB,SAAS;AAChC,wBAAmB,UAAU,WAAW,iBAAiB,IAAI;AAC7D;;AAGD,wBAAoB,UAAU;AAE9B,WACE,qBAAqB,EAAE,gBAAgB,CAAC,CACxC,MAAM,aAAa;AACnB,uBAAkB,UAAU;AAG5B,4BAAuB;MACtB;MACA,WAAW;MACX,SAAS;MACT,YAAY,IAAI,KAAK,SAAS,WAAW;MACzC,CAAC;MACD,CACD,OAAO,QAAQ;AACf,aAAQ,MAAM,wCAAwC,IAAI;MACzD,CACD,cAAc;AACd,yBAAoB,UAAU;AAC9B,wBAAmB,UAAU;MAC5B;;AAGJ,oBAAiB;KACf,gCAAgC;AAEnC,eAAa;AACZ,OAAI,mBAAmB,SAAS;AAC/B,iBAAa,mBAAmB,QAAQ;AACxC,uBAAmB,UAAU;;;IAG7B;EACF;EACA;EACA;EACA;EACA;EACA;EACA;EACA,CAAC"}
@@ -91,7 +91,7 @@ function useConversationPage(options) {
91
91
  userId: null,
92
92
  visitorId: visitor?.id ?? null,
93
93
  aiAgentId: null,
94
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
94
+ createdAt: typeof window !== "undefined" ? (/* @__PURE__ */ new Date()).toISOString() : "",
95
95
  deletedAt: null
96
96
  };
97
97
  return [...baseItems, identificationItem];
@@ -1 +1 @@
1
- {"version":3,"file":"use-conversation-page.js","names":["identificationItem: TimelineItem"],"sources":["../../src/hooks/use-conversation-page.ts"],"sourcesContent":["import type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport {\n\tConversationTimelineType,\n\tTimelineItemVisibility,\n} from \"@cossistant/types/enums\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { useSupport } from \"../provider\";\nimport { useDefaultMessages } from \"./private/use-default-messages\";\nimport { useConversationAutoSeen } from \"./use-conversation-auto-seen\";\nimport { useConversationLifecycle } from \"./use-conversation-lifecycle\";\nimport { useConversationTimelineItems } from \"./use-conversation-timeline-items\";\nimport { useMessageComposer } from \"./use-message-composer\";\n\nexport type UseConversationPageOptions = {\n\t/**\n\t * Initial conversation ID (from URL params, navigation state, etc.)\n\t * Can be PENDING_CONVERSATION_ID or a real ID.\n\t */\n\tconversationId: string;\n\n\t/**\n\t * Optional initial message to send when the conversation opens.\n\t */\n\tinitialMessage?: string;\n\n\t/**\n\t * Callback when conversation ID changes (e.g., after creation).\n\t * Use this to update navigation state or URL.\n\t */\n\tonConversationIdChange?: (conversationId: string) => void;\n\n\t/**\n\t * Optional timeline items to pass through (e.g., optimistic updates).\n\t */\n\titems?: TimelineItem[];\n\n\t/**\n\t * Whether automatic \"seen\" tracking should be enabled.\n\t * Set to false when the conversation isn't visible (e.g. widget closed).\n\t * Default: true\n\t */\n\tautoSeenEnabled?: boolean;\n};\n\nexport type UseConversationPageReturn = {\n\t// Conversation state\n\tconversationId: string;\n\tisPending: boolean;\n\titems: TimelineItem[];\n\tisLoading: boolean;\n\terror: Error | null;\n\n\t// Message composer\n\tcomposer: {\n\t\tmessage: string;\n\t\tfiles: File[];\n\t\tisSubmitting: boolean;\n\t\tcanSubmit: boolean;\n\t\tsetMessage: (message: string) => void;\n\t\taddFiles: (files: File[]) => void;\n\t\tremoveFile: (index: number) => void;\n\t\tsubmit: () => void;\n\t};\n\n\t// UI helpers\n\thasItems: boolean;\n\tlastTimelineItem: TimelineItem | null;\n};\n\n/**\n * Main orchestrator hook for the conversation page.\n *\n * This hook combines all conversation-related logic:\n * - Lifecycle management (pending → real conversation)\n * - Message fetching and display\n * - Message composition and sending\n * - Automatic seen tracking\n * - Default/welcome messages before conversation is created\n *\n * It provides a clean, simple API for building conversation UIs.\n *\n * @example\n * ```tsx\n * export function ConversationPage({ conversationId: initialId }) {\n * const conversation = useConversationPage({\n * conversationId: initialId,\n * onConversationIdChange: (newId) => {\n * // Update URL or navigation state\n * navigate(`/conversation/${newId}`);\n * },\n * });\n *\n * return (\n * <>\n * <MessageList messages={conversation.messages} />\n * <MessageInput\n * value={conversation.composer.message}\n * onChange={conversation.composer.setMessage}\n * onSubmit={conversation.composer.submit}\n * />\n * </>\n * );\n * }\n * ```\n */\nexport function useConversationPage(\n\toptions: UseConversationPageOptions\n): UseConversationPageReturn {\n\tconst {\n\t\tconversationId: initialConversationId,\n\t\tinitialMessage,\n\t\tonConversationIdChange,\n\t\titems: passedItems = [],\n\t\tautoSeenEnabled = true,\n\t} = options;\n\n\tconst { client, visitor } = useSupport();\n\n\tconst trimmedInitialMessage = initialMessage?.trim() ?? \"\";\n\tconst hasInitialMessage = trimmedInitialMessage.length > 0;\n\n\t// 1. Manage conversation lifecycle (pending vs real)\n\tconst lifecycle = useConversationLifecycle({\n\t\tinitialConversationId,\n\t\tonConversationCreated: onConversationIdChange,\n\t});\n\n\t// 2. Get default timeline items for pending state\n\tconst defaultTimelineItems = useDefaultMessages({\n\t\tconversationId: lifecycle.conversationId,\n\t});\n\n\tconst effectiveDefaultTimelineItems = hasInitialMessage\n\t\t? []\n\t\t: defaultTimelineItems;\n\n\t// 3. Fetch timeline items from backend if real conversation exists\n\tconst timelineQuery = useConversationTimelineItems(lifecycle.conversationId, {\n\t\tenabled: !lifecycle.isPending,\n\t});\n\n\t// 4. Determine which items to display\n\tconst baseItems = useMemo(() => {\n\t\t// If we have fetched timeline items, use them\n\t\tif (timelineQuery.items.length > 0) {\n\t\t\treturn timelineQuery.items;\n\t\t}\n\n\t\t// If pending, use default timeline items\n\t\tif (lifecycle.isPending && effectiveDefaultTimelineItems.length > 0) {\n\t\t\treturn effectiveDefaultTimelineItems;\n\t\t}\n\n\t\t// Use passed items as fallback\n\t\tif (passedItems.length > 0) {\n\t\t\treturn passedItems;\n\t\t}\n\n\t\treturn [];\n\t}, [\n\t\ttimelineQuery.items,\n\t\tlifecycle.isPending,\n\t\teffectiveDefaultTimelineItems,\n\t\tpassedItems,\n\t]);\n\n\tconst shouldShowIdentificationTool = useMemo(() => {\n\t\tif (lifecycle.isPending) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (visitor?.contact) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn !baseItems.some(\n\t\t\t(item) => item.type === ConversationTimelineType.IDENTIFICATION\n\t\t);\n\t}, [baseItems, lifecycle.isPending, visitor?.contact]);\n\n\tconst displayItems = useMemo(() => {\n\t\tif (!shouldShowIdentificationTool) {\n\t\t\treturn baseItems;\n\t\t}\n\n\t\tconst organizationId =\n\t\t\tbaseItems.at(-1)?.organizationId ??\n\t\t\tclient.getConfiguration().organizationId ??\n\t\t\t\"\";\n\n\t\tconst identificationItem: TimelineItem = {\n\t\t\tid: `identification-${lifecycle.conversationId}`,\n\t\t\tconversationId: lifecycle.conversationId,\n\t\t\torganizationId,\n\t\t\tvisibility: TimelineItemVisibility.PUBLIC,\n\t\t\ttype: ConversationTimelineType.IDENTIFICATION,\n\t\t\ttext: null,\n\t\t\ttool: \"identification\",\n\t\t\tparts: [],\n\t\t\tuserId: null,\n\t\t\tvisitorId: visitor?.id ?? null,\n\t\t\taiAgentId: null,\n\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\tdeletedAt: null,\n\t\t};\n\n\t\treturn [...baseItems, identificationItem];\n\t}, [\n\t\tbaseItems,\n\t\tclient,\n\t\tlifecycle.conversationId,\n\t\tshouldShowIdentificationTool,\n\t\tvisitor?.id,\n\t]);\n\n\tconst lastTimelineItem = useMemo(\n\t\t() => displayItems.at(-1) ?? null,\n\t\t[displayItems]\n\t);\n\n\t// 5. Set up message composer\n\tconst composer = useMessageComposer({\n\t\tclient,\n\t\tconversationId: lifecycle.realConversationId,\n\t\tdefaultTimelineItems: effectiveDefaultTimelineItems,\n\t\tvisitorId: visitor?.id,\n\t\tonMessageSent: (newConversationId) => {\n\t\t\t// Transition from pending to real conversation\n\t\t\tif (lifecycle.isPending) {\n\t\t\t\tlifecycle.setConversationId(newConversationId);\n\t\t\t}\n\t\t},\n\t});\n\n\tconst initialMessageSubmittedRef = useRef(false);\n\tconst lastInitialMessageRef = useRef<string | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!hasInitialMessage) {\n\t\t\tinitialMessageSubmittedRef.current = false;\n\t\t\tlastInitialMessageRef.current = null;\n\t\t\treturn;\n\t\t}\n\n\t\tif (lastInitialMessageRef.current !== trimmedInitialMessage) {\n\t\t\tinitialMessageSubmittedRef.current = false;\n\t\t\tlastInitialMessageRef.current = trimmedInitialMessage;\n\t\t}\n\n\t\tif (!lifecycle.isPending) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (composer.message !== trimmedInitialMessage) {\n\t\t\tcomposer.setMessage(trimmedInitialMessage);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tinitialMessageSubmittedRef.current ||\n\t\t\tcomposer.isSubmitting ||\n\t\t\t!composer.canSubmit\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tinitialMessageSubmittedRef.current = true;\n\t\tcomposer.submit();\n\t}, [\n\t\thasInitialMessage,\n\t\tlifecycle.isPending,\n\t\tcomposer.message,\n\t\tcomposer.setMessage,\n\t\tcomposer.isSubmitting,\n\t\tcomposer.canSubmit,\n\t\tcomposer.submit,\n\t\ttrimmedInitialMessage,\n\t]);\n\n\t// 6. Auto-mark messages as seen\n\tuseConversationAutoSeen({\n\t\tclient,\n\t\tconversationId: lifecycle.realConversationId,\n\t\tvisitorId: visitor?.id,\n\t\tlastTimelineItem,\n\t\tenabled: autoSeenEnabled,\n\t\tisWidgetOpen: autoSeenEnabled,\n\t});\n\n\treturn {\n\t\tconversationId: lifecycle.conversationId,\n\t\tisPending: lifecycle.isPending,\n\t\titems: displayItems,\n\t\tisLoading: timelineQuery.isLoading,\n\t\terror: timelineQuery.error || composer.error,\n\t\tcomposer: {\n\t\t\tmessage: composer.message,\n\t\t\tfiles: composer.files,\n\t\t\tisSubmitting: composer.isSubmitting,\n\t\t\tcanSubmit: composer.canSubmit,\n\t\t\tsetMessage: composer.setMessage,\n\t\t\taddFiles: composer.addFiles,\n\t\t\tremoveFile: composer.removeFile,\n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AAO,cAAc,SAAS,SAAS;EACvC,UAAU;GACT,SAAS,SAAS;GAClB,OAAO,SAAS;GAChB,cAAc,SAAS;GACvB,WAAW,SAAS;GACpB,YAAY,SAAS;GACrB,UAAU,SAAS;GACnB,YAAY,SAAS;GACrB,QAAQ,SAAS;GACjB;EACD,UAAU,aAAa,SAAS;EAChC;EACA"}
1
+ {"version":3,"file":"use-conversation-page.js","names":["identificationItem: TimelineItem"],"sources":["../../src/hooks/use-conversation-page.ts"],"sourcesContent":["import type { TimelineItem } from \"@cossistant/types/api/timeline-item\";\nimport {\n\tConversationTimelineType,\n\tTimelineItemVisibility,\n} from \"@cossistant/types/enums\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { useSupport } from \"../provider\";\nimport { useDefaultMessages } from \"./private/use-default-messages\";\nimport { useConversationAutoSeen } from \"./use-conversation-auto-seen\";\nimport { useConversationLifecycle } from \"./use-conversation-lifecycle\";\nimport { useConversationTimelineItems } from \"./use-conversation-timeline-items\";\nimport { useMessageComposer } from \"./use-message-composer\";\n\nexport type UseConversationPageOptions = {\n\t/**\n\t * Initial conversation ID (from URL params, navigation state, etc.)\n\t * Can be PENDING_CONVERSATION_ID or a real ID.\n\t */\n\tconversationId: string;\n\n\t/**\n\t * Optional initial message to send when the conversation opens.\n\t */\n\tinitialMessage?: string;\n\n\t/**\n\t * Callback when conversation ID changes (e.g., after creation).\n\t * Use this to update navigation state or URL.\n\t */\n\tonConversationIdChange?: (conversationId: string) => void;\n\n\t/**\n\t * Optional timeline items to pass through (e.g., optimistic updates).\n\t */\n\titems?: TimelineItem[];\n\n\t/**\n\t * Whether automatic \"seen\" tracking should be enabled.\n\t * Set to false when the conversation isn't visible (e.g. widget closed).\n\t * Default: true\n\t */\n\tautoSeenEnabled?: boolean;\n};\n\nexport type UseConversationPageReturn = {\n\t// Conversation state\n\tconversationId: string;\n\tisPending: boolean;\n\titems: TimelineItem[];\n\tisLoading: boolean;\n\terror: Error | null;\n\n\t// Message composer\n\tcomposer: {\n\t\tmessage: string;\n\t\tfiles: File[];\n\t\tisSubmitting: boolean;\n\t\tcanSubmit: boolean;\n\t\tsetMessage: (message: string) => void;\n\t\taddFiles: (files: File[]) => void;\n\t\tremoveFile: (index: number) => void;\n\t\tsubmit: () => void;\n\t};\n\n\t// UI helpers\n\thasItems: boolean;\n\tlastTimelineItem: TimelineItem | null;\n};\n\n/**\n * Main orchestrator hook for the conversation page.\n *\n * This hook combines all conversation-related logic:\n * - Lifecycle management (pending → real conversation)\n * - Message fetching and display\n * - Message composition and sending\n * - Automatic seen tracking\n * - Default/welcome messages before conversation is created\n *\n * It provides a clean, simple API for building conversation UIs.\n *\n * @example\n * ```tsx\n * export function ConversationPage({ conversationId: initialId }) {\n * const conversation = useConversationPage({\n * conversationId: initialId,\n * onConversationIdChange: (newId) => {\n * // Update URL or navigation state\n * navigate(`/conversation/${newId}`);\n * },\n * });\n *\n * return (\n * <>\n * <MessageList messages={conversation.messages} />\n * <MessageInput\n * value={conversation.composer.message}\n * onChange={conversation.composer.setMessage}\n * onSubmit={conversation.composer.submit}\n * />\n * </>\n * );\n * }\n * ```\n */\nexport function useConversationPage(\n\toptions: UseConversationPageOptions\n): UseConversationPageReturn {\n\tconst {\n\t\tconversationId: initialConversationId,\n\t\tinitialMessage,\n\t\tonConversationIdChange,\n\t\titems: passedItems = [],\n\t\tautoSeenEnabled = true,\n\t} = options;\n\n\tconst { client, visitor } = useSupport();\n\n\tconst trimmedInitialMessage = initialMessage?.trim() ?? \"\";\n\tconst hasInitialMessage = trimmedInitialMessage.length > 0;\n\n\t// 1. Manage conversation lifecycle (pending vs real)\n\tconst lifecycle = useConversationLifecycle({\n\t\tinitialConversationId,\n\t\tonConversationCreated: onConversationIdChange,\n\t});\n\n\t// 2. Get default timeline items for pending state\n\tconst defaultTimelineItems = useDefaultMessages({\n\t\tconversationId: lifecycle.conversationId,\n\t});\n\n\tconst effectiveDefaultTimelineItems = hasInitialMessage\n\t\t? []\n\t\t: defaultTimelineItems;\n\n\t// 3. Fetch timeline items from backend if real conversation exists\n\tconst timelineQuery = useConversationTimelineItems(lifecycle.conversationId, {\n\t\tenabled: !lifecycle.isPending,\n\t});\n\n\t// 4. Determine which items to display\n\tconst baseItems = useMemo(() => {\n\t\t// If we have fetched timeline items, use them\n\t\tif (timelineQuery.items.length > 0) {\n\t\t\treturn timelineQuery.items;\n\t\t}\n\n\t\t// If pending, use default timeline items\n\t\tif (lifecycle.isPending && effectiveDefaultTimelineItems.length > 0) {\n\t\t\treturn effectiveDefaultTimelineItems;\n\t\t}\n\n\t\t// Use passed items as fallback\n\t\tif (passedItems.length > 0) {\n\t\t\treturn passedItems;\n\t\t}\n\n\t\treturn [];\n\t}, [\n\t\ttimelineQuery.items,\n\t\tlifecycle.isPending,\n\t\teffectiveDefaultTimelineItems,\n\t\tpassedItems,\n\t]);\n\n\tconst shouldShowIdentificationTool = useMemo(() => {\n\t\tif (lifecycle.isPending) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (visitor?.contact) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn !baseItems.some(\n\t\t\t(item) => item.type === ConversationTimelineType.IDENTIFICATION\n\t\t);\n\t}, [baseItems, lifecycle.isPending, visitor?.contact]);\n\n\tconst displayItems = useMemo(() => {\n\t\tif (!shouldShowIdentificationTool) {\n\t\t\treturn baseItems;\n\t\t}\n\n\t\tconst organizationId =\n\t\t\tbaseItems.at(-1)?.organizationId ??\n\t\t\tclient.getConfiguration().organizationId ??\n\t\t\t\"\";\n\n\t\tconst identificationItem: TimelineItem = {\n\t\t\tid: `identification-${lifecycle.conversationId}`,\n\t\t\tconversationId: lifecycle.conversationId,\n\t\t\torganizationId,\n\t\t\tvisibility: TimelineItemVisibility.PUBLIC,\n\t\t\ttype: ConversationTimelineType.IDENTIFICATION,\n\t\t\ttext: null,\n\t\t\ttool: \"identification\",\n\t\t\tparts: [],\n\t\t\tuserId: null,\n\t\t\tvisitorId: visitor?.id ?? null,\n\t\t\taiAgentId: null,\n\t\t\tcreatedAt: typeof window !== \"undefined\" ? new Date().toISOString() : \"\",\n\t\t\tdeletedAt: null,\n\t\t};\n\n\t\treturn [...baseItems, identificationItem];\n\t}, [\n\t\tbaseItems,\n\t\tclient,\n\t\tlifecycle.conversationId,\n\t\tshouldShowIdentificationTool,\n\t\tvisitor?.id,\n\t]);\n\n\tconst lastTimelineItem = useMemo(\n\t\t() => displayItems.at(-1) ?? null,\n\t\t[displayItems]\n\t);\n\n\t// 5. Set up message composer\n\tconst composer = useMessageComposer({\n\t\tclient,\n\t\tconversationId: lifecycle.realConversationId,\n\t\tdefaultTimelineItems: effectiveDefaultTimelineItems,\n\t\tvisitorId: visitor?.id,\n\t\tonMessageSent: (newConversationId) => {\n\t\t\t// Transition from pending to real conversation\n\t\t\tif (lifecycle.isPending) {\n\t\t\t\tlifecycle.setConversationId(newConversationId);\n\t\t\t}\n\t\t},\n\t});\n\n\tconst initialMessageSubmittedRef = useRef(false);\n\tconst lastInitialMessageRef = useRef<string | null>(null);\n\n\tuseEffect(() => {\n\t\tif (!hasInitialMessage) {\n\t\t\tinitialMessageSubmittedRef.current = false;\n\t\t\tlastInitialMessageRef.current = null;\n\t\t\treturn;\n\t\t}\n\n\t\tif (lastInitialMessageRef.current !== trimmedInitialMessage) {\n\t\t\tinitialMessageSubmittedRef.current = false;\n\t\t\tlastInitialMessageRef.current = trimmedInitialMessage;\n\t\t}\n\n\t\tif (!lifecycle.isPending) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (composer.message !== trimmedInitialMessage) {\n\t\t\tcomposer.setMessage(trimmedInitialMessage);\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tinitialMessageSubmittedRef.current ||\n\t\t\tcomposer.isSubmitting ||\n\t\t\t!composer.canSubmit\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tinitialMessageSubmittedRef.current = true;\n\t\tcomposer.submit();\n\t}, [\n\t\thasInitialMessage,\n\t\tlifecycle.isPending,\n\t\tcomposer.message,\n\t\tcomposer.setMessage,\n\t\tcomposer.isSubmitting,\n\t\tcomposer.canSubmit,\n\t\tcomposer.submit,\n\t\ttrimmedInitialMessage,\n\t]);\n\n\t// 6. Auto-mark messages as seen\n\tuseConversationAutoSeen({\n\t\tclient,\n\t\tconversationId: lifecycle.realConversationId,\n\t\tvisitorId: visitor?.id,\n\t\tlastTimelineItem,\n\t\tenabled: autoSeenEnabled,\n\t\tisWidgetOpen: autoSeenEnabled,\n\t});\n\n\treturn {\n\t\tconversationId: lifecycle.conversationId,\n\t\tisPending: lifecycle.isPending,\n\t\titems: displayItems,\n\t\tisLoading: timelineQuery.isLoading,\n\t\terror: timelineQuery.error || composer.error,\n\t\tcomposer: {\n\t\t\tmessage: composer.message,\n\t\t\tfiles: composer.files,\n\t\t\tisSubmitting: composer.isSubmitting,\n\t\t\tcanSubmit: composer.canSubmit,\n\t\t\tsetMessage: composer.setMessage,\n\t\t\taddFiles: composer.addFiles,\n\t\t\tremoveFile: composer.removeFile,\n\t\t\tsubmit: composer.submit,\n\t\t},\n\t\thasItems: displayItems.length > 0,\n\t\tlastTimelineItem,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,SAAgB,oBACf,SAC4B;CAC5B,MAAM,EACL,gBAAgB,uBAChB,gBACA,wBACA,OAAO,cAAc,EAAE,EACvB,kBAAkB,SACf;CAEJ,MAAM,EAAE,QAAQ,YAAY,YAAY;CAExC,MAAM,wBAAwB,gBAAgB,MAAM,IAAI;CACxD,MAAM,oBAAoB,sBAAsB,SAAS;CAGzD,MAAM,YAAY,yBAAyB;EAC1C;EACA,uBAAuB;EACvB,CAAC;CAGF,MAAM,uBAAuB,mBAAmB,EAC/C,gBAAgB,UAAU,gBAC1B,CAAC;CAEF,MAAM,gCAAgC,oBACnC,EAAE,GACF;CAGH,MAAM,gBAAgB,6BAA6B,UAAU,gBAAgB,EAC5E,SAAS,CAAC,UAAU,WACpB,CAA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KAAK;AAEzD,iBAAgB;AACf,MAAI,CAAC,mBAAmB;AACvB,8BAA2B,UAAU;AACrC,yBAAsB,UAAU;AAChC;;AAGD,MAAI,sBAAsB,YAAY,uBAAuB;AAC5D,8BAA2B,UAAU;AACrC,yBAAsB,UAAU;;AAGjC,MAAI,CAAC,UAAU,UACd;AAGD,MAAI,SAAS,YAAY,uBAAuB;AAC/C,YAAS,WAAW,sBAAsB;AAC1C;;AAGD,MACC,2BAA2B,WAC3B,SAAS,gBACT,CAAC,SAAS,UAEV;AAGD,6BAA2B,UAAU;AACrC,WAAS,QAAQ;IACf;EACF;EACA,UAAU;EACV,SAAS;EACT,SAAS;EACT,SAAS;EACT,SAAS;EACT,SAAS;EACT;EACA,CAAC;AAGF,yBAAwB;EACvB;EACA,gBAAgB,UAAU;EAC1B,WAAW,SAAS;EACpB;EACA,SAAS;EACT,cAAc;EACd,CAAC;AAEF,QAAO;EACN,gBAAgB,UAAU;EAC1B,WAAW,UAAU;EACrB,OAAO;EACP,WAAW,cAAc;EACzB,OAAO,cAAc,SAAS,SAAS;EACvC,UAAU;GACT,SAAS,SAAS;GAClB,OAAO,SAAS;GAChB,cAAc,SAAS;GACvB,WAAW,SAAS;GACpB,YAAY,SAAS;GACrB,UAAU,SAAS;GACnB,YAAY,SAAS;GACrB,QAAQ,SAAS;GACjB;EACD,UAAU,aAAa,SAAS;EAChC;EACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-conversation-seen.d.ts","names":[],"sources":["../../src/hooks/use-conversation-seen.ts"],"sourcesContent":[],"mappings":";;;KAIK,0BAAA;gBACU;AALmD,CAAA;AAoBlE;AAwDA;;;iBAxDgB,mBAAA,sDAEN,6BACP;;;;;;;iBAqDa,4BAAA,sDAEN,6CAEP"}
1
+ {"version":3,"file":"use-conversation-seen.d.ts","names":[],"sources":["../../src/hooks/use-conversation-seen.ts"],"sourcesContent":[],"mappings":";;;KAIK,0BAAA;gBACU;AALmD,CAAA;AAoBlE;AA8DA;;;iBA9DgB,mBAAA,sDAEN,6BACP;;;;;;;iBA2Da,4BAAA,sDAEN,6CAEP"}