@webority/mobile-chat 0.162.0 → 0.164.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/ChatFrame.js +1 -1
- package/lib/commonjs/ChatSheet.js +1 -1
- package/lib/commonjs/ChatStarters.js +1 -1
- package/lib/commonjs/ChatThread.js +1 -1
- package/lib/module/ChatFrame.js +1 -1
- package/lib/module/ChatSheet.js +1 -1
- package/lib/module/ChatStarters.js +1 -1
- package/lib/module/ChatThread.js +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatFrame=ChatFrame;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatComposer=require("./ChatComposer.js"),_ChatConversationActions=require("./ChatConversationActions.js"),_ChatHistory=require("./ChatHistory.js"),_ChatLiveBar=require("./ChatLiveBar.js"),_ChatPanel=require("./ChatPanel.js"),_ChatStarters=require("./ChatStarters.js"),_ChatThread=require("./ChatThread.js"),_chatShared=require("./chatShared.js"),_useChatHaptics=require("./useChatHaptics.js"),_useChatSound=require("./useChatSound.js"),_jsxRuntime=require("react/jsx-runtime");const lastAgentName=e=>{for(let t=e.length-1;t>=0;t-=1){const a=e[t]?.author;if("Agent"===a?.kind&&a.displayName?.trim())return a.displayName}return null},headerStatusText=(e,t)=>"WaitingForAgent"===e.conversationState?t.statusWaitingForAgent:"WithAgent"===e.conversationState?t.statusWithAgent(lastAgentName(e.messages)??t.handoffAgentFallback):t.headerStatus;function ChatFrame({chat:e,labels:t,renderers:a,layoutParts:s,loader:r="Steps",look:i,pickAttachments:n,onOpenAttachment:o,onOpenTarget:l,onNavigate:u,openTicket:c,handoffHosts:h,resolveLink:m,keyboardOffset:d,layout:_,title:x,headerActions:C,onClose:j,enterKey:p=0,testID:b="chat-frame"}){const v=(0,_mobileUi.useTheme)(),g=(0,_react.useMemo)(()=>(0,_chatCore.mergeLook)(i),[i]),y=(0,_mobileUi.useReducedMotion)(),f="Reduced"===g.motion||y,R="embedded"===_?"None":g.panel.motion,A="sheet"===_?"sheet":"screen",I=(0,_react.useMemo)(()=>(0,_ChatPanel.panelRun)({motion:R,reduced:f,mode:A,run:p}),[R,f,A,p]),[S,k]=(0,_react.useState)(!1),w=S&&!0===e.features.History;(0,_useChatHaptics.useChatHaptics)(e),(0,_useChatSound.useChatSound)(e);const T="sheet"!==_,D=null!==e.profile,q=(0,_react.useRef)(null);if(D&&!e.features.VisitorChat)return null;const L=e.messages.length>0,N=e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind),P="screen"===_||N,H=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,B=x??e.profile?.assistant.name
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatFrame=ChatFrame;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatComposer=require("./ChatComposer.js"),_ChatConversationActions=require("./ChatConversationActions.js"),_ChatHistory=require("./ChatHistory.js"),_ChatLiveBar=require("./ChatLiveBar.js"),_ChatPanel=require("./ChatPanel.js"),_ChatStarters=require("./ChatStarters.js"),_ChatThread=require("./ChatThread.js"),_chatShared=require("./chatShared.js"),_useChatHaptics=require("./useChatHaptics.js"),_useChatSound=require("./useChatSound.js"),_jsxRuntime=require("react/jsx-runtime");const lastAgentName=e=>{for(let t=e.length-1;t>=0;t-=1){const a=e[t]?.author;if("Agent"===a?.kind&&a.displayName?.trim())return a.displayName}return null},headerStatusText=(e,t)=>"WaitingForAgent"===e.conversationState?t.statusWaitingForAgent:"WithAgent"===e.conversationState?t.statusWithAgent(lastAgentName(e.messages)??t.handoffAgentFallback):t.headerStatus;function ChatFrame({chat:e,labels:t,renderers:a,layoutParts:s,loader:r="Steps",look:i,pickAttachments:n,onOpenAttachment:o,onOpenTarget:l,onNavigate:u,openTicket:c,handoffHosts:h,resolveLink:m,keyboardOffset:d,layout:_,title:x,headerActions:C,onClose:j,enterKey:p=0,testID:b="chat-frame"}){const v=(0,_mobileUi.useTheme)(),g=(0,_react.useMemo)(()=>(0,_chatCore.mergeLook)(i),[i]),y=(0,_mobileUi.useReducedMotion)(),f="Reduced"===g.motion||y,R="embedded"===_?"None":g.panel.motion,A="sheet"===_?"sheet":"screen",I=(0,_react.useMemo)(()=>(0,_ChatPanel.panelRun)({motion:R,reduced:f,mode:A,run:p}),[R,f,A,p]),[S,k]=(0,_react.useState)(!1),w=S&&!0===e.features.History;(0,_useChatHaptics.useChatHaptics)(e),(0,_useChatSound.useChatSound)(e);const T="sheet"!==_,D=null!==e.profile,q=(0,_react.useRef)(null);if(D&&!e.features.VisitorChat)return null;const L=e.messages.length>0,N=e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind),P="screen"===_||N,H=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,B=x??(t.panelTitle||e.profile?.assistant.name||t.assistant),U=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:v.space.sm,paddingHorizontal:v.space.md,paddingVertical:v.space.sm,borderBottomWidth:1,borderBottomColor:v.colors["border-subtle"]},children:[g.avatar?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"sm",name:e.profile?.assistant.name||t.assistant,source:{uri:g.avatar}})}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1,minWidth:0},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"title",numberOfLines:1,..._chatShared.WEB_STRONG,children:B}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:headerStatusText(e,t)})]}),C,w?null:(0,_jsxRuntime.jsx)(_ChatConversationActions.ChatConversationActions,{chat:e,labels:t,testID:`${b}-conversation-actions`}),e.features.History?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:w?"arrow-left":"history",variant:"ghost",tone:"neutral",accessibilityLabel:w?t.backToChat:t.history,onPress:()=>k(e=>!e),testID:`${b}-history`}):null,H?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:e.muted?"volume-mute":"volume-high",variant:"ghost",tone:"neutral",accessibilityLabel:e.muted?t.unmuteSounds:t.muteSounds,onPress:()=>e.session.setMuted(!e.muted),testID:`${b}-mute`}):null,w||!P?null:(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"plus",variant:"ghost",tone:"neutral",accessibilityLabel:t.newChat,disabled:e.streaming||e.thinking,onPress:()=>e.newConversation(),testID:`${b}-new`}),j?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"x",variant:"ghost",tone:"neutral",accessibilityLabel:t.close,onPress:j,testID:`${b}-close`}):null]});let $;return $=w?(0,_jsxRuntime.jsx)(_ChatHistory.ChatHistory,{chat:e,labels:t,onOpen:()=>k(!1),testID:`${b}-history-list`}):e.profileError?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{tone:"danger",message:e.profileError.message,accessibilityRole:"alert",testID:`${b}-profile-error`}):!D||e.loading?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,alignItems:"center",justifyContent:"center"},children:(0,_jsxRuntime.jsx)(_mobileUi.Spinner,{message:t.loadingConversation,testID:`${b}-loading`})}):e.loadError?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{tone:"danger",message:e.loadError.message,accessibilityRole:"alert",testID:`${b}-load-error`}):L?(0,_jsxRuntime.jsx)(_ChatThread.ChatThread,{chat:e,labels:t,renderers:a,layoutParts:s,loader:r,motion:g.motion,avatar:g.avatar,replyAvatars:g.panel.replyAvatars,expressive:g.expressive,pickAttachments:n,onOpenAttachment:o,onOpenTarget:l,onNavigate:u,openTicket:c,handoffHosts:h,resolveLink:m,focusComposer:()=>q.current?.(),keyboardAware:T,keyboardOffset:d,style:{flex:1},testID:`${b}-thread`}):(0,_jsxRuntime.jsx)(_ChatStarters.ChatStarters,{chat:e,labels:t,openTicket:c,avatar:g.avatar,motion:g.motion,greetingLoaderMs:f?0:g.panel.greetingLoaderMs,testID:`${b}-starters`}),(0,_jsxRuntime.jsx)(_ChatPanel.ChatPanelGrow,{grow:I.grow,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1},role:"sheet"===_?"dialog":"region",accessibilityLabel:B,testID:b,children:[(0,_jsxRuntime.jsx)(_ChatPanel.ChatReveal,{plan:I.reveal.header,children:U}),(0,_jsxRuntime.jsx)(_ChatPanel.ChatReveal,{plan:I.reveal.body,flex:!0,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1},children:$})}),w?null:(0,_jsxRuntime.jsx)(_ChatLiveBar.ChatLiveBar,{chat:e,labels:t,testID:`${b}-live`}),w?null:(0,_jsxRuntime.jsx)(_ChatPanel.ChatReveal,{plan:I.reveal.composer,children:(0,_jsxRuntime.jsx)(_ChatComposer.ChatComposer,{chat:e,labels:t,look:g,sendIcon:i?.input?.sendIcon,pickAttachments:n,keyboardOffset:d,keyboardAware:T,focusRef:q,testID:`${b}-composer`})})]})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatSheet=ChatSheet;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatAppearanceScope=require("./ChatAppearanceScope.js"),_ChatFrame=require("./ChatFrame.js"),_ChatLauncher=require("./ChatLauncher.js"),_ChatNudge=require("./ChatNudge.js"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;function ChatSheet({chat:e,labels:t,renderers:r,layoutParts:a,loader:s="Steps",look:n,appearance:o,pickAttachments:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatSheet=ChatSheet;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatAppearanceScope=require("./ChatAppearanceScope.js"),_ChatFrame=require("./ChatFrame.js"),_ChatLauncher=require("./ChatLauncher.js"),_ChatNudge=require("./ChatNudge.js"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;function ChatSheet({chat:e,labels:t,renderers:r,layoutParts:a,loader:s="Steps",look:n,appearance:o,pickAttachments:i,onOpenAttachment:c,onOpenTarget:u,onNavigate:l,keyboardOffset:h,open:p,defaultOpen:f=!1,onOpenChange:_,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:m,handoffHosts:b,resolveLink:C,conversationId:g,onClose:j,testID:x="chat-sheet"}){const S=(0,_mobileUi.useTheme)(),v=(0,_chatCore.mergeLabels)(t),T=(0,_react.useMemo)(()=>(0,_chatCore.mergeLook)(n),[n]),O=(0,_mobileUi.useReducedMotion)(),k="Reduced"===T.motion||O,R=o?.position??"end",y=void 0!==p,A=y?p:e.open,N=(0,_react.useRef)(null),E=(0,_react.useRef)(!1),F=(0,_react.useRef)(g??null),L=e.setChatVisible,P=(0,_react.useRef)(!1),q=!P.current,[D,I]=(0,_react.useState)(0),U=(0,_react.useRef)(A);(0,_react.useEffect)(()=>{A&&(P.current=!0)},[A]),(0,_react.useEffect)(()=>{A&&!U.current&&I(e=>e+1),U.current=A},[A]),(0,_react.useEffect)(()=>{E.current||(E.current=!0,y||!f||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[y,f,e.profile,e.open,e.session]),(0,_react.useEffect)(()=>{y&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[y,p,e.open,e.session]);const w=(0,_react.useRef)(A);if((0,_react.useEffect)(()=>{w.current&&!A&&(0,_chatShared.focusForAccessibility)(N.current),w.current=A},[A]),(0,_react.useEffect)(()=>{L(A)},[L,A]),(0,_react.useEffect)(()=>{!y&&g&&g!==F.current&&null!==e.profile&&(F.current=g,e.open||(e.session.open({trigger:"manual"}),_?.(!0)))},[y,g,e.profile,e.open,e.session,_]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),_?.(t)},closeSheet=()=>{setOpen(!1),j?.()},M=o?.offsetY??DEFAULT_BOTTOM_OFFSET;return(0,_jsxRuntime.jsx)(_reactNative.View,{testID:x,style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",children:(0,_jsxRuntime.jsxs)(_ChatAppearanceScope.ChatAppearanceScope,{appearance:o,children:[(0,_jsxRuntime.jsx)(_ChatLauncher.ChatLauncher,{look:T,hidden:A,label:e.profile?.experience.launcher?.hoverLabel||v.launcher,side:R,offsetX:o?.offsetX??0,offsetY:M,enter:q,reduced:k,mark:T.launcher.mark,avatar:T.avatar,buttonRef:N,onPress:()=>setOpen(!0),testID:`${x}-launcher`}),(0,_jsxRuntime.jsx)(_ChatNudge.ChatNudge,{chat:e,labels:v,enabled:!A&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:M,position:R,testID:`${x}-nudge`}),(0,_jsxRuntime.jsx)(_mobileUi.BottomSheet,{open:A,onClose:closeSheet,...void 0===d?{}:{snapPoints:d},keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:v.panelTitle||e.profile?.assistant.name||v.assistant,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,backgroundColor:S.colors.bg},children:(0,_jsxRuntime.jsx)(_ChatFrame.ChatFrame,{chat:e,labels:v,renderers:r,layoutParts:a,loader:s,look:n,pickAttachments:i,onOpenAttachment:c,onOpenTarget:u,onNavigate:l,openTicket:m,handoffHosts:b,resolveLink:C,keyboardOffset:h,onClose:closeSheet,layout:"sheet",enterKey:D,testID:`${x}-frame`})})})]})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatStarters=ChatStarters;var _mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatEntrance=require("./ChatEntrance.js"),_ChatOpenTickets=require("./ChatOpenTickets.js"),_ChatPastChats=require("./ChatPastChats.js"),_iconName=require("./iconName.js"),_TypingPill=require("./loaders/TypingPill.js"),_chipLook=require("./renderers/chipLook.js"),_jsxRuntime=require("react/jsx-runtime");function ChatStarters({chat:e,labels:t,openTicket:i,avatar:s,motion:a="On",greetingLoaderMs:r=0,testID:n="chat-starters"}){const l=(0,_mobileUi.useTheme)(),[c,o]=(0,_react.useState)(!(r>0));(0,_react.useEffect)(()=>{if(c)return;const e=setTimeout(()=>o(!0),r);return()=>clearTimeout(e)},[c,r]);const u=e.profile,m=e.greeting??"";if(!u)return null;const _=u.assistant.intro,x=e.features.Starters&&e.starters.length>0,j=e.lastConversation,h=e.features.ResumeLast&&!e.features.History&&null!==j;return(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:l.space.md,padding:l.space.md},testID:n,children:c?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[s?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"lg",name:e.profile?.assistant.name
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatStarters=ChatStarters;var _mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatEntrance=require("./ChatEntrance.js"),_ChatOpenTickets=require("./ChatOpenTickets.js"),_ChatPastChats=require("./ChatPastChats.js"),_iconName=require("./iconName.js"),_TypingPill=require("./loaders/TypingPill.js"),_chipLook=require("./renderers/chipLook.js"),_jsxRuntime=require("react/jsx-runtime");function ChatStarters({chat:e,labels:t,openTicket:i,avatar:s,motion:a="On",greetingLoaderMs:r=0,testID:n="chat-starters"}){const l=(0,_mobileUi.useTheme)(),[c,o]=(0,_react.useState)(!(r>0));(0,_react.useEffect)(()=>{if(c)return;const e=setTimeout(()=>o(!0),r);return()=>clearTimeout(e)},[c,r]);const u=e.profile,m=e.greeting??"";if(!u)return null;const _=u.assistant.intro,x=e.features.Starters&&e.starters.length>0,j=e.lastConversation,h=e.features.ResumeLast&&!e.features.History&&null!==j;return(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:l.space.md,padding:l.space.md},testID:n,children:c?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[s?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"lg",name:e.profile?.assistant.name||t.assistant,source:{uri:s}})}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"h2",align:"center",children:m}),_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",color:"secondary",align:"center",children:_}):null,x?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"none",accessibilityLabel:t.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:l.space.xs},children:e.starters.map((t,i)=>{const s=(0,_iconName.iconNameOf)(t.icon);return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{...t.variant?(0,_chipLook.chipLook)(t.variant):null,label:t.label,...null===s?{}:{leftIcon:s},onPress:()=>{e.submit(t.message)},testID:`${n}-${t.id}`})},t.id)})}):null,h&&j?(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",onPress:()=>{e.resumeLast()},testID:`${n}-resume`,children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:t.resumeLast}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",numberOfLines:1,children:j.title||t.untitled}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_mobileCore.formatDate)(j.lastActivityDateTimeUtc)})]}):null,e.features.History?(0,_jsxRuntime.jsx)(_ChatPastChats.ChatPastChats,{chat:e,labels:t,testID:`${n}-past-chats`}):null,(0,_jsxRuntime.jsx)(_ChatOpenTickets.ChatOpenTickets,{chat:e,labels:t,onOpenTicket:i})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{children:(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:a,mark:s?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name||t.assistant,source:{uri:s}}):null})})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatThread=ChatThread;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_AgentByline=require("./AgentByline.js"),_ChatEntrance=require("./ChatEntrance.js"),_ChatMessageActions=require("./ChatMessageActions.js"),_chatShared=require("./chatShared.js"),_ChatLoader=require("./loaders/ChatLoader.js"),_ReplyRing=require("./loaders/ReplyRing.js"),_TypingPill=require("./loaders/TypingPill.js"),_index=require("./renderers/index.js"),_jsxRuntime=require("react/jsx-runtime");const MINE=new Set(["Visitor","Customer"]),visuallyHidden={position:"absolute",left:-1e4,width:1,height:1,overflow:"hidden"},spokenAuthor=(e,t,s)=>MINE.has(e.author.kind)?t.you:e.author.displayName?e.author.displayName:"Agent"===e.author.kind?t.agent:s??t.assistant,joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n");function isKind(e,t){return e.kind===t}const kindWrappers=new WeakMap;function forKind(e,t){const s=kindWrappers.get(t)??new Map,a=s.get(e);if(a)return a;function KindEntry(s){if(!isKind(s.part,e))throw new Error(`renderer for ${e} received a ${s.part.kind} part`);return(0,_react.createElement)(t,{part:s.part,message:s.message,turn:s.turn,pickAttachments:s.pickAttachments})}return s.set(e,KindEntry),kindWrappers.set(t,s),KindEntry}const defaults=_index.defaultRenderers;function entryFor(e,t){return forKind(e,t??defaults[e])}function resolveRenderers(e){return{Text:entryFor("Text",e?.Text),Sources:entryFor("Sources",e?.Sources),QuickReplies:entryFor("QuickReplies",e?.QuickReplies),InputRequest:entryFor("InputRequest",e?.InputRequest),Action:entryFor("Action",e?.Action),Notice:entryFor("Notice",e?.Notice),Table:entryFor("Table",e?.Table),Chart:entryFor("Chart",e?.Chart),Figures:entryFor("Figures",e?.Figures),RecordCard:entryFor("RecordCard",e?.RecordCard),Image:entryFor("Image",e?.Image),File:entryFor("File",e?.File),Ticket:entryFor("Ticket",e?.Ticket),Handoff:entryFor("Handoff",e?.Handoff),VoiceClip:entryFor("VoiceClip",e?.VoiceClip)}}const renderPart=(e,t,s,a,i,r)=>{const n=e[t.kind];return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:a,pickAttachments:i})},sameMessage=(e,t)=>e.signature===t.signature&&e.message.id===t.message.id&&e.message.rating===t.message.rating&&e.message.stored===t.message.stored&&e.groupPosition===t.groupPosition&&e.isLast===t.isLast&&e.handoffSettled===t.handoffSettled&&e.isLastVisitor===t.isLastVisitor&&e.thinking===t.thinking&&e.streaming===t.streaming&&e.pickAttachments===t.pickAttachments&&e.labels===t.labels&&e.all===t.all&&e.layoutParts===t.layoutParts&&e.chat.session===t.chat.session&&e.chat.features===t.chat.features&&e.chat.onNavigate===t.chat.onNavigate&&e.onNavigate===t.onNavigate&&e.onOpenAttachment===t.onOpenAttachment&&e.onOpenTarget===t.onOpenTarget&&e.openTicket===t.openTicket&&e.resolveLink===t.resolveLink&&e.focusComposer===t.focusComposer&&e.byline===t.byline&&e.avatar===t.avatar&&e.replyAvatars===t.replyAvatars&&e.avatarStart===t.avatarStart&&e.expressive===t.expressive&&e.reduced===t.reduced&&e.handoffHosts===t.handoffHosts;function ThreadMessageView({chat:e,message:t,labels:s,all:a,layoutParts:i,groupPosition:r,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:c,onOpenTarget:d,onNavigate:u,openTicket:m,handoffHosts:g,resolveLink:p,focusComposer:h,byline:y,avatar:_,replyAvatars:x,avatarStart:f,expressive:v,reduced:j,sourceRows:R,testID:T}){const k=(0,_mobileUi.useTheme)(),b=Object.assign((0,_chatCore.createTurnApi)(e.session,{messageId:t.id,labels:s,openAttachment:c,openTarget:d??_chatShared.defaultOpenTarget,onNavigate:u??e.onNavigate,openTicket:m,handoffHosts:g,openCitation:e=>{return t=String(e),void(0,_chatShared.focusForAccessibility)(R.current.get(t));var t}}),{resolveLink:p,focusComposer:h,registerSourceRow:(e,t)=>{t?R.current.set(e,t):R.current.delete(e)}});let A=0;const nextSlot=()=>(A+=1,A),N=(0,_jsxRuntime.jsx)(_ChatMessageActions.ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${T}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind||"VoiceClip"===e.kind),s=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:k.space.xs},children:[e.map(e=>renderPart(a,e,t,b,l,`${t.id}-file-${nextSlot()}`)),N]});return(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:r,footer:s,testID:T})}const w="Agent"===t.author.kind,C=t.author.displayName||s.agent,M=(i?i(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:k.space.xs},children:e.map(e=>renderPart(a,e,t,b,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,b,l,`${t.id}-item-${nextSlot()}`)),S=w&&y?(0,_jsxRuntime.jsx)(_AgentByline.AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=S?[S,...M]:M,P=(0,_chatCore.messagePlainText)(t.parts),V=(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"theirs",...w?{}:{author:`${t.author.displayName||(e.profile?.assistant.name??s.assistant)}:`},text:w?`${s.agentSays(C)} ${P}`:P,streaming:t.streaming,groupPosition:r,footer:N,testID:T,children:I});if(!x||!_||"Assistant"!==t.author.kind)return V;const F=t.author.displayName||(e.profile?.assistant.name??s.assistant);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"flex-end",gap:k.space.xs},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:f?void 0:{opacity:0},children:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:v&&t.streaming&&f,reduced:j,children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:F,...f?{source:{uri:_}}:{}})})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,minWidth:0},children:V})]})}const ThreadMessage=(0,_react.memo)(ThreadMessageView,sameMessage),TYPING_ORB_MARK=14,TYPING_ASSISTANT_MARK=8,TypingMark=({size:e})=>{const t=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:e,height:e,borderRadius:t.radius.pill,backgroundColor:t.colors.primary}})},TYPING_DOT=6,TypingDots=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},children:[0,1,2].map(t=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:6,height:6,borderRadius:3,backgroundColor:e.colors["text-muted"]}},t))})},TurnGap=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:e.space.lg}})},followNew=()=>!0;function ChatThread({chat:e,labels:t,renderers:s,layoutParts:a,loader:i="Steps",motion:r="On",avatar:n,replyAvatars:o="First",expressive:l=!1,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,keyboardAware:_,keyboardOffset:x,empty:f,style:v,testID:j="chat-thread"}){const R=(0,_mobileUi.useTheme)(),T=(0,_mobileUi.useReducedMotion)(),k="Reduced"===r||T,b=(0,_react.useMemo)(()=>resolveRenderers(s),[s]),A=e.messages[0],N=e.greeting??"",w=(0,_react.useMemo)(()=>""!==N&&void 0!==A&&MINE.has(A.author.kind)?{...A,id:"greeting",author:{...A.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:N}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[N,A]),C=(0,_react.useMemo)(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return w?[...t,w]:t},[e.messages,w]),M=e.messages[e.messages.length-1]?.id,S=(0,_react.useRef)(new Map),I=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(null!==I.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||I.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;I.current.add(s.id);const e=(0,_chatCore.messagePlainText)(s.parts);""!==e&&_reactNative.AccessibilityInfo.announceForAccessibility("Agent"===s.author.kind?`${t.agentSays(s.author.displayName||t.agent)} ${e}`:e)}else I.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const P=(0,_react.useMemo)(()=>{for(let t=e.messages.length-1;t>=0;t-=1){const s=e.messages[t];if(s?.stored&&"Visitor"===s.author.kind)return s.id}},[e.messages]),V=(0,_react.useMemo)(()=>{const t=new Set;return e.messages.forEach((s,a)=>{if("Agent"!==s.author.kind)return;const i=e.messages[a-1];"Agent"===i?.author.kind&&(i.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),F=(0,_react.useMemo)(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return w&&t.add(w.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,w]),L=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),$=e.turnError,E="daily_limit"===$?.code,O=null!==$&&/feature_off$/.test($.code),D=E&&$?.resetsDateTimeUtc?` ${t.dailyLimitRefresh((0,_chatCore.formatChatDateTime)($.resetsDateTimeUtc))}`:"",U=e.streaming||null===$&&!e.stopped?null:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs},testID:`${j}-error`,children:[null!==$?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityRole:E?void 0:"alert",accessibilityLiveRegion:E?"polite":void 0,children:`${$.message}${D}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||E||O?null:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${j}-retry`})})]}),q=e.thinking&&null!==e.profile?(0,_jsxRuntime.jsx)(_ChatLoader.ChatLoader,{style:i,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:r}):null,H=!0===e.pending?.typing?(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:l,reduced:k,children:n?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:n}}):(0,_jsxRuntime.jsx)(TypingMark,{size:"Orb"===i?TYPING_ORB_MARK:TYPING_ASSISTANT_MARK})})}):null,K=null!==e.agentTyping&&"WithAgent"===e.conversationState?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs,alignSelf:"flex-start"},children:[(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(TypingDots,{})}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,B=H||q||U||K?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.sm},children:[H,q,K,U]}):void 0,G=(0,_jsxRuntime.jsx)(_mobileUi.MessageList,{messages:C,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:i})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"listitem",children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{style:visuallyHidden,children:`${spokenAuthor(s,t,e.profile?.assistant.name)}: `}),(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{animate:!s.restored,children:(0,_jsxRuntime.jsx)(ThreadMessage,{chat:e,message:s,signature:(0,_chatShared.messageSignature)(s),labels:t,all:b,layoutParts:a,groupPosition:i,isLast:s.id===M,isLastVisitor:s.id===P,handoffSettled:L.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,byline:V.has(s.id),avatar:n,replyAvatars:"None"!==o,avatarStart:"Every"===o||F.has(s.id),expressive:l,reduced:k,sourceRows:S,testID:`${j}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:B,empty:f,ItemSeparatorComponent:TurnGap,...void 0===_?{}:{keyboardAware:_},...void 0===x?{}:{keyboardOffset:x},..."web"===_reactNative.Platform.OS?{}:{accessibilityLabel:t.thread},accessibilityRole:"list",style:v,testID:j});return"web"!==_reactNative.Platform.OS?G:(0,_jsxRuntime.jsx)(_reactNative.View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:G})}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatThread=ChatThread;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_AgentByline=require("./AgentByline.js"),_ChatEntrance=require("./ChatEntrance.js"),_ChatMessageActions=require("./ChatMessageActions.js"),_chatShared=require("./chatShared.js"),_ChatLoader=require("./loaders/ChatLoader.js"),_ReplyRing=require("./loaders/ReplyRing.js"),_TypingPill=require("./loaders/TypingPill.js"),_index=require("./renderers/index.js"),_jsxRuntime=require("react/jsx-runtime");const MINE=new Set(["Visitor","Customer"]),visuallyHidden={position:"absolute",left:-1e4,width:1,height:1,overflow:"hidden"},spokenAuthor=(e,t,s)=>MINE.has(e.author.kind)?t.you:e.author.displayName?e.author.displayName:"Agent"===e.author.kind?t.agent:s??t.assistant,joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n");function isKind(e,t){return e.kind===t}const kindWrappers=new WeakMap;function forKind(e,t){const s=kindWrappers.get(t)??new Map,a=s.get(e);if(a)return a;function KindEntry(s){if(!isKind(s.part,e))throw new Error(`renderer for ${e} received a ${s.part.kind} part`);return(0,_react.createElement)(t,{part:s.part,message:s.message,turn:s.turn,pickAttachments:s.pickAttachments})}return s.set(e,KindEntry),kindWrappers.set(t,s),KindEntry}const defaults=_index.defaultRenderers;function entryFor(e,t){return forKind(e,t??defaults[e])}function resolveRenderers(e){return{Text:entryFor("Text",e?.Text),Sources:entryFor("Sources",e?.Sources),QuickReplies:entryFor("QuickReplies",e?.QuickReplies),InputRequest:entryFor("InputRequest",e?.InputRequest),Action:entryFor("Action",e?.Action),Notice:entryFor("Notice",e?.Notice),Table:entryFor("Table",e?.Table),Chart:entryFor("Chart",e?.Chart),Figures:entryFor("Figures",e?.Figures),RecordCard:entryFor("RecordCard",e?.RecordCard),Image:entryFor("Image",e?.Image),File:entryFor("File",e?.File),Ticket:entryFor("Ticket",e?.Ticket),Handoff:entryFor("Handoff",e?.Handoff),VoiceClip:entryFor("VoiceClip",e?.VoiceClip)}}const renderPart=(e,t,s,a,i,r)=>{const n=e[t.kind];return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:a,pickAttachments:i})},sameMessage=(e,t)=>e.signature===t.signature&&e.message.id===t.message.id&&e.message.rating===t.message.rating&&e.message.stored===t.message.stored&&e.groupPosition===t.groupPosition&&e.isLast===t.isLast&&e.handoffSettled===t.handoffSettled&&e.isLastVisitor===t.isLastVisitor&&e.thinking===t.thinking&&e.streaming===t.streaming&&e.pickAttachments===t.pickAttachments&&e.labels===t.labels&&e.all===t.all&&e.layoutParts===t.layoutParts&&e.chat.session===t.chat.session&&e.chat.features===t.chat.features&&e.chat.onNavigate===t.chat.onNavigate&&e.onNavigate===t.onNavigate&&e.onOpenAttachment===t.onOpenAttachment&&e.onOpenTarget===t.onOpenTarget&&e.openTicket===t.openTicket&&e.resolveLink===t.resolveLink&&e.focusComposer===t.focusComposer&&e.byline===t.byline&&e.avatar===t.avatar&&e.replyAvatars===t.replyAvatars&&e.avatarStart===t.avatarStart&&e.expressive===t.expressive&&e.reduced===t.reduced&&e.handoffHosts===t.handoffHosts;function ThreadMessageView({chat:e,message:t,labels:s,all:a,layoutParts:i,groupPosition:r,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:c,onOpenTarget:d,onNavigate:u,openTicket:m,handoffHosts:g,resolveLink:p,focusComposer:h,byline:y,avatar:_,replyAvatars:x,avatarStart:f,expressive:v,reduced:j,sourceRows:R,testID:k}){const T=(0,_mobileUi.useTheme)(),b=Object.assign((0,_chatCore.createTurnApi)(e.session,{messageId:t.id,labels:s,openAttachment:c,openTarget:d??_chatShared.defaultOpenTarget,onNavigate:u??e.onNavigate,openTicket:m,handoffHosts:g,openCitation:e=>{return t=String(e),void(0,_chatShared.focusForAccessibility)(R.current.get(t));var t}}),{resolveLink:p,focusComposer:h,registerSourceRow:(e,t)=>{t?R.current.set(e,t):R.current.delete(e)}});let A=0;const nextSlot=()=>(A+=1,A),N=(0,_jsxRuntime.jsx)(_ChatMessageActions.ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${k}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind||"VoiceClip"===e.kind),s=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:T.space.xs},children:[e.map(e=>renderPart(a,e,t,b,l,`${t.id}-file-${nextSlot()}`)),N]});return(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:r,footer:s,testID:k})}const w="Agent"===t.author.kind,C=t.author.displayName||s.agent,M=(i?i(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:T.space.xs},children:e.map(e=>renderPart(a,e,t,b,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,b,l,`${t.id}-item-${nextSlot()}`)),S=w&&y?(0,_jsxRuntime.jsx)(_AgentByline.AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=S?[S,...M]:M,P=(0,_chatCore.messagePlainText)(t.parts),V=(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"theirs",...w?{}:{author:`${t.author.displayName||(e.profile?.assistant.name??s.assistant)}:`},text:w?`${s.agentSays(C)} ${P}`:P,streaming:t.streaming,groupPosition:r,footer:N,testID:k,children:I});if(!x||!_||"Assistant"!==t.author.kind)return V;const F=t.author.displayName||(e.profile?.assistant.name??s.assistant);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"flex-end",gap:T.space.xs},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:f?void 0:{opacity:0},children:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:v&&t.streaming&&f,reduced:j,children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:F,...f?{source:{uri:_}}:{}})})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,minWidth:0},children:V})]})}const ThreadMessage=(0,_react.memo)(ThreadMessageView,sameMessage),TYPING_ORB_MARK=14,TYPING_ASSISTANT_MARK=8,TypingMark=({size:e})=>{const t=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:e,height:e,borderRadius:t.radius.pill,backgroundColor:t.colors.primary}})},TYPING_DOT=6,TypingDots=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},children:[0,1,2].map(t=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:6,height:6,borderRadius:3,backgroundColor:e.colors["text-muted"]}},t))})},TurnGap=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:e.space.lg}})},followNew=()=>!0;function ChatThread({chat:e,labels:t,renderers:s,layoutParts:a,loader:i="Steps",motion:r="On",avatar:n,replyAvatars:o="First",expressive:l=!1,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,keyboardAware:_,keyboardOffset:x,empty:f,style:v,testID:j="chat-thread"}){const R=(0,_mobileUi.useTheme)(),k=(0,_mobileUi.useReducedMotion)(),T="Reduced"===r||k,b=(0,_react.useMemo)(()=>resolveRenderers(s),[s]),A=e.messages[0],N=e.greeting??"",w=(0,_react.useMemo)(()=>""!==N&&void 0!==A&&MINE.has(A.author.kind)?{...A,id:"greeting",author:{...A.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:N}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[N,A]),C=(0,_react.useMemo)(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return w?[...t,w]:t},[e.messages,w]),M=e.messages[e.messages.length-1]?.id,S=(0,_react.useRef)(new Map),I=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(null!==I.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||I.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;I.current.add(s.id);const e=(0,_chatCore.messagePlainText)(s.parts);""!==e&&_reactNative.AccessibilityInfo.announceForAccessibility("Agent"===s.author.kind?`${t.agentSays(s.author.displayName||t.agent)} ${e}`:e)}else I.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const P=(0,_react.useMemo)(()=>{for(let t=e.messages.length-1;t>=0;t-=1){const s=e.messages[t];if(s?.stored&&"Visitor"===s.author.kind)return s.id}},[e.messages]),V=(0,_react.useMemo)(()=>{const t=new Set;return e.messages.forEach((s,a)=>{if("Agent"!==s.author.kind)return;const i=e.messages[a-1];"Agent"===i?.author.kind&&(i.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),F=(0,_react.useMemo)(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return w&&t.add(w.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,w]),L=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),$=e.turnError,E="daily_limit"===$?.code,O=null!==$&&/feature_off$/.test($.code),D=E&&$?.resetsDateTimeUtc?` ${t.dailyLimitRefresh((0,_chatCore.formatChatDateTime)($.resetsDateTimeUtc))}`:"",U=e.streaming||null===$&&!e.stopped?null:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs},testID:`${j}-error`,children:[null!==$?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityRole:E?void 0:"alert",accessibilityLiveRegion:E?"polite":void 0,children:`${$.message}${D}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||E||O?null:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${j}-retry`})})]}),q=e.thinking&&null!==e.profile?(0,_jsxRuntime.jsx)(_ChatLoader.ChatLoader,{style:i,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:r}):null,H=!0===e.pending?.typing?(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:l,reduced:T,children:n?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name||t.assistant,source:{uri:n}}):(0,_jsxRuntime.jsx)(TypingMark,{size:"Orb"===i?TYPING_ORB_MARK:TYPING_ASSISTANT_MARK})})}):null,K=null!==e.agentTyping&&"WithAgent"===e.conversationState?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs,alignSelf:"flex-start"},children:[(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(TypingDots,{})}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,B=H||q||U||K?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.sm},children:[H,q,K,U]}):void 0,G=(0,_jsxRuntime.jsx)(_mobileUi.MessageList,{messages:C,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:i})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"listitem",children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{style:visuallyHidden,children:`${spokenAuthor(s,t,e.profile?.assistant.name)}: `}),(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{animate:!s.restored,children:(0,_jsxRuntime.jsx)(ThreadMessage,{chat:e,message:s,signature:(0,_chatShared.messageSignature)(s),labels:t,all:b,layoutParts:a,groupPosition:i,isLast:s.id===M,isLastVisitor:s.id===P,handoffSettled:L.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,byline:V.has(s.id),avatar:n,replyAvatars:"None"!==o,avatarStart:"Every"===o||F.has(s.id),expressive:l,reduced:T,sourceRows:S,testID:`${j}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:B,empty:f,ItemSeparatorComponent:TurnGap,...void 0===_?{}:{keyboardAware:_},...void 0===x?{}:{keyboardOffset:x},..."web"===_reactNative.Platform.OS?{}:{accessibilityLabel:t.thread},accessibilityRole:"list",style:v,testID:j});return"web"!==_reactNative.Platform.OS?G:(0,_jsxRuntime.jsx)(_reactNative.View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:G})}
|
package/lib/module/ChatFrame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{mergeLook}from"@webority/chat-core";import{Avatar,Banner,IconButton,Spinner,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useMemo,useRef,useState}from"react";import{View}from"react-native";import{ChatComposer}from"./ChatComposer.js";import{ChatConversationActions}from"./ChatConversationActions.js";import{ChatHistory}from"./ChatHistory.js";import{ChatLiveBar}from"./ChatLiveBar.js";import{ChatPanelGrow,ChatReveal,panelRun}from"./ChatPanel.js";import{ChatStarters}from"./ChatStarters.js";import{ChatThread}from"./ChatThread.js";import{WEB_STRONG}from"./chatShared.js";import{useChatHaptics}from"./useChatHaptics.js";import{useChatSound}from"./useChatSound.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const lastAgentName=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t]?.author;if("Agent"===s?.kind&&s.displayName?.trim())return s.displayName}return null},headerStatusText=(e,t)=>"WaitingForAgent"===e.conversationState?t.statusWaitingForAgent:"WithAgent"===e.conversationState?t.statusWithAgent(lastAgentName(e.messages)??t.handoffAgentFallback):t.headerStatus;export function ChatFrame({chat:e,labels:t,renderers:s,layoutParts:a,loader:o="Steps",look:r,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:h,handoffHosts:m,resolveLink:u,keyboardOffset:d,layout:p,title:f,headerActions:g,onClose:C,enterKey:x=0,testID:v="chat-frame"}){const j=useTheme(),y=useMemo(()=>mergeLook(r),[r]),b=useReducedMotion(),_="Reduced"===y.motion||b,A="embedded"===p?"None":y.panel.motion,I="sheet"===p?"sheet":"screen",k=useMemo(()=>panelRun({motion:A,reduced:_,mode:I,run:x}),[A,_,I,x]),[S,w]=useState(!1),T=S&&!0===e.features.History;useChatHaptics(e),useChatSound(e);const D="sheet"!==p,R=null!==e.profile,B=useRef(null);if(R&&!e.features.VisitorChat)return null;const L=e.messages.length>0,$=e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind),H="screen"===p||$,O=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,V=f??e.profile?.assistant.name
|
|
1
|
+
"use strict";import{mergeLook}from"@webority/chat-core";import{Avatar,Banner,IconButton,Spinner,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useMemo,useRef,useState}from"react";import{View}from"react-native";import{ChatComposer}from"./ChatComposer.js";import{ChatConversationActions}from"./ChatConversationActions.js";import{ChatHistory}from"./ChatHistory.js";import{ChatLiveBar}from"./ChatLiveBar.js";import{ChatPanelGrow,ChatReveal,panelRun}from"./ChatPanel.js";import{ChatStarters}from"./ChatStarters.js";import{ChatThread}from"./ChatThread.js";import{WEB_STRONG}from"./chatShared.js";import{useChatHaptics}from"./useChatHaptics.js";import{useChatSound}from"./useChatSound.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const lastAgentName=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t]?.author;if("Agent"===s?.kind&&s.displayName?.trim())return s.displayName}return null},headerStatusText=(e,t)=>"WaitingForAgent"===e.conversationState?t.statusWaitingForAgent:"WithAgent"===e.conversationState?t.statusWithAgent(lastAgentName(e.messages)??t.handoffAgentFallback):t.headerStatus;export function ChatFrame({chat:e,labels:t,renderers:s,layoutParts:a,loader:o="Steps",look:r,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:h,handoffHosts:m,resolveLink:u,keyboardOffset:d,layout:p,title:f,headerActions:g,onClose:C,enterKey:x=0,testID:v="chat-frame"}){const j=useTheme(),y=useMemo(()=>mergeLook(r),[r]),b=useReducedMotion(),_="Reduced"===y.motion||b,A="embedded"===p?"None":y.panel.motion,I="sheet"===p?"sheet":"screen",k=useMemo(()=>panelRun({motion:A,reduced:_,mode:I,run:x}),[A,_,I,x]),[S,w]=useState(!1),T=S&&!0===e.features.History;useChatHaptics(e),useChatSound(e);const D="sheet"!==p,R=null!==e.profile,B=useRef(null);if(R&&!e.features.VisitorChat)return null;const L=e.messages.length>0,$=e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind),H="screen"===p||$,O=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,V=f??(t.panelTitle||e.profile?.assistant.name||t.assistant),N=_jsxs(View,{style:{flexDirection:"row",alignItems:"center",gap:j.space.sm,paddingHorizontal:j.space.md,paddingVertical:j.space.sm,borderBottomWidth:1,borderBottomColor:j.colors["border-subtle"]},children:[y.avatar?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(Avatar,{size:"sm",name:e.profile?.assistant.name||t.assistant,source:{uri:y.avatar}})}):null,_jsxs(View,{style:{flex:1,minWidth:0},children:[_jsx(Text,{variant:"title",numberOfLines:1,...WEB_STRONG,children:V}),_jsx(Text,{variant:"caption",color:"secondary",children:headerStatusText(e,t)})]}),g,T?null:_jsx(ChatConversationActions,{chat:e,labels:t,testID:`${v}-conversation-actions`}),e.features.History?_jsx(IconButton,{icon:T?"arrow-left":"history",variant:"ghost",tone:"neutral",accessibilityLabel:T?t.backToChat:t.history,onPress:()=>w(e=>!e),testID:`${v}-history`}):null,O?_jsx(IconButton,{icon:e.muted?"volume-mute":"volume-high",variant:"ghost",tone:"neutral",accessibilityLabel:e.muted?t.unmuteSounds:t.muteSounds,onPress:()=>e.session.setMuted(!e.muted),testID:`${v}-mute`}):null,T||!H?null:_jsx(IconButton,{icon:"plus",variant:"ghost",tone:"neutral",accessibilityLabel:t.newChat,disabled:e.streaming||e.thinking,onPress:()=>e.newConversation(),testID:`${v}-new`}),C?_jsx(IconButton,{icon:"x",variant:"ghost",tone:"neutral",accessibilityLabel:t.close,onPress:C,testID:`${v}-close`}):null]});let P;return P=T?_jsx(ChatHistory,{chat:e,labels:t,onOpen:()=>w(!1),testID:`${v}-history-list`}):e.profileError?_jsx(Banner,{tone:"danger",message:e.profileError.message,accessibilityRole:"alert",testID:`${v}-profile-error`}):!R||e.loading?_jsx(View,{style:{flex:1,alignItems:"center",justifyContent:"center"},children:_jsx(Spinner,{message:t.loadingConversation,testID:`${v}-loading`})}):e.loadError?_jsx(Banner,{tone:"danger",message:e.loadError.message,accessibilityRole:"alert",testID:`${v}-load-error`}):L?_jsx(ChatThread,{chat:e,labels:t,renderers:s,layoutParts:a,loader:o,motion:y.motion,avatar:y.avatar,replyAvatars:y.panel.replyAvatars,expressive:y.expressive,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:h,handoffHosts:m,resolveLink:u,focusComposer:()=>B.current?.(),keyboardAware:D,keyboardOffset:d,style:{flex:1},testID:`${v}-thread`}):_jsx(ChatStarters,{chat:e,labels:t,openTicket:h,avatar:y.avatar,motion:y.motion,greetingLoaderMs:_?0:y.panel.greetingLoaderMs,testID:`${v}-starters`}),_jsx(ChatPanelGrow,{grow:k.grow,children:_jsxs(View,{style:{flex:1},role:"sheet"===p?"dialog":"region",accessibilityLabel:V,testID:v,children:[_jsx(ChatReveal,{plan:k.reveal.header,children:N}),_jsx(ChatReveal,{plan:k.reveal.body,flex:!0,children:_jsx(View,{style:{flex:1},children:P})}),T?null:_jsx(ChatLiveBar,{chat:e,labels:t,testID:`${v}-live`}),T?null:_jsx(ChatReveal,{plan:k.reveal.composer,children:_jsx(ChatComposer,{chat:e,labels:t,look:y,sendIcon:r?.input?.sendIcon,pickAttachments:n,keyboardOffset:d,keyboardAware:D,focusRef:B,testID:`${v}-composer`})})]})})}
|
package/lib/module/ChatSheet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{mergeLabels,mergeLook}from"@webority/chat-core";import{BottomSheet,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{ChatLauncher}from"./ChatLauncher.js";import{ChatNudge}from"./ChatNudge.js";import{focusForAccessibility}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;export function ChatSheet({chat:e,labels:t,renderers:o,layoutParts:s,loader:r="Steps",look:n,appearance:a,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,keyboardOffset:f,open:p,defaultOpen:h=!1,onOpenChange:m,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:b,handoffHosts:g,resolveLink:C,conversationId:S,onClose:k,testID:j="chat-sheet"}){const y=useTheme(),x=mergeLabels(t),T=useMemo(()=>mergeLook(n),[n]),A=useReducedMotion(),_="Reduced"===T.motion||A,v=a?.position??"end",L=void 0!==p,O=L?p:e.open,E=useRef(null),F=useRef(!1),P=useRef(S??null),R=e.setChatVisible,N=useRef(!1),D=!N.current,[I,w]=useState(0),M=useRef(O);useEffect(()=>{O&&(N.current=!0)},[O]),useEffect(()=>{O&&!M.current&&w(e=>e+1),M.current=O},[O]),useEffect(()=>{F.current||(F.current=!0,L||!h||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[L,h,e.profile,e.open,e.session]),useEffect(()=>{L&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[L,p,e.open,e.session]);const V=useRef(O);if(useEffect(()=>{V.current&&!O&&focusForAccessibility(E.current),V.current=O},[O]),useEffect(()=>{R(O)},[R,O]),useEffect(()=>{!L&&S&&S!==P.current&&null!==e.profile&&(P.current=S,e.open||(e.session.open({trigger:"manual"}),m?.(!0)))},[L,S,e.profile,e.open,e.session,m]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),m?.(t)},closeSheet=()=>{setOpen(!1),k?.()},B=a?.offsetY??16;return _jsx(View,{testID:j,style:StyleSheet.absoluteFill,pointerEvents:"box-none",children:_jsxs(ChatAppearanceScope,{appearance:a,children:[_jsx(ChatLauncher,{look:T,hidden:O,label:e.profile?.experience.launcher?.hoverLabel||x.launcher,side:v,offsetX:a?.offsetX??0,offsetY:B,enter:D,reduced:_,mark:T.launcher.mark,avatar:T.avatar,buttonRef:E,onPress:()=>setOpen(!0),testID:`${j}-launcher`}),_jsx(ChatNudge,{chat:e,labels:x,enabled:!O&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:B,position:v,testID:`${j}-nudge`}),_jsx(BottomSheet,{open:O,onClose:closeSheet,...void 0===d?{}:{snapPoints:d},keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:x.panelTitle,children:_jsx(View,{style:{flex:1,backgroundColor:y.colors.bg},children:_jsx(ChatFrame,{chat:e,labels:x,renderers:o,layoutParts:s,loader:r,look:n,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,openTicket:b,handoffHosts:g,resolveLink:C,keyboardOffset:f,onClose:closeSheet,layout:"sheet",enterKey:I,testID:`${j}-frame`})})})]})})}
|
|
1
|
+
"use strict";import{mergeLabels,mergeLook}from"@webority/chat-core";import{BottomSheet,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{ChatLauncher}from"./ChatLauncher.js";import{ChatNudge}from"./ChatNudge.js";import{focusForAccessibility}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;export function ChatSheet({chat:e,labels:t,renderers:o,layoutParts:s,loader:r="Steps",look:n,appearance:a,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,keyboardOffset:f,open:p,defaultOpen:h=!1,onOpenChange:m,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:b,handoffHosts:g,resolveLink:C,conversationId:S,onClose:k,testID:j="chat-sheet"}){const y=useTheme(),x=mergeLabels(t),T=useMemo(()=>mergeLook(n),[n]),A=useReducedMotion(),_="Reduced"===T.motion||A,v=a?.position??"end",L=void 0!==p,O=L?p:e.open,E=useRef(null),F=useRef(!1),P=useRef(S??null),R=e.setChatVisible,N=useRef(!1),D=!N.current,[I,w]=useState(0),M=useRef(O);useEffect(()=>{O&&(N.current=!0)},[O]),useEffect(()=>{O&&!M.current&&w(e=>e+1),M.current=O},[O]),useEffect(()=>{F.current||(F.current=!0,L||!h||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[L,h,e.profile,e.open,e.session]),useEffect(()=>{L&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[L,p,e.open,e.session]);const V=useRef(O);if(useEffect(()=>{V.current&&!O&&focusForAccessibility(E.current),V.current=O},[O]),useEffect(()=>{R(O)},[R,O]),useEffect(()=>{!L&&S&&S!==P.current&&null!==e.profile&&(P.current=S,e.open||(e.session.open({trigger:"manual"}),m?.(!0)))},[L,S,e.profile,e.open,e.session,m]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),m?.(t)},closeSheet=()=>{setOpen(!1),k?.()},B=a?.offsetY??16;return _jsx(View,{testID:j,style:StyleSheet.absoluteFill,pointerEvents:"box-none",children:_jsxs(ChatAppearanceScope,{appearance:a,children:[_jsx(ChatLauncher,{look:T,hidden:O,label:e.profile?.experience.launcher?.hoverLabel||x.launcher,side:v,offsetX:a?.offsetX??0,offsetY:B,enter:D,reduced:_,mark:T.launcher.mark,avatar:T.avatar,buttonRef:E,onPress:()=>setOpen(!0),testID:`${j}-launcher`}),_jsx(ChatNudge,{chat:e,labels:x,enabled:!O&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:B,position:v,testID:`${j}-nudge`}),_jsx(BottomSheet,{open:O,onClose:closeSheet,...void 0===d?{}:{snapPoints:d},keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:x.panelTitle||e.profile?.assistant.name||x.assistant,children:_jsx(View,{style:{flex:1,backgroundColor:y.colors.bg},children:_jsx(ChatFrame,{chat:e,labels:x,renderers:o,layoutParts:s,loader:r,look:n,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,openTicket:b,handoffHosts:g,resolveLink:C,keyboardOffset:f,onClose:closeSheet,layout:"sheet",enterKey:I,testID:`${j}-frame`})})})]})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatDate}from"@webority/mobile-core";import{Avatar,Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{View}from"react-native";import{ChatEntrance}from"./ChatEntrance.js";import{ChatOpenTickets}from"./ChatOpenTickets.js";import{ChatPastChats}from"./ChatPastChats.js";import{iconNameOf}from"./iconName.js";import{TypingPill}from"./loaders/TypingPill.js";import{chipLook}from"./renderers/chipLook.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export function ChatStarters({chat:e,labels:t,openTicket:s,avatar:a,motion:r="On",greetingLoaderMs:i=0,testID:n="chat-starters"}){const o=useTheme(),[l,c]=useState(!(i>0));useEffect(()=>{if(l)return;const e=setTimeout(()=>c(!0),i);return()=>clearTimeout(e)},[l,i]);const m=e.profile,
|
|
1
|
+
"use strict";import{formatDate}from"@webority/mobile-core";import{Avatar,Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{View}from"react-native";import{ChatEntrance}from"./ChatEntrance.js";import{ChatOpenTickets}from"./ChatOpenTickets.js";import{ChatPastChats}from"./ChatPastChats.js";import{iconNameOf}from"./iconName.js";import{TypingPill}from"./loaders/TypingPill.js";import{chipLook}from"./renderers/chipLook.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export function ChatStarters({chat:e,labels:t,openTicket:s,avatar:a,motion:r="On",greetingLoaderMs:i=0,testID:n="chat-starters"}){const o=useTheme(),[l,c]=useState(!(i>0));useEffect(()=>{if(l)return;const e=setTimeout(()=>c(!0),i);return()=>clearTimeout(e)},[l,i]);const m=e.profile,u=e.greeting??"";if(!m)return null;const p=m.assistant.intro,h=e.features.Starters&&e.starters.length>0,d=e.lastConversation,f=e.features.ResumeLast&&!e.features.History&&null!==d;return _jsx(View,{accessibilityLabel:t.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:o.space.md,padding:o.space.md},testID:n,children:l?_jsxs(_Fragment,{children:[a?_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsx(Avatar,{size:"lg",name:e.profile?.assistant.name||t.assistant,source:{uri:a}})}):null,_jsx(Text,{variant:"h2",align:"center",children:u}),p?_jsx(Text,{variant:"body",color:"secondary",align:"center",children:p}):null,h?_jsx(View,{accessibilityRole:"none",accessibilityLabel:t.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:o.space.xs},children:e.starters.map((t,s)=>{const a=iconNameOf(t.icon);return _jsx(ChatEntrance,{index:s,children:_jsx(Chip,{...t.variant?chipLook(t.variant):null,label:t.label,...null===a?{}:{leftIcon:a},onPress:()=>{e.submit(t.message)},testID:`${n}-${t.id}`})},t.id)})}):null,f&&d?_jsxs(Card,{variant:"outline",padding:"sm",onPress:()=>{e.resumeLast()},testID:`${n}-resume`,children:[_jsx(Text,{variant:"caption",color:"secondary",children:t.resumeLast}),_jsx(Text,{variant:"label",numberOfLines:1,children:d.title||t.untitled}),_jsx(Text,{variant:"caption",color:"secondary",children:formatDate(d.lastActivityDateTimeUtc)})]}):null,e.features.History?_jsx(ChatPastChats,{chat:e,labels:t,testID:`${n}-past-chats`}):null,_jsx(ChatOpenTickets,{chat:e,labels:t,onOpenTicket:s})]}):_jsx(View,{children:_jsx(TypingPill,{motion:r,mark:a?_jsx(Avatar,{size:"xs",name:e.profile?.assistant.name||t.assistant,source:{uri:a}}):null})})})}
|
package/lib/module/ChatThread.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createTurnApi,formatChatDateTime,handoffSettledIds,messagePlainText}from"@webority/chat-core";import{Avatar,Button,MessageBubble,MessageList,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{createElement,memo,useEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Platform,View}from"react-native";import{AgentByline}from"./AgentByline.js";import{ChatEntrance}from"./ChatEntrance.js";import{ChatMessageActions}from"./ChatMessageActions.js";import{defaultOpenTarget,focusForAccessibility,messageSignature}from"./chatShared.js";import{ChatLoader}from"./loaders/ChatLoader.js";import{ReplyRing}from"./loaders/ReplyRing.js";import{TypingPill}from"./loaders/TypingPill.js";import{defaultRenderers}from"./renderers/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MINE=new Set(["Visitor","Customer"]),visuallyHidden={position:"absolute",left:-1e4,width:1,height:1,overflow:"hidden"},spokenAuthor=(e,t,s)=>MINE.has(e.author.kind)?t.you:e.author.displayName?e.author.displayName:"Agent"===e.author.kind?t.agent:s??t.assistant,joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n");function isKind(e,t){return e.kind===t}const kindWrappers=new WeakMap;function forKind(e,t){const s=kindWrappers.get(t)??new Map,a=s.get(e);if(a)return a;function KindEntry(s){if(!isKind(s.part,e))throw new Error(`renderer for ${e} received a ${s.part.kind} part`);return createElement(t,{part:s.part,message:s.message,turn:s.turn,pickAttachments:s.pickAttachments})}return s.set(e,KindEntry),kindWrappers.set(t,s),KindEntry}const defaults=defaultRenderers;function entryFor(e,t){return forKind(e,t??defaults[e])}function resolveRenderers(e){return{Text:entryFor("Text",e?.Text),Sources:entryFor("Sources",e?.Sources),QuickReplies:entryFor("QuickReplies",e?.QuickReplies),InputRequest:entryFor("InputRequest",e?.InputRequest),Action:entryFor("Action",e?.Action),Notice:entryFor("Notice",e?.Notice),Table:entryFor("Table",e?.Table),Chart:entryFor("Chart",e?.Chart),Figures:entryFor("Figures",e?.Figures),RecordCard:entryFor("RecordCard",e?.RecordCard),Image:entryFor("Image",e?.Image),File:entryFor("File",e?.File),Ticket:entryFor("Ticket",e?.Ticket),Handoff:entryFor("Handoff",e?.Handoff),VoiceClip:entryFor("VoiceClip",e?.VoiceClip)}}const renderPart=(e,t,s,a,r,i)=>{const n=e[t.kind];return createElement(n,{key:i,part:t,message:s,turn:a,pickAttachments:r})},sameMessage=(e,t)=>e.signature===t.signature&&e.message.id===t.message.id&&e.message.rating===t.message.rating&&e.message.stored===t.message.stored&&e.groupPosition===t.groupPosition&&e.isLast===t.isLast&&e.handoffSettled===t.handoffSettled&&e.isLastVisitor===t.isLastVisitor&&e.thinking===t.thinking&&e.streaming===t.streaming&&e.pickAttachments===t.pickAttachments&&e.labels===t.labels&&e.all===t.all&&e.layoutParts===t.layoutParts&&e.chat.session===t.chat.session&&e.chat.features===t.chat.features&&e.chat.onNavigate===t.chat.onNavigate&&e.onNavigate===t.onNavigate&&e.onOpenAttachment===t.onOpenAttachment&&e.onOpenTarget===t.onOpenTarget&&e.openTicket===t.openTicket&&e.resolveLink===t.resolveLink&&e.focusComposer===t.focusComposer&&e.byline===t.byline&&e.avatar===t.avatar&&e.replyAvatars===t.replyAvatars&&e.avatarStart===t.avatarStart&&e.expressive===t.expressive&&e.reduced===t.reduced&&e.handoffHosts===t.handoffHosts;function ThreadMessageView({chat:e,message:t,labels:s,all:a,layoutParts:r,groupPosition:i,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:d,onOpenTarget:c,onNavigate:u,openTicket:p,handoffHosts:g,resolveLink:m,focusComposer:h,byline:f,avatar:y,replyAvatars:x,avatarStart:k,expressive:T,reduced:v,sourceRows:A,testID:b}){const w=useTheme(),j=Object.assign(createTurnApi(e.session,{messageId:t.id,labels:s,openAttachment:d,openTarget:c??defaultOpenTarget,onNavigate:u??e.onNavigate,openTicket:p,handoffHosts:g,openCitation:e=>{return t=String(e),void focusForAccessibility(A.current.get(t));var t}}),{resolveLink:m,focusComposer:h,registerSourceRow:(e,t)=>{t?A.current.set(e,t):A.current.delete(e)}});let _=0;const nextSlot=()=>(_+=1,_),R=_jsx(ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${b}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind||"VoiceClip"===e.kind),s=_jsxs(View,{style:{gap:w.space.xs},children:[e.map(e=>renderPart(a,e,t,j,l,`${t.id}-file-${nextSlot()}`)),R]});return _jsx(MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:i,footer:s,testID:b})}const M="Agent"===t.author.kind,N=t.author.displayName||s.agent,S=(r?r(t):t.parts).map(e=>Array.isArray(e)?_jsx(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:w.space.xs},children:e.map(e=>renderPart(a,e,t,j,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,j,l,`${t.id}-item-${nextSlot()}`)),C=M&&f?_jsx(AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=C?[C,...S]:S,P=messagePlainText(t.parts),V=_jsx(MessageBubble,{side:"theirs",...M?{}:{author:`${t.author.displayName||(e.profile?.assistant.name??s.assistant)}:`},text:M?`${s.agentSays(N)} ${P}`:P,streaming:t.streaming,groupPosition:i,footer:R,testID:b,children:I});if(!x||!y||"Assistant"!==t.author.kind)return V;const F=t.author.displayName||(e.profile?.assistant.name??s.assistant);return _jsxs(View,{style:{flexDirection:"row",alignItems:"flex-end",gap:w.space.xs},children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:k?void 0:{opacity:0},children:_jsx(ReplyRing,{active:T&&t.streaming&&k,reduced:v,children:_jsx(Avatar,{size:"xs",name:F,...k?{source:{uri:y}}:{}})})}),_jsx(View,{style:{flex:1,minWidth:0},children:V})]})}const ThreadMessage=memo(ThreadMessageView,sameMessage),TYPING_ORB_MARK=14,TYPING_ASSISTANT_MARK=8,TypingMark=({size:e})=>{const t=useTheme();return _jsx(View,{style:{width:e,height:e,borderRadius:t.radius.pill,backgroundColor:t.colors.primary}})},TYPING_DOT=6,TypingDots=()=>{const e=useTheme();return _jsx(View,{style:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},children:[0,1,2].map(t=>_jsx(View,{style:{width:6,height:6,borderRadius:3,backgroundColor:e.colors["text-muted"]}},t))})},TurnGap=()=>{const e=useTheme();return _jsx(View,{style:{height:e.space.lg}})},followNew=()=>!0;export function ChatThread({chat:e,labels:t,renderers:s,layoutParts:a,loader:r="Steps",motion:i="On",avatar:n,replyAvatars:o="First",expressive:l=!1,pickAttachments:d,onOpenAttachment:c,onOpenTarget:u,onNavigate:p,openTicket:g,handoffHosts:m,resolveLink:h,focusComposer:f,keyboardAware:y,keyboardOffset:x,empty:k,style:T,testID:v="chat-thread"}){const A=useTheme(),b=useReducedMotion(),w="Reduced"===i||b,j=useMemo(()=>resolveRenderers(s),[s]),_=e.messages[0],R=e.greeting??"",M=useMemo(()=>""!==R&&void 0!==_&&MINE.has(_.author.kind)?{..._,id:"greeting",author:{..._.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:R}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[R,_]),N=useMemo(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return M?[...t,M]:t},[e.messages,M]),S=e.messages[e.messages.length-1]?.id,C=useRef(new Map),I=useRef(null);useEffect(()=>{if(null!==I.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||I.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;I.current.add(s.id);const e=messagePlainText(s.parts);""!==e&&AccessibilityInfo.announceForAccessibility("Agent"===s.author.kind?`${t.agentSays(s.author.displayName||t.agent)} ${e}`:e)}else I.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const P=useMemo(()=>{for(let t=e.messages.length-1;t>=0;t-=1){const s=e.messages[t];if(s?.stored&&"Visitor"===s.author.kind)return s.id}},[e.messages]),V=useMemo(()=>{const t=new Set;return e.messages.forEach((s,a)=>{if("Agent"!==s.author.kind)return;const r=e.messages[a-1];"Agent"===r?.author.kind&&(r.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),F=useMemo(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return M&&t.add(M.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,M]),L=useMemo(()=>handoffSettledIds(e.messages),[e.messages]),$=e.turnError,E="daily_limit"===$?.code,D=null!==$&&/feature_off$/.test($.code),O=E&&$?.resetsDateTimeUtc?` ${t.dailyLimitRefresh(formatChatDateTime($.resetsDateTimeUtc))}`:"",H=e.streaming||null===$&&!e.stopped?null:_jsxs(View,{style:{gap:A.space.xs},testID:`${v}-error`,children:[_jsx(Text,null!==$?{variant:"bodySmall",color:"danger",accessibilityRole:E?void 0:"alert",accessibilityLiveRegion:E?"polite":void 0,children:`${$.message}${O}`}:{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||E||D?null:_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${v}-retry`})})]}),K=e.thinking&&null!==e.profile?_jsx(ChatLoader,{style:r,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:i}):null,B=!0===e.pending?.typing?_jsx(TypingPill,{motion:i,mark:_jsx(ReplyRing,{active:l,reduced:w,children:n?_jsx(Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:n}}):_jsx(TypingMark,{size:"Orb"===r?14:8})})}):null,W=null!==e.agentTyping&&"WithAgent"===e.conversationState?_jsxs(View,{style:{gap:A.space.xs,alignSelf:"flex-start"},children:[_jsx(TypingPill,{motion:i,mark:_jsx(TypingDots,{})}),_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,z=B||K||H||W?_jsxs(View,{style:{gap:A.space.sm},children:[B,K,W,H]}):void 0,G=_jsx(MessageList,{messages:N,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:r})=>_jsxs(View,{role:"listitem",children:[_jsx(Text,{style:visuallyHidden,children:`${spokenAuthor(s,t,e.profile?.assistant.name)}: `}),_jsx(ChatEntrance,{animate:!s.restored,children:_jsx(ThreadMessage,{chat:e,message:s,signature:messageSignature(s),labels:t,all:j,layoutParts:a,groupPosition:r,isLast:s.id===S,isLastVisitor:s.id===P,handoffSettled:L.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:d,onOpenAttachment:c,onOpenTarget:u,onNavigate:p,openTicket:g,handoffHosts:m,resolveLink:h,focusComposer:f,byline:V.has(s.id),avatar:n,replyAvatars:"None"!==o,avatarStart:"Every"===o||F.has(s.id),expressive:l,reduced:w,sourceRows:C,testID:`${v}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:z,empty:k,ItemSeparatorComponent:TurnGap,...void 0===y?{}:{keyboardAware:y},...void 0===x?{}:{keyboardOffset:x},..."web"===Platform.OS?{}:{accessibilityLabel:t.thread},accessibilityRole:"list",style:T,testID:v});return"web"!==Platform.OS?G:_jsx(View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:G})}
|
|
1
|
+
"use strict";import{createTurnApi,formatChatDateTime,handoffSettledIds,messagePlainText}from"@webority/chat-core";import{Avatar,Button,MessageBubble,MessageList,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{createElement,memo,useEffect,useMemo,useRef}from"react";import{AccessibilityInfo,Platform,View}from"react-native";import{AgentByline}from"./AgentByline.js";import{ChatEntrance}from"./ChatEntrance.js";import{ChatMessageActions}from"./ChatMessageActions.js";import{defaultOpenTarget,focusForAccessibility,messageSignature}from"./chatShared.js";import{ChatLoader}from"./loaders/ChatLoader.js";import{ReplyRing}from"./loaders/ReplyRing.js";import{TypingPill}from"./loaders/TypingPill.js";import{defaultRenderers}from"./renderers/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MINE=new Set(["Visitor","Customer"]),visuallyHidden={position:"absolute",left:-1e4,width:1,height:1,overflow:"hidden"},spokenAuthor=(e,t,s)=>MINE.has(e.author.kind)?t.you:e.author.displayName?e.author.displayName:"Agent"===e.author.kind?t.agent:s??t.assistant,joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n");function isKind(e,t){return e.kind===t}const kindWrappers=new WeakMap;function forKind(e,t){const s=kindWrappers.get(t)??new Map,a=s.get(e);if(a)return a;function KindEntry(s){if(!isKind(s.part,e))throw new Error(`renderer for ${e} received a ${s.part.kind} part`);return createElement(t,{part:s.part,message:s.message,turn:s.turn,pickAttachments:s.pickAttachments})}return s.set(e,KindEntry),kindWrappers.set(t,s),KindEntry}const defaults=defaultRenderers;function entryFor(e,t){return forKind(e,t??defaults[e])}function resolveRenderers(e){return{Text:entryFor("Text",e?.Text),Sources:entryFor("Sources",e?.Sources),QuickReplies:entryFor("QuickReplies",e?.QuickReplies),InputRequest:entryFor("InputRequest",e?.InputRequest),Action:entryFor("Action",e?.Action),Notice:entryFor("Notice",e?.Notice),Table:entryFor("Table",e?.Table),Chart:entryFor("Chart",e?.Chart),Figures:entryFor("Figures",e?.Figures),RecordCard:entryFor("RecordCard",e?.RecordCard),Image:entryFor("Image",e?.Image),File:entryFor("File",e?.File),Ticket:entryFor("Ticket",e?.Ticket),Handoff:entryFor("Handoff",e?.Handoff),VoiceClip:entryFor("VoiceClip",e?.VoiceClip)}}const renderPart=(e,t,s,a,r,i)=>{const n=e[t.kind];return createElement(n,{key:i,part:t,message:s,turn:a,pickAttachments:r})},sameMessage=(e,t)=>e.signature===t.signature&&e.message.id===t.message.id&&e.message.rating===t.message.rating&&e.message.stored===t.message.stored&&e.groupPosition===t.groupPosition&&e.isLast===t.isLast&&e.handoffSettled===t.handoffSettled&&e.isLastVisitor===t.isLastVisitor&&e.thinking===t.thinking&&e.streaming===t.streaming&&e.pickAttachments===t.pickAttachments&&e.labels===t.labels&&e.all===t.all&&e.layoutParts===t.layoutParts&&e.chat.session===t.chat.session&&e.chat.features===t.chat.features&&e.chat.onNavigate===t.chat.onNavigate&&e.onNavigate===t.onNavigate&&e.onOpenAttachment===t.onOpenAttachment&&e.onOpenTarget===t.onOpenTarget&&e.openTicket===t.openTicket&&e.resolveLink===t.resolveLink&&e.focusComposer===t.focusComposer&&e.byline===t.byline&&e.avatar===t.avatar&&e.replyAvatars===t.replyAvatars&&e.avatarStart===t.avatarStart&&e.expressive===t.expressive&&e.reduced===t.reduced&&e.handoffHosts===t.handoffHosts;function ThreadMessageView({chat:e,message:t,labels:s,all:a,layoutParts:r,groupPosition:i,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:d,onOpenTarget:c,onNavigate:u,openTicket:p,handoffHosts:g,resolveLink:m,focusComposer:h,byline:f,avatar:y,replyAvatars:x,avatarStart:k,expressive:T,reduced:v,sourceRows:A,testID:b}){const w=useTheme(),j=Object.assign(createTurnApi(e.session,{messageId:t.id,labels:s,openAttachment:d,openTarget:c??defaultOpenTarget,onNavigate:u??e.onNavigate,openTicket:p,handoffHosts:g,openCitation:e=>{return t=String(e),void focusForAccessibility(A.current.get(t));var t}}),{resolveLink:m,focusComposer:h,registerSourceRow:(e,t)=>{t?A.current.set(e,t):A.current.delete(e)}});let _=0;const nextSlot=()=>(_+=1,_),R=_jsx(ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${b}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind||"VoiceClip"===e.kind),s=_jsxs(View,{style:{gap:w.space.xs},children:[e.map(e=>renderPart(a,e,t,j,l,`${t.id}-file-${nextSlot()}`)),R]});return _jsx(MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:i,footer:s,testID:b})}const M="Agent"===t.author.kind,N=t.author.displayName||s.agent,S=(r?r(t):t.parts).map(e=>Array.isArray(e)?_jsx(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:w.space.xs},children:e.map(e=>renderPart(a,e,t,j,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,j,l,`${t.id}-item-${nextSlot()}`)),C=M&&f?_jsx(AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=C?[C,...S]:S,P=messagePlainText(t.parts),V=_jsx(MessageBubble,{side:"theirs",...M?{}:{author:`${t.author.displayName||(e.profile?.assistant.name??s.assistant)}:`},text:M?`${s.agentSays(N)} ${P}`:P,streaming:t.streaming,groupPosition:i,footer:R,testID:b,children:I});if(!x||!y||"Assistant"!==t.author.kind)return V;const F=t.author.displayName||(e.profile?.assistant.name??s.assistant);return _jsxs(View,{style:{flexDirection:"row",alignItems:"flex-end",gap:w.space.xs},children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:k?void 0:{opacity:0},children:_jsx(ReplyRing,{active:T&&t.streaming&&k,reduced:v,children:_jsx(Avatar,{size:"xs",name:F,...k?{source:{uri:y}}:{}})})}),_jsx(View,{style:{flex:1,minWidth:0},children:V})]})}const ThreadMessage=memo(ThreadMessageView,sameMessage),TYPING_ORB_MARK=14,TYPING_ASSISTANT_MARK=8,TypingMark=({size:e})=>{const t=useTheme();return _jsx(View,{style:{width:e,height:e,borderRadius:t.radius.pill,backgroundColor:t.colors.primary}})},TYPING_DOT=6,TypingDots=()=>{const e=useTheme();return _jsx(View,{style:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},children:[0,1,2].map(t=>_jsx(View,{style:{width:6,height:6,borderRadius:3,backgroundColor:e.colors["text-muted"]}},t))})},TurnGap=()=>{const e=useTheme();return _jsx(View,{style:{height:e.space.lg}})},followNew=()=>!0;export function ChatThread({chat:e,labels:t,renderers:s,layoutParts:a,loader:r="Steps",motion:i="On",avatar:n,replyAvatars:o="First",expressive:l=!1,pickAttachments:d,onOpenAttachment:c,onOpenTarget:u,onNavigate:p,openTicket:g,handoffHosts:m,resolveLink:h,focusComposer:f,keyboardAware:y,keyboardOffset:x,empty:k,style:T,testID:v="chat-thread"}){const A=useTheme(),b=useReducedMotion(),w="Reduced"===i||b,j=useMemo(()=>resolveRenderers(s),[s]),_=e.messages[0],R=e.greeting??"",M=useMemo(()=>""!==R&&void 0!==_&&MINE.has(_.author.kind)?{..._,id:"greeting",author:{..._.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:R}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[R,_]),N=useMemo(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return M?[...t,M]:t},[e.messages,M]),S=e.messages[e.messages.length-1]?.id,C=useRef(new Map),I=useRef(null);useEffect(()=>{if(null!==I.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||I.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;I.current.add(s.id);const e=messagePlainText(s.parts);""!==e&&AccessibilityInfo.announceForAccessibility("Agent"===s.author.kind?`${t.agentSays(s.author.displayName||t.agent)} ${e}`:e)}else I.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const P=useMemo(()=>{for(let t=e.messages.length-1;t>=0;t-=1){const s=e.messages[t];if(s?.stored&&"Visitor"===s.author.kind)return s.id}},[e.messages]),V=useMemo(()=>{const t=new Set;return e.messages.forEach((s,a)=>{if("Agent"!==s.author.kind)return;const r=e.messages[a-1];"Agent"===r?.author.kind&&(r.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),F=useMemo(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return M&&t.add(M.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,M]),L=useMemo(()=>handoffSettledIds(e.messages),[e.messages]),$=e.turnError,E="daily_limit"===$?.code,D=null!==$&&/feature_off$/.test($.code),O=E&&$?.resetsDateTimeUtc?` ${t.dailyLimitRefresh(formatChatDateTime($.resetsDateTimeUtc))}`:"",H=e.streaming||null===$&&!e.stopped?null:_jsxs(View,{style:{gap:A.space.xs},testID:`${v}-error`,children:[_jsx(Text,null!==$?{variant:"bodySmall",color:"danger",accessibilityRole:E?void 0:"alert",accessibilityLiveRegion:E?"polite":void 0,children:`${$.message}${O}`}:{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||E||D?null:_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${v}-retry`})})]}),K=e.thinking&&null!==e.profile?_jsx(ChatLoader,{style:r,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:i}):null,B=!0===e.pending?.typing?_jsx(TypingPill,{motion:i,mark:_jsx(ReplyRing,{active:l,reduced:w,children:n?_jsx(Avatar,{size:"xs",name:e.profile?.assistant.name||t.assistant,source:{uri:n}}):_jsx(TypingMark,{size:"Orb"===r?14:8})})}):null,W=null!==e.agentTyping&&"WithAgent"===e.conversationState?_jsxs(View,{style:{gap:A.space.xs,alignSelf:"flex-start"},children:[_jsx(TypingPill,{motion:i,mark:_jsx(TypingDots,{})}),_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,z=B||K||H||W?_jsxs(View,{style:{gap:A.space.sm},children:[B,K,W,H]}):void 0,G=_jsx(MessageList,{messages:N,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:r})=>_jsxs(View,{role:"listitem",children:[_jsx(Text,{style:visuallyHidden,children:`${spokenAuthor(s,t,e.profile?.assistant.name)}: `}),_jsx(ChatEntrance,{animate:!s.restored,children:_jsx(ThreadMessage,{chat:e,message:s,signature:messageSignature(s),labels:t,all:j,layoutParts:a,groupPosition:r,isLast:s.id===S,isLastVisitor:s.id===P,handoffSettled:L.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:d,onOpenAttachment:c,onOpenTarget:u,onNavigate:p,openTicket:g,handoffHosts:m,resolveLink:h,focusComposer:f,byline:V.has(s.id),avatar:n,replyAvatars:"None"!==o,avatarStart:"Every"===o||F.has(s.id),expressive:l,reduced:w,sourceRows:C,testID:`${v}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:z,empty:k,ItemSeparatorComponent:TurnGap,...void 0===y?{}:{keyboardAware:y},...void 0===x?{}:{keyboardOffset:x},..."web"===Platform.OS?{}:{accessibilityLabel:t.thread},accessibilityRole:"list",style:T,testID:v});return"web"!==Platform.OS?G:_jsx(View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:G})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.164.0",
|
|
4
4
|
"description": "Webority Chat for React Native apps: the chat screen, sheet and embedded shells, thread, composer, one renderer per message part kind and the useChat hook, built on @webority/chat-core and @webority/mobile-ui.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"!**/*.map"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@webority/chat-core": "0.
|
|
46
|
-
"@webority/markdown-core": "^0.
|
|
47
|
-
"@webority/mobile-core": "^0.
|
|
48
|
-
"@webority/mobile-ui": "^0.
|
|
45
|
+
"@webority/chat-core": "0.164.0",
|
|
46
|
+
"@webority/markdown-core": "^0.192.0",
|
|
47
|
+
"@webority/mobile-core": "^0.192.0",
|
|
48
|
+
"@webority/mobile-ui": "^0.192.0",
|
|
49
49
|
"expo-audio": ">=58.0.0",
|
|
50
50
|
"expo-crypto": ">=58.0.0",
|
|
51
51
|
"expo-file-system": ">=58.0.0",
|
|
@@ -99,11 +99,11 @@
|
|
|
99
99
|
"@testing-library/react-native": "14.1.0",
|
|
100
100
|
"@types/jest": "29.5.14",
|
|
101
101
|
"@types/react": "19.3.0",
|
|
102
|
-
"@webority/canvas-kit": "0.
|
|
103
|
-
"@webority/chat-core": "0.
|
|
104
|
-
"@webority/markdown-core": "0.
|
|
105
|
-
"@webority/mobile-core": "0.
|
|
106
|
-
"@webority/mobile-ui": "0.
|
|
102
|
+
"@webority/canvas-kit": "0.192.0",
|
|
103
|
+
"@webority/chat-core": "0.164.0",
|
|
104
|
+
"@webority/markdown-core": "0.192.0",
|
|
105
|
+
"@webority/mobile-core": "0.192.0",
|
|
106
|
+
"@webority/mobile-ui": "0.192.0",
|
|
107
107
|
"babel-jest": "29.7.0",
|
|
108
108
|
"expo": "58.0.23",
|
|
109
109
|
"expo-application": "58.1.2",
|