@helpway/react 0.15.2 → 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -523,7 +523,16 @@ function latestAssignee(items) {
523
523
  }
524
524
  return null;
525
525
  }
526
+ var AI_INDICATOR_MAX_MS = 45e3;
526
527
  function createWidgetStore() {
528
+ const indicatorWatchdogs = /* @__PURE__ */ new Map();
529
+ const clearWatchdog = (conversationId) => {
530
+ const timer = indicatorWatchdogs.get(conversationId);
531
+ if (timer !== void 0) {
532
+ clearTimeout(timer);
533
+ indicatorWatchdogs.delete(conversationId);
534
+ }
535
+ };
527
536
  const store = createStore((set, get) => ({
528
537
  // Initial state
529
538
  isReady: false,
@@ -683,6 +692,17 @@ function createWidgetStore() {
683
692
  });
684
693
  },
685
694
  remapConversationId(oldId, newId) {
695
+ if (indicatorWatchdogs.has(oldId)) {
696
+ clearWatchdog(oldId);
697
+ indicatorWatchdogs.set(
698
+ newId,
699
+ setTimeout(() => {
700
+ indicatorWatchdogs.delete(newId);
701
+ get().setAiProcessing(newId, false);
702
+ get().setTyping(newId, false);
703
+ }, AI_INDICATOR_MAX_MS)
704
+ );
705
+ }
686
706
  set((state) => {
687
707
  const nextMessages = new Map(state.messages);
688
708
  const tempItems = nextMessages.get(oldId) ?? [];
@@ -765,6 +785,17 @@ function createWidgetStore() {
765
785
  });
766
786
  },
767
787
  setAiProcessing(conversationId, processing) {
788
+ clearWatchdog(conversationId);
789
+ if (processing) {
790
+ indicatorWatchdogs.set(
791
+ conversationId,
792
+ setTimeout(() => {
793
+ indicatorWatchdogs.delete(conversationId);
794
+ get().setAiProcessing(conversationId, false);
795
+ get().setTyping(conversationId, false);
796
+ }, AI_INDICATOR_MAX_MS)
797
+ );
798
+ }
768
799
  set((state) => {
769
800
  const next = new Map(state.aiProcessing);
770
801
  next.set(conversationId, processing);
@@ -789,6 +820,9 @@ function createWidgetStore() {
789
820
  */
790
821
  appendStreamChunk(conversationId, delta, done) {
791
822
  void done;
823
+ if (get().aiProcessing.get(conversationId)) {
824
+ get().setAiProcessing(conversationId, true);
825
+ }
792
826
  set((state) => {
793
827
  const next = new Map(state.streamingText);
794
828
  const prev = next.get(conversationId) ?? "";
@@ -2323,6 +2357,13 @@ function useConversations() {
2323
2357
  }
2324
2358
 
2325
2359
  // src/hooks/use-header-identity.ts
2360
+ function conversationIdentity(conv) {
2361
+ const teamSender = conv?.lastMessageSenderType === "team" && conv?.lastMessageSenderName ? conv : null;
2362
+ return {
2363
+ humanName: conv?.assigneeName ?? teamSender?.lastMessageSenderName ?? null,
2364
+ humanImage: conv?.assigneeImage ?? teamSender?.lastMessageSenderImage ?? null
2365
+ };
2366
+ }
2326
2367
  function useHeaderIdentity() {
2327
2368
  const activeConvSummary = useWidgetStore((s) => {
2328
2369
  const id = s.activeConversationId;
@@ -2330,9 +2371,7 @@ function useHeaderIdentity() {
2330
2371
  });
2331
2372
  const agentConfigName = useWidgetStore((s) => s.agentConfig?.name);
2332
2373
  const websiteName = useWidgetStore((s) => s.website?.name);
2333
- const teamSender = activeConvSummary?.lastMessageSenderType === "team" && activeConvSummary?.lastMessageSenderName ? activeConvSummary : null;
2334
- const humanName = activeConvSummary?.assigneeName ?? teamSender?.lastMessageSenderName ?? null;
2335
- const humanImage = activeConvSummary?.assigneeImage ?? teamSender?.lastMessageSenderImage ?? null;
2374
+ const { humanName, humanImage } = conversationIdentity(activeConvSummary);
2336
2375
  const companyName = agentConfigName ?? websiteName ?? "Support";
2337
2376
  return {
2338
2377
  humanName,
@@ -5860,7 +5899,7 @@ function DefaultWidget({
5860
5899
  },
5861
5900
  children: [
5862
5901
  /* @__PURE__ */ jsxs11("span", { className: "hw-header-menu-conv-top", children: [
5863
- /* @__PURE__ */ jsx16("span", { className: "hw-header-menu-conv-name", children: conv.assigneeName ?? (conv.lastMessageSenderType === "team" ? conv.lastMessageSenderName : null) ?? companyName }),
5902
+ /* @__PURE__ */ jsx16("span", { className: "hw-header-menu-conv-name", children: conversationIdentity(conv).humanName ?? companyName }),
5864
5903
  conv.lastMessageAt && /* @__PURE__ */ jsx16("span", { className: "hw-header-menu-conv-time", children: formatRelativeTime(conv.lastMessageAt) })
5865
5904
  ] }),
5866
5905
  /* @__PURE__ */ jsx16("span", { className: "hw-header-menu-conv-preview", children: conv.lastMessageText ?? t("widget.no_preview") })
@@ -6215,11 +6254,12 @@ function MessagesView({
6215
6254
  }
6216
6255
  function ConvCardBody({ conv }) {
6217
6256
  const agentName = useWidgetStore((s) => s.agentConfig?.name) ?? "Support";
6218
- const isTeam = conv.lastMessageSenderType === "team" && conv.lastMessageSenderName;
6219
- const displayName = isTeam ? conv.lastMessageSenderName : agentName;
6257
+ const { humanName, humanImage } = conversationIdentity(conv);
6258
+ const isTeam = !!humanName;
6259
+ const displayName = humanName ?? agentName;
6220
6260
  const preview = conv.lastMessageText ?? t("widget.no_preview");
6221
6261
  return /* @__PURE__ */ jsxs11(Fragment5, { children: [
6222
- /* @__PURE__ */ jsx16("div", { className: `hw-conv-card-avatar${isTeam ? " hw-conv-card-avatar--team" : ""}`, children: isTeam ? conv.lastMessageSenderImage ? /* @__PURE__ */ jsx16("img", { src: conv.lastMessageSenderImage, alt: displayName, className: "hw-conv-card-avatar-img" }) : /* @__PURE__ */ jsx16("span", { className: "hw-conv-card-avatar-initials", children: displayName.split(" ").map((w) => w[0]).join("").slice(0, 2).toUpperCase() }) : /* @__PURE__ */ jsx16(WidgetLogo, {}) }),
6262
+ /* @__PURE__ */ jsx16("div", { className: `hw-conv-card-avatar${isTeam ? " hw-conv-card-avatar--team" : ""}`, children: isTeam ? humanImage ? /* @__PURE__ */ jsx16("img", { src: humanImage, alt: displayName, className: "hw-conv-card-avatar-img" }) : /* @__PURE__ */ jsx16("span", { className: "hw-conv-card-avatar-initials", children: displayName.split(" ").map((w) => w[0]).join("").slice(0, 2).toUpperCase() }) : /* @__PURE__ */ jsx16(WidgetLogo, {}) }),
6223
6263
  /* @__PURE__ */ jsxs11("div", { className: "hw-conv-card-content", children: [
6224
6264
  /* @__PURE__ */ jsxs11("div", { className: "hw-conv-card-top", children: [
6225
6265
  /* @__PURE__ */ jsx16("span", { className: "hw-conv-card-name", children: displayName }),
@@ -6441,8 +6481,8 @@ function ConversationView({
6441
6481
  MessageList,
6442
6482
  {
6443
6483
  items,
6444
- isTyping,
6445
- isAiProcessing,
6484
+ isTyping: isTyping && !needsEmail,
6485
+ isAiProcessing: isAiProcessing && !needsEmail,
6446
6486
  streamingText: streamingText || void 0,
6447
6487
  hasMore,
6448
6488
  isLoadingMore: isLoading,