@webority/mobile-chat 0.146.1 → 0.147.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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  Copyright (c) Webority Technologies. All rights reserved.
2
2
 
3
- This software and its NuGet packages are the proprietary and confidential property
3
+ This software and its Webority packages are the proprietary and confidential property
4
4
  of Webority Technologies. They are published publicly only for the convenience of
5
5
  Webority's own projects and internal consumption.
6
6
 
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatFooter=ChatFooter;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>(0,_chatShared.openExternalUrl)(e);function ChatFooter({chat:e,labels:i}){const t=(0,_mobileUi.useTheme)(),r=e.profile;if(!r)return null;const o=r.footer.disclaimer||i.disclaimer,a=r.footer.privacyUrl,n=r.footer.assuranceText,l=r.footer.privacyText,c=(0,_chatCore.showsCaptchaNote)(r);return Boolean(o)||Boolean(l)||Boolean(a)||Boolean(n)||c?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xxs,alignItems:"center"},...(0,_chatShared.webProps)({role:"paragraph"}),children:[o?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:o}):null,l?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:l}):null,a?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(a),children:i.footerPrivacy}):null,n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:n}):null,c?(0,_jsxRuntime.jsxs)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:[i.captchaNote," ",(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:i.captchaPrivacy})," ",(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:i.captchaTerms})]}):null]}):null}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatFooter=ChatFooter;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>(0,_chatShared.openExternalUrl)(e);function ChatFooter({chat:e,labels:i}){const t=(0,_mobileUi.useTheme)(),r=e.profile;if(!r)return null;const a=r.footer.disclaimer||i.disclaimer,o=r.footer.privacyUrl,n=r.footer.assuranceText,c=r.footer.privacyText,l=(0,_chatCore.showsCaptchaNote)(r);if(!(Boolean(a)||Boolean(c)||Boolean(o)||Boolean(n)||l))return null;const s=[];return a&&s.push((0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:a},"disclaimer")),(c||o)&&s.push((0,_jsxRuntime.jsxs)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:[c,c&&o?" ":null,o?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(o),children:i.footerPrivacy}):null]},"privacy")),n&&s.push((0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:n},"assurance")),l&&s.push((0,_jsxRuntime.jsxs)(_mobileUi.Text,{variant:"caption",color:"tertiary",align:"center",children:[i.captchaNote," ",(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:i.captchaPrivacy})," ",(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:i.captchaTerms})]},"captcha")),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{gap:t.space.xxs,alignItems:"center",flexDirection:"row",flexWrap:"wrap",justifyContent:"center"},...(0,_chatShared.webProps)({role:"paragraph"}),children:s.flatMap((e,i)=>i?[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",accessibilityElementsHidden:!0,importantForAccessibility:"no",...(0,_chatShared.webProps)({"aria-hidden":!0}),children:"·"},`sep-${e.key}`),e]:[e])})}
@@ -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??t.panelTitle,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.panelTitle,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}),w?null:(0,_jsxRuntime.jsx)(_ChatLiveBar.ChatLiveBar,{chat:e,labels:t,testID:`${b}-live`}),(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)(_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
+ "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??t.panelTitle,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.panelTitle,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.ChatMessageActions=ChatMessageActions;var _chatCore=require("@webority/chat-core"),_clipboard=require("@webority/mobile-core/clipboard"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("./chatShared.js"),_ReadAloudButton=require("./ReadAloudButton.js"),_useTranscriptActions=_interopRequireDefault(require("./useTranscriptActions.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);function ChatMessageActions({chat:e,message:t,labels:i,isLast:s,isLastVisitor:a,testID:r}){const n=(0,_mobileUi.useTheme)(),[o,l]=(0,_react.useState)(!1),[c,u]=(0,_react.useState)("idle"),d=(0,_react.useRef)(null),m=(0,_useTranscriptActions.default)(e,i),_=(0,_react.useMemo)(()=>TEXT_AUTHORS.has(t.author.kind)&&(0,_chatCore.buildTranscript)([t],{labels:i,title:null,figureText:!1,...void 0===e.profile?.assistant.name?{}:{assistantName:e.profile.assistant.name}}).entries.length>0,[t,i,e.profile]);if((0,_react.useEffect)(()=>()=>{null!==d.current&&clearTimeout(d.current)},[]),t.streaming)return null;const h=(0,_chatCore.messagePlainText)(t.parts),p=TEXT_AUTHORS.has(t.author.kind)&&""!==h,g=t.stored&&RATED_AUTHORS.has(t.author.kind),b=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==(0,_chatCore.messagePlainText)(t.parts).trim(),x=s&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),R=a&&t.stored&&e.features.Edit&&!e.streaming&&!e.thinking,save=async i=>{try{await e.rate(t.id,i),u("saved")}catch{u("failed")}};return p&&e.features.Copy||_&&e.features.Share&&m.canShare||b||x||R||g&&e.features.Rating?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[p&&e.features.Copy?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:o?i.copied:i.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await(0,_clipboard.copyText)(h)&&(l(!0),null!==d.current&&clearTimeout(d.current),d.current=setTimeout(()=>l(!1),2e3))})()},testID:`${r}-copy`}):null,_&&e.features.Share&&m.canShare?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{m.shareReply(t)},testID:`${r}-share`}):null,b?(0,_jsxRuntime.jsx)(_ReadAloudButton.ReadAloudButton,{chat:e,message:t,labels:i}):null,x?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${r}-regenerate`}):null,R?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${r}-edit`}):null,g&&e.features.Rating?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"summary",accessibilityLabel:i.rating,...(0,_chatShared.webProps)({role:"group","aria-label":`${i.rateUp} / ${i.rateDown}`}),style:{flexDirection:"row",alignItems:"center",gap:n.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"like",accessibilityLabel:i.rateUp,tone:"neutral",size:"sm",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{checked:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${r}-rate-up`}),(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"dislike",accessibilityLabel:i.rateDown,tone:"neutral",size:"sm",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{checked:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${r}-rate-down`})]}),"failed"===c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:i.ratingFailed}):null,"saved"===c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:i.rated}):null]}):null,null!==m.notice?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:m.notice}):null]}):null}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatMessageActions=ChatMessageActions;var _chatCore=require("@webority/chat-core"),_clipboard=require("@webority/mobile-core/clipboard"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("./chatShared.js"),_ReadAloudButton=require("./ReadAloudButton.js"),_useTranscriptActions=_interopRequireDefault(require("./useTranscriptActions.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);function ChatMessageActions({chat:e,message:t,labels:i,isLast:s,isLastVisitor:a,testID:r}){const n=(0,_mobileUi.useTheme)(),[o,l]=(0,_react.useState)(!1),[c,u]=(0,_react.useState)("idle"),d=(0,_react.useRef)(null),m=(0,_useTranscriptActions.default)(e,i),_=(0,_react.useMemo)(()=>TEXT_AUTHORS.has(t.author.kind)&&(0,_chatCore.buildTranscript)([t],{labels:i,title:null,figureText:!1,...void 0===e.profile?.assistant.name?{}:{assistantName:e.profile.assistant.name}}).entries.length>0,[t,i,e.profile]);if((0,_react.useEffect)(()=>()=>{null!==d.current&&clearTimeout(d.current)},[]),t.streaming)return null;const h=(0,_chatCore.messagePlainText)(t.parts),p=TEXT_AUTHORS.has(t.author.kind)&&""!==h,g=t.stored&&RATED_AUTHORS.has(t.author.kind),b=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==(0,_chatCore.messagePlainText)(t.parts).trim(),x=s&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),R=a&&t.stored&&e.features.Edit&&!e.streaming&&!e.thinking,save=async i=>{try{await e.rate(t.id,i),u("saved")}catch{u("failed")}};return p&&e.features.Copy||_&&e.features.Share&&m.canShare||b||x||R||g&&e.features.Rating?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[p&&e.features.Copy?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:o?i.copied:i.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await(0,_clipboard.copyText)(h)&&(l(!0),null!==d.current&&clearTimeout(d.current),d.current=setTimeout(()=>l(!1),2e3))})()},testID:`${r}-copy`}):null,b?(0,_jsxRuntime.jsx)(_ReadAloudButton.ReadAloudButton,{chat:e,message:t,labels:i}):null,_&&e.features.Share&&m.canShare?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{m.shareReply(t)},testID:`${r}-share`}):null,x?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${r}-regenerate`}):null,R?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${r}-edit`}):null,g&&e.features.Rating?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"summary",accessibilityLabel:i.rating,...(0,_chatShared.webProps)({role:"group","aria-label":`${i.rateUp} / ${i.rateDown}`}),style:{flexDirection:"row",alignItems:"center",gap:n.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"like",accessibilityLabel:i.rateUp,tone:"neutral",size:"sm",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{checked:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${r}-rate-up`}),(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"dislike",accessibilityLabel:i.rateDown,tone:"neutral",size:"sm",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{checked:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${r}-rate-down`})]}),"failed"===c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:i.ratingFailed}):null,"saved"===c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:i.rated}):null]}):null,null!==m.notice?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:m.notice}):null]}):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"},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,i=s.get(e);if(i)return i;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,i,a,r)=>{const n=e[t.kind];return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:i,pickAttachments:a})},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:i,layoutParts:a,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 b=(0,_mobileUi.useTheme)(),k=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),s=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:b.space.xs},children:[e.map(e=>renderPart(i,e,t,k,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=(a?a(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:b.space.xs},children:e.map(e=>renderPart(i,e,t,k,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(i,e,t,k,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:b.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:i,loader:a="Steps",motion:r="On",avatar:n,replyAvatars:o=!0,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)(),b="Reduced"===r||T,k=(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,i)=>{if("Agent"!==s.author.kind)return;const a=e.messages[i-1];"Agent"===a?.author.kind&&(a.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,i)=>{"Assistant"===e.author.kind&&"Assistant"!==s[i-1]?.author.kind&&t.add(e.id)}),t},[e.messages,w]),L=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),$=e.turnError,O="daily_limit"===$?.code,D=null!==$&&/feature_off$/.test($.code),E=O&&$?.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:O?void 0:"alert",accessibilityLiveRegion:O?"polite":void 0,children:`${$.message}${E}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||O||D?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:a,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:b,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"===a?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:a})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"listitem",children:[MINE.has(s.author.kind)?(0,_jsxRuntime.jsx)(_mobileUi.Text,{style:visuallyHidden,children:`${t.you}: `}):null,(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:k,layoutParts:i,groupPosition:a,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:o,avatarStart:F.has(s.id),expressive:l,reduced:b,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: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=!0,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,O="daily_limit"===$?.code,D=null!==$&&/feature_off$/.test($.code),E=O&&$?.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:O?void 0:"alert",accessibilityLiveRegion:O?"polite":void 0,children:`${$.message}${E}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||O||D?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:o,avatarStart: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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TypingPill=TypingPill;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const DOT=6,LIFT_PX=4,CYCLE_MS=1200,HALF_MS=300,STEP_MS=140,STILL_OPACITY=[1,.65,.3],DOT_INDEXES=[0,1,2];function TypingPill({motion:e,mark:t}){const i=(0,_mobileUi.useTheme)(),r=(0,_react.useMemo)(()=>buildStyles(i),[i]),a=(0,_mobileUi.useReducedMotion)(),s="Reduced"===e||a;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:r.pill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:[t,(0,_jsxRuntime.jsx)(_reactNative.View,{style:r.dots,children:DOT_INDEXES.map(e=>(0,_jsxRuntime.jsx)(Dot,{index:e,reduced:s,color:i.colors["text-subtle"],size:DOT},e))})]})}const Dot=({index:e,reduced:t,color:i,size:r})=>{const a=(0,_react.useRef)(new _reactNative.Animated.Value(0)).current;(0,_react.useEffect)(()=>{if(t)return void a.setValue(0);const i=_reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.delay(140*e),_reactNative.Animated.timing(a,{toValue:1,duration:300,useNativeDriver:!0}),_reactNative.Animated.timing(a,{toValue:0,duration:300,useNativeDriver:!0}),_reactNative.Animated.delay(600-140*e)]));return i.start(),()=>i.stop()},[a,e,t]);const s={width:r,height:r,borderRadius:r/2,backgroundColor:i};if(t)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[s,{opacity:STILL_OPACITY[e]}]});const n=a.interpolate({inputRange:[0,1],outputRange:[0,-4]});return(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[s,{transform:[{translateY:n}]}]})},buildStyles=e=>_reactNative.StyleSheet.create({pill:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.pill,paddingHorizontal:e.space.md,paddingVertical:e.space.sm},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TypingPill=TypingPill;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const DOT=6,LIFT_PX=4,CYCLE_MS=1200,HALF_MS=300,STEP_MS=140,STILL_OPACITY=[1,.65,.3],DOT_INDEXES=[0,1,2];function TypingPill({motion:e,mark:t}){const i=(0,_mobileUi.useTheme)(),r=(0,_react.useMemo)(()=>buildStyles(i),[i]),a=(0,_mobileUi.useReducedMotion)(),s="Reduced"===e||a;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:r.pill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",testID:"chat-typing-pill",children:[t,(0,_jsxRuntime.jsx)(_reactNative.View,{style:r.dots,children:DOT_INDEXES.map(e=>(0,_jsxRuntime.jsx)(Dot,{index:e,reduced:s,color:i.colors["text-subtle"],size:DOT},e))})]})}const Dot=({index:e,reduced:t,color:i,size:r})=>{const a=(0,_react.useRef)(new _reactNative.Animated.Value(0)).current;(0,_react.useEffect)(()=>{if(t)return void a.setValue(0);const i=_reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.delay(140*e),_reactNative.Animated.timing(a,{toValue:1,duration:300,useNativeDriver:!0}),_reactNative.Animated.timing(a,{toValue:0,duration:300,useNativeDriver:!0}),_reactNative.Animated.delay(600-140*e)]));return i.start(),()=>i.stop()},[a,e,t]);const s={width:r,height:r,borderRadius:r/2,backgroundColor:i};if(t)return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[s,{opacity:STILL_OPACITY[e]}]});const n=a.interpolate({inputRange:[0,1],outputRange:[0,-4]});return(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[s,{transform:[{translateY:n}]}]})},buildStyles=e=>_reactNative.StyleSheet.create({pill:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.pill,paddingHorizontal:e.space.md,paddingVertical:e.space.sm},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionPart=ActionPart;var _chatCore=require("@webority/chat-core"),_markdownCore=require("@webority/markdown-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https?:\/\//i,inlineNodes=(e,t)=>e.map(e=>{if("text"===e.type||"code"===e.type||"citation"===e.type)return e.text;if("link"===e.type){const i=inlineNodes(e.children,t);return SAFE_LINK.test(e.href)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"link",style:{color:t.colors.link,textDecorationLine:"underline"},onPress:()=>(0,_chatShared.openExternalUrl)(e.href),children:i},e.key):(0,_jsxRuntime.jsx)(_reactNative.Text,{children:i},e.key)}if("image"===e.type)return null;const i="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return(0,_jsxRuntime.jsx)(_reactNative.Text,{style:i,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${(0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat((0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),{labels:n,features:r}=t,[a,o]=(0,_react.useState)(null),[l,s]=(0,_react.useState)(""),[c,d]=(0,_react.useState)(!1),run=async(e,t)=>{o(e),s("");try{await t()}catch(t){_mobileCore.Logger.error(`[chat] action ${e} failed`,t),s(t instanceof _chatCore.ChatApiError&&""!==t.message?t.message:n.actionFailed),o(null)}},u=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=r.LeadRecap&&e.actionKind===LEAD_CAPTURE,x=m&&u.length>0,_=m&&e.confirmLabel||n.actionConfirm,h=m&&e.rejectLabel||n.actionDismiss,p=null!==a;return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",..._chatShared.WEB_STRONG,children:e.title}),e.lines.map(e=>{if(!m)return(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:e},e);const{term:t,detail:n}=splitLine(e);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",...(0,_chatShared.webProps)({role:"term"}),children:t}),null!==n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",...(0,_chatShared.webProps)({role:"definition"}),children:n}):null]},e)}),m&&e.consentText?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:inlineNodes((0,_markdownCore.parseInline)(e.consentText),i)}):null,"Pending"===e.state?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[""!==l?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:"confirm"===a?n.actionWorking:_,loading:"confirm"===a,disabled:p,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:h,variant:"ghost",disabled:p,onPress:()=>{run("reject",()=>t.rejectAction(e.actionId))}})]})]}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"Done"===e.state||"Confirmed"===e.state||"Repeat"===e.state?"success":"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:statusLine(e,n)}),x?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.editSomething,variant:"ghost",disabled:p||"Pending"!==e.state,onPress:()=>d(!0)}):null,e.note?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:e.note}):null]}),x?(0,_jsxRuntime.jsx)(_mobileUi.OptionSheet,{open:c,onClose:()=>d(!1),title:n.editSomething,options:u,onChange:(e,i)=>{d(!1),t.chooseQuickReply({id:`lead.edit:${String(i.value)}`,label:i.label,action:"Send",target:null,navigateAfterMs:null,icon:null,variant:null})}}):null]})}function ActionPart({part:e,turn:t}){return(0,_jsxRuntime.jsx)(ActionBody,{part:e,turn:t},e.actionId)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionPart=ActionPart;var _chatCore=require("@webority/chat-core"),_markdownCore=require("@webority/markdown-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https?:\/\//i,inlineNodes=(e,t)=>e.map(e=>{if("text"===e.type||"code"===e.type||"citation"===e.type)return e.text;if("link"===e.type){const i=inlineNodes(e.children,t);return SAFE_LINK.test(e.href)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"link",style:{color:t.colors.link,textDecorationLine:"underline"},onPress:()=>(0,_chatShared.openExternalUrl)(e.href),children:i},e.key):(0,_jsxRuntime.jsx)(_reactNative.Text,{children:i},e.key)}if("image"===e.type)return null;const i="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return(0,_jsxRuntime.jsx)(_reactNative.Text,{style:i,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${(0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat((0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),{labels:n,features:r}=t,[a,o]=(0,_react.useState)(null),[l,s]=(0,_react.useState)(""),[c,d]=(0,_react.useState)(!1),run=async(e,t)=>{o(e),s("");try{await t()}catch(t){_mobileCore.Logger.error(`[chat] action ${e} failed`,t),s(t instanceof _chatCore.ChatApiError&&""!==t.message?t.message:n.actionFailed),o(null)}},u=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=r.LeadRecap&&e.actionKind===LEAD_CAPTURE,x=m&&u.length>0,_=m&&e.confirmLabel||n.actionConfirm,h=m&&e.rejectLabel||n.actionDismiss,p=null!==a;return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",..._chatShared.WEB_STRONG,children:e.title}),e.lines.map(e=>{if(!m)return(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:e},e);const{term:t,detail:n}=splitLine(e);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",...(0,_chatShared.webProps)({role:"term"}),children:t}),null!==n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",...(0,_chatShared.webProps)({role:"definition"}),children:n}):null]},e)}),m&&e.consentText?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:inlineNodes((0,_markdownCore.parseInline)(e.consentText),i)}):null,e.note?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:e.note}):null,"Pending"===e.state?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[""!==l?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:"confirm"===a?n.actionWorking:_,loading:"confirm"===a,disabled:p,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:h,variant:"ghost",disabled:p,onPress:()=>{run("reject",()=>t.rejectAction(e.actionId))}})]})]}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"Done"===e.state||"Confirmed"===e.state||"Repeat"===e.state?"success":"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:statusLine(e,n)}),x?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.editSomething,variant:"ghost",disabled:p||"Pending"!==e.state,onPress:()=>d(!0)}):null]}),x?(0,_jsxRuntime.jsx)(_mobileUi.OptionSheet,{open:c,onClose:()=>d(!1),title:n.editSomething,options:u,onChange:(e,i)=>{d(!1),t.chooseQuickReply({id:`lead.edit:${String(i.value)}`,label:i.label,action:"Send",target:null,navigateAfterMs:null,icon:null,variant:null})}}):null]})}function ActionPart({part:e,turn:t}){return(0,_jsxRuntime.jsx)(ActionBody,{part:e,turn:t},e.actionId)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const fileNameOf=(e,t)=>{const i="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` (${t.inputOptional})`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:a,features:s}=t,[n,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[b,_]=(0,_react.useState)({}),[f,h]=(0,_react.useState)({}),j=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=j.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,w=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(a.errorGeneric),m(!1)}},U=s.LeadShortcuts,T=e.fields[0];if(U&&1===e.fields.length&&void 0===T)throw new Error("A one-field form has no field.");const q=U&&1===e.fields.length&&void 0!==T&&!T.required,C=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...(0,_chatShared.webProps)({role:"form","aria-label":e.title||e.submitLabel}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",...(0,_chatShared.webProps)({"aria-level":3}),children:e.title}):null,e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.typeAnswer}):null,e.fields.map(s=>{const l=n[s.key]??"",c=o[s.key];if("File"===s.type){const e=y[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:e?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=s.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:a.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:a.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:a.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i(e.accept??void 0)}catch{return void d(a.errorGeneric)}const s=r[0];if(!s)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(s,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(s,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(s)}})})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},s.key)}if("MultiChoice"===s.type){const e=(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(s.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Choice"===s.type||"TimeSlot"===s.type){const e="TimeSlot"===s.type?(s.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(s.key,String(e)),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Consent"===s.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(s.key,e?"true":"false"),label:s.consentText??s.label,...void 0===c?{}:{error:c},disabled:p},s.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{j.current[s.key]=e},label:s.label,..."string"==typeof s.placeholder?{placeholder:s.placeholder}:{},value:l,onChangeText:e=>setValue(s.key,e),..."number"==typeof s.maxLength?{maxLength:s.maxLength}:{},required:s.required,...void 0===c?{}:{error:c},...s.required?{}:{help:a.inputOptional},labelMode:"top",disabled:p,type:s.secret?"password":"LongText"===s.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[s.type]??"default",..."Email"===s.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[s.type]?{}:{autoComplete:AUTO_COMPLETE[s.type]}},s.key);if(!("Otp"===s.verify&&("Email"===s.type||"Phone"===s.type)))return u;const m=f[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[u,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async i=>{if("Otp"===i.verify)try{await t.sendOtp(e.requestId,{fieldKey:i.key,value:(n[i.key]??"").trim()}),h(e=>({...e,[i.key]:"sent"}))}catch{h(e=>({...e,[i.key]:"failed"}))}})(s)},testID:`otp-send-${s.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:a.inputEnterCode,value:b[s.key]??"",onChangeText:e=>_(t=>({...t,[s.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"failed"===m?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===m?a.inputCodeFailed:a.inputCodeSent}):null]})]},s.key)}),""!==u?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?a.inputSubmitting:e.submitLabel,loading:p,disabled:p||w,onPress:()=>{(async()=>{if(w)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const s="true"===e;t.required&&!s&&(i[t.key]=a.inputConsentRequired),r[t.key]=s?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const s=selectedIds(e);t.required&&0===s.length&&(i[t.key]=a.inputRequired),r[t.key]=JSON.stringify(s)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else{const s=t.secret?e:e.trim();t.required&&""===s&&(i[t.key]=a.inputRequired),r[t.key]=s}}const s={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(b[t.key]??"").trim();""===e&&(i[t.key]=a.inputRequired),s[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&S(t))}m(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(s).length>0?s:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(a.errorGeneric)}m(!1)})()}}),w?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.attachmentUploading}):null,q?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]})]})})}function InputRequestPart({part:e,turn:t,pickAttachments:i}){return"Answered"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:e,turn:t,pickAttachments:i},e.requestId)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const fileNameOf=(e,t)=>{const i="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:a,features:s}=t,[n,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[b,_]=(0,_react.useState)({}),[f,h]=(0,_react.useState)({}),j=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=j.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,w=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(a.errorGeneric),m(!1)}},U=s.LeadShortcuts,T=e.fields[0];if(U&&1===e.fields.length&&void 0===T)throw new Error("A one-field form has no field.");const C=U&&1===e.fields.length&&void 0!==T&&!T.required,q=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...(0,_chatShared.webProps)({role:"form","aria-label":e.title||e.submitLabel}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",...(0,_chatShared.webProps)({"aria-level":3}),children:e.title}):null,e.fields.map(s=>{const l=n[s.key]??"",c=o[s.key];if("File"===s.type){const e=y[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:e?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=s.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:a.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:a.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:a.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i(e.accept??void 0)}catch{return void d(a.errorGeneric)}const s=r[0];if(!s)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(s,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(s,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(s)}})})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},s.key)}if("MultiChoice"===s.type){const e=(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},...(0,_chatShared.webProps)({role:"group","aria-label":s.label}),children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(s.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Choice"===s.type||"TimeSlot"===s.type){const e="TimeSlot"===s.type?(s.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(s.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${s.label}${optionalSuffix(s,a)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[s.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(s.key,String(e)),accessibilityLabel:s.label,...void 0===c?{}:{error:c},disabled:p})})]},s.key)}if("Consent"===s.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(s.key,e?"true":"false"),label:s.consentText??s.label,...void 0===c?{}:{error:c},disabled:p},s.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{j.current[s.key]=e},label:s.label,..."string"==typeof s.placeholder?{placeholder:s.placeholder}:{},value:l,onChangeText:e=>setValue(s.key,e),..."number"==typeof s.maxLength?{maxLength:s.maxLength}:{},showCounter:!1,required:s.required,...void 0===c?{}:{error:c},...s.required?{}:{help:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.inputOptional})},labelMode:"top",disabled:p,type:s.secret?"password":"LongText"===s.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[s.type]??"default",..."Email"===s.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[s.type]?{}:{autoComplete:AUTO_COMPLETE[s.type]}},s.key);if(!("Otp"===s.verify&&("Email"===s.type||"Phone"===s.type)))return u;const m=f[s.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[u,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async i=>{if("Otp"===i.verify)try{await t.sendOtp(e.requestId,{fieldKey:i.key,value:(n[i.key]??"").trim()}),h(e=>({...e,[i.key]:"sent"}))}catch{h(e=>({...e,[i.key]:"failed"}))}})(s)},testID:`otp-send-${s.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:a.inputEnterCode,value:b[s.key]??"",onChangeText:e=>_(t=>({...t,[s.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"failed"===m?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===m?a.inputCodeFailed:a.inputCodeSent}):null]})]},s.key)}),""!==u?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?a.inputSubmitting:e.submitLabel,loading:p,disabled:p||w,onPress:()=>{(async()=>{if(w)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const s="true"===e;t.required&&!s&&(i[t.key]=a.inputConsentRequired),r[t.key]=s?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const s=selectedIds(e);t.required&&0===s.length&&(i[t.key]=a.inputRequired),r[t.key]=JSON.stringify(s)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=a.inputRequired),r[t.key]=e;else{const s=t.secret?e:e.trim();t.required&&""===s&&(i[t.key]=a.inputRequired),r[t.key]=s}}const s={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(b[t.key]??"").trim();""===e&&(i[t.key]=a.inputRequired),s[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&S(t))}m(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(s).length>0?s:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(a.errorGeneric)}m(!1)})()}}),w?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.attachmentUploading}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,q?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:a.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]}),e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",...(0,_chatShared.webProps)({role:"paragraph"}),children:a.typeAnswer}):null]})})}function InputRequestPart({part:e,turn:t,pickAttachments:i}){return"Answered"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:e,turn:t,pickAttachments:i},e.requestId)}
@@ -1 +1 @@
1
- "use strict";import{showsCaptchaNote}from"@webority/chat-core";import{Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{openExternalUrl,webProps}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>openExternalUrl(e);export function ChatFooter({chat:e,labels:o}){const r=useTheme(),t=e.profile;if(!t)return null;const i=t.footer.disclaimer||o.disclaimer,a=t.footer.privacyUrl,n=t.footer.assuranceText,l=t.footer.privacyText,c=showsCaptchaNote(t);return Boolean(i)||Boolean(l)||Boolean(a)||Boolean(n)||c?_jsxs(View,{style:{gap:r.space.xxs,alignItems:"center"},...webProps({role:"paragraph"}),children:[i?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:i}):null,l?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:l}):null,a?_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(a),children:o.footerPrivacy}):null,n?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:n}):null,c?_jsxs(Text,{variant:"caption",color:"tertiary",align:"center",children:[o.captchaNote," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:o.captchaPrivacy})," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:o.captchaTerms})]}):null]}):null}
1
+ "use strict";import{showsCaptchaNote}from"@webority/chat-core";import{Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{openExternalUrl,webProps}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>openExternalUrl(e);export function ChatFooter({chat:e,labels:r}){const t=useTheme(),i=e.profile;if(!i)return null;const o=i.footer.disclaimer||r.disclaimer,a=i.footer.privacyUrl,n=i.footer.assuranceText,c=i.footer.privacyText,s=showsCaptchaNote(i);if(!(Boolean(o)||Boolean(c)||Boolean(a)||Boolean(n)||s))return null;const l=[];return o&&l.push(_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:o},"disclaimer")),(c||a)&&l.push(_jsxs(Text,{variant:"caption",color:"tertiary",align:"center",children:[c,c&&a?" ":null,a?_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(a),children:r.footerPrivacy}):null]},"privacy")),n&&l.push(_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:n},"assurance")),s&&l.push(_jsxs(Text,{variant:"caption",color:"tertiary",align:"center",children:[r.captchaNote," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:r.captchaPrivacy})," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:r.captchaTerms})]},"captcha")),_jsx(View,{style:{gap:t.space.xxs,alignItems:"center",flexDirection:"row",flexWrap:"wrap",justifyContent:"center"},...webProps({role:"paragraph"}),children:l.flatMap((e,r)=>r?[_jsx(Text,{variant:"caption",color:"tertiary",accessibilityElementsHidden:!0,importantForAccessibility:"no",...webProps({"aria-hidden":!0}),children:"·"},`sep-${e.key}`),e]:[e])})}
@@ -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??t.panelTitle,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.panelTitle,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}),T?null:_jsx(ChatLiveBar,{chat:e,labels:t,testID:`${v}-live`}),_jsx(ChatReveal,{plan:k.reveal.body,flex:!0,children:_jsx(View,{style:{flex:1},children:P})}),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`})})]})})}
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??t.panelTitle,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.panelTitle,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`})})]})})}
@@ -1 +1 @@
1
- "use strict";import{buildTranscript,messagePlainText}from"@webority/chat-core";import{copyText}from"@webority/mobile-core/clipboard";import{Button,IconButton,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{webProps}from"./chatShared.js";import{ReadAloudButton}from"./ReadAloudButton.js";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);export function ChatMessageActions({chat:e,message:t,labels:s,isLast:a,isLastVisitor:i,testID:r}){const n=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),m=useRef(null),p=useTranscriptActions(e,s),d=useMemo(()=>TEXT_AUTHORS.has(t.author.kind)&&buildTranscript([t],{labels:s,title:null,figureText:!1,...void 0===e.profile?.assistant.name?{}:{assistantName:e.profile.assistant.name}}).entries.length>0,[t,s,e.profile]);if(useEffect(()=>()=>{null!==m.current&&clearTimeout(m.current)},[]),t.streaming)return null;const g=messagePlainText(t.parts),h=TEXT_AUTHORS.has(t.author.kind)&&""!==g,f=t.stored&&RATED_AUTHORS.has(t.author.kind),x=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==messagePlainText(t.parts).trim(),T=a&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),b=i&&t.stored&&e.features.Edit&&!e.streaming&&!e.thinking,save=async s=>{try{await e.rate(t.id,s),u("saved")}catch{u("failed")}};return h&&e.features.Copy||d&&e.features.Share&&p.canShare||x||T||b||f&&e.features.Rating?_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[h&&e.features.Copy?_jsx(Button,{label:o?s.copied:s.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await copyText(g)&&(l(!0),null!==m.current&&clearTimeout(m.current),m.current=setTimeout(()=>l(!1),2e3))})()},testID:`${r}-copy`}):null,d&&e.features.Share&&p.canShare?_jsx(Button,{label:s.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{p.shareReply(t)},testID:`${r}-share`}):null,x?_jsx(ReadAloudButton,{chat:e,message:t,labels:s}):null,T?_jsx(Button,{label:s.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${r}-regenerate`}):null,b?_jsx(Button,{label:s.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${r}-edit`}):null,f&&e.features.Rating?_jsxs(_Fragment,{children:[_jsxs(View,{accessibilityRole:"summary",accessibilityLabel:s.rating,...webProps({role:"group","aria-label":`${s.rateUp} / ${s.rateDown}`}),style:{flexDirection:"row",alignItems:"center",gap:n.space.xs},children:[_jsx(IconButton,{icon:"like",accessibilityLabel:s.rateUp,tone:"neutral",size:"sm",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{checked:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${r}-rate-up`}),_jsx(IconButton,{icon:"dislike",accessibilityLabel:s.rateDown,tone:"neutral",size:"sm",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{checked:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${r}-rate-down`})]}),"failed"===c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.ratingFailed}):null,"saved"===c?_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:s.rated}):null]}):null,null!==p.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:p.notice}):null]}):null}
1
+ "use strict";import{buildTranscript,messagePlainText}from"@webority/chat-core";import{copyText}from"@webority/mobile-core/clipboard";import{Button,IconButton,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{webProps}from"./chatShared.js";import{ReadAloudButton}from"./ReadAloudButton.js";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);export function ChatMessageActions({chat:e,message:t,labels:s,isLast:a,isLastVisitor:i,testID:r}){const n=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),m=useRef(null),p=useTranscriptActions(e,s),d=useMemo(()=>TEXT_AUTHORS.has(t.author.kind)&&buildTranscript([t],{labels:s,title:null,figureText:!1,...void 0===e.profile?.assistant.name?{}:{assistantName:e.profile.assistant.name}}).entries.length>0,[t,s,e.profile]);if(useEffect(()=>()=>{null!==m.current&&clearTimeout(m.current)},[]),t.streaming)return null;const g=messagePlainText(t.parts),h=TEXT_AUTHORS.has(t.author.kind)&&""!==g,f=t.stored&&RATED_AUTHORS.has(t.author.kind),x=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==messagePlainText(t.parts).trim(),T=a&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),b=i&&t.stored&&e.features.Edit&&!e.streaming&&!e.thinking,save=async s=>{try{await e.rate(t.id,s),u("saved")}catch{u("failed")}};return h&&e.features.Copy||d&&e.features.Share&&p.canShare||x||T||b||f&&e.features.Rating?_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[h&&e.features.Copy?_jsx(Button,{label:o?s.copied:s.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await copyText(g)&&(l(!0),null!==m.current&&clearTimeout(m.current),m.current=setTimeout(()=>l(!1),2e3))})()},testID:`${r}-copy`}):null,x?_jsx(ReadAloudButton,{chat:e,message:t,labels:s}):null,d&&e.features.Share&&p.canShare?_jsx(Button,{label:s.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{p.shareReply(t)},testID:`${r}-share`}):null,T?_jsx(Button,{label:s.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${r}-regenerate`}):null,b?_jsx(Button,{label:s.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${r}-edit`}):null,f&&e.features.Rating?_jsxs(_Fragment,{children:[_jsxs(View,{accessibilityRole:"summary",accessibilityLabel:s.rating,...webProps({role:"group","aria-label":`${s.rateUp} / ${s.rateDown}`}),style:{flexDirection:"row",alignItems:"center",gap:n.space.xs},children:[_jsx(IconButton,{icon:"like",accessibilityLabel:s.rateUp,tone:"neutral",size:"sm",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{checked:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${r}-rate-up`}),_jsx(IconButton,{icon:"dislike",accessibilityLabel:s.rateDown,tone:"neutral",size:"sm",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{checked:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${r}-rate-down`})]}),"failed"===c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.ratingFailed}):null,"saved"===c?_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:s.rated}):null]}):null,null!==p.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:p.notice}):null]}):null}
@@ -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"},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:T,expressive:k,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),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,S=t.author.displayName||s.agent,I=(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,N=C?[C,...I]:I,P=messagePlainText(t.parts),V=_jsx(MessageBubble,{side:"theirs",...M?{}:{author:t.author.displayName||(e.profile?.assistant.name??s.assistant)},text:M?`${s.agentSays(S)} ${P}`:P,streaming:t.streaming,groupPosition:i,footer:R,testID:b,children:N});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:T?void 0:{opacity:0},children:_jsx(ReplyRing,{active:k&&t.streaming&&T,reduced:v,children:_jsx(Avatar,{size:"xs",name:F,...T?{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=!0,expressive:l=!1,pickAttachments:d,onOpenAttachment:c,onOpenTarget:u,onNavigate:p,openTicket:g,handoffHosts:m,resolveLink:h,focusComposer:f,keyboardAware:y,keyboardOffset:x,empty:T,style:k,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,_]),S=useMemo(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return M?[...t,M]:t},[e.messages,M]),I=e.messages[e.messages.length-1]?.id,C=useRef(new Map),N=useRef(null);useEffect(()=>{if(null!==N.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||N.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;N.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 N.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,D="daily_limit"===$?.code,E=null!==$&&/feature_off$/.test($.code),O=D&&$?.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:D?void 0:"alert",accessibilityLiveRegion:D?"polite":void 0,children:`${$.message}${O}`}:{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||D||E?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:S,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:r})=>_jsxs(View,{role:"listitem",children:[MINE.has(s.author.kind)?_jsx(Text,{style:visuallyHidden,children:`${t.you}: `}):null,_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===I,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:o,avatarStart: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:T,ItemSeparatorComponent:TurnGap,...void 0===y?{}:{keyboardAware:y},...void 0===x?{}:{keyboardOffset:x},..."web"===Platform.OS?{}:{accessibilityLabel:t.thread},accessibilityRole:"list",style:k,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=!0,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,D="daily_limit"===$?.code,E=null!==$&&/feature_off$/.test($.code),O=D&&$?.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:D?void 0:"alert",accessibilityLiveRegion:D?"polite":void 0,children:`${$.message}${O}`}:{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||D||E?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:o,avatarStart: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 +1 @@
1
- "use strict";import{useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DOT=6,LIFT_PX=4,CYCLE_MS=1200,HALF_MS=300,STEP_MS=140,STILL_OPACITY=[1,.65,.3],DOT_INDEXES=[0,1,2];export function TypingPill({motion:e,mark:t}){const i=useTheme(),s=useMemo(()=>buildStyles(i),[i]),o=useReducedMotion(),r="Reduced"===e||o;return _jsxs(View,{style:s.pill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:[t,_jsx(View,{style:s.dots,children:DOT_INDEXES.map(e=>_jsx(Dot,{index:e,reduced:r,color:i.colors["text-subtle"],size:6},e))})]})}const Dot=({index:e,reduced:t,color:i,size:s})=>{const o=useRef(new Animated.Value(0)).current;useEffect(()=>{if(t)return void o.setValue(0);const i=Animated.loop(Animated.sequence([Animated.delay(140*e),Animated.timing(o,{toValue:1,duration:300,useNativeDriver:!0}),Animated.timing(o,{toValue:0,duration:300,useNativeDriver:!0}),Animated.delay(600-140*e)]));return i.start(),()=>i.stop()},[o,e,t]);const r={width:s,height:s,borderRadius:s/2,backgroundColor:i};if(t)return _jsx(View,{style:[r,{opacity:STILL_OPACITY[e]}]});const n=o.interpolate({inputRange:[0,1],outputRange:[0,-4]});return _jsx(Animated.View,{style:[r,{transform:[{translateY:n}]}]})},buildStyles=e=>StyleSheet.create({pill:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.pill,paddingHorizontal:e.space.md,paddingVertical:e.space.sm},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});
1
+ "use strict";import{useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef}from"react";import{Animated,StyleSheet,View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DOT=6,LIFT_PX=4,CYCLE_MS=1200,HALF_MS=300,STEP_MS=140,STILL_OPACITY=[1,.65,.3],DOT_INDEXES=[0,1,2];export function TypingPill({motion:e,mark:t}){const i=useTheme(),s=useMemo(()=>buildStyles(i),[i]),o=useReducedMotion(),r="Reduced"===e||o;return _jsxs(View,{style:s.pill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",testID:"chat-typing-pill",children:[t,_jsx(View,{style:s.dots,children:DOT_INDEXES.map(e=>_jsx(Dot,{index:e,reduced:r,color:i.colors["text-subtle"],size:6},e))})]})}const Dot=({index:e,reduced:t,color:i,size:s})=>{const o=useRef(new Animated.Value(0)).current;useEffect(()=>{if(t)return void o.setValue(0);const i=Animated.loop(Animated.sequence([Animated.delay(140*e),Animated.timing(o,{toValue:1,duration:300,useNativeDriver:!0}),Animated.timing(o,{toValue:0,duration:300,useNativeDriver:!0}),Animated.delay(600-140*e)]));return i.start(),()=>i.stop()},[o,e,t]);const r={width:s,height:s,borderRadius:s/2,backgroundColor:i};if(t)return _jsx(View,{style:[r,{opacity:STILL_OPACITY[e]}]});const n=o.interpolate({inputRange:[0,1],outputRange:[0,-4]});return _jsx(Animated.View,{style:[r,{transform:[{translateY:n}]}]})},buildStyles=e=>StyleSheet.create({pill:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.pill,paddingHorizontal:e.space.md,paddingVertical:e.space.sm},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});
@@ -1 +1 @@
1
- "use strict";import{ChatApiError,formatChatDate}from"@webority/chat-core";import{parseInline}from"@webority/markdown-core";import{Logger}from"@webority/mobile-core";import{Button,Card,OptionSheet,Text,useTheme}from"@webority/mobile-ui";import{useState}from"react";import{Text as RNText,View}from"react-native";import{openExternalUrl,WEB_STRONG,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https?:\/\//i,inlineNodes=(e,t)=>e.map(e=>{if("text"===e.type||"code"===e.type||"citation"===e.type)return e.text;if("link"===e.type){const n=inlineNodes(e.children,t);return SAFE_LINK.test(e.href)?_jsx(RNText,{accessibilityRole:"link",style:{color:t.colors.link,textDecorationLine:"underline"},onPress:()=>openExternalUrl(e.href),children:n},e.key):_jsx(RNText,{children:n},e.key)}if("image"===e.type)return null;const n="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return _jsx(RNText,{style:n,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${formatChatDate(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat(formatChatDate(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const n=useTheme(),{labels:i,features:r}=t,[a,o]=useState(null),[l,s]=useState(""),[c,d]=useState(!1),run=async(e,t)=>{o(e),s("");try{await t()}catch(t){Logger.error(`[chat] action ${e} failed`,t),s(t instanceof ChatApiError&&""!==t.message?t.message:i.actionFailed),o(null)}},p=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=r.LeadRecap&&e.actionKind===LEAD_CAPTURE,u=m&&p.length>0,x=m&&e.confirmLabel||i.actionConfirm,h=m&&e.rejectLabel||i.actionDismiss,f=null!==a;return _jsxs(Card,{variant:"outline",padding:"sm",children:[_jsxs(View,{style:{gap:n.space.sm},children:[_jsx(Text,{variant:"label",...WEB_STRONG,children:e.title}),e.lines.map(e=>{if(!m)return _jsx(Text,{variant:"bodySmall",children:e},e);const{term:t,detail:i}=splitLine(e);return _jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:n.space.xs},children:[_jsx(Text,{variant:"label",...webProps({role:"term"}),children:t}),null!==i?_jsx(Text,{variant:"bodySmall",...webProps({role:"definition"}),children:i}):null]},e)}),m&&e.consentText?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:inlineNodes(parseInline(e.consentText),n)}):null,"Pending"===e.state?_jsxs(_Fragment,{children:[""!==l?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:l}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:n.space.sm},children:[_jsx(Button,{label:"confirm"===a?i.actionWorking:x,loading:"confirm"===a,disabled:f,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),_jsx(Button,{label:h,variant:"ghost",disabled:f,onPress:()=>{run("reject",()=>t.rejectAction(e.actionId))}})]})]}):_jsx(Text,{variant:"bodySmall",color:"Done"===e.state||"Confirmed"===e.state||"Repeat"===e.state?"success":"secondary",...webProps({role:"paragraph"}),children:statusLine(e,i)}),u?_jsx(Button,{label:i.editSomething,variant:"ghost",disabled:f||"Pending"!==e.state,onPress:()=>d(!0)}):null,e.note?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:e.note}):null]}),u?_jsx(OptionSheet,{open:c,onClose:()=>d(!1),title:i.editSomething,options:p,onChange:(e,n)=>{d(!1),t.chooseQuickReply({id:`lead.edit:${String(n.value)}`,label:n.label,action:"Send",target:null,navigateAfterMs:null,icon:null,variant:null})}}):null]})}export function ActionPart({part:e,turn:t}){return _jsx(ActionBody,{part:e,turn:t},e.actionId)}
1
+ "use strict";import{ChatApiError,formatChatDate}from"@webority/chat-core";import{parseInline}from"@webority/markdown-core";import{Logger}from"@webority/mobile-core";import{Button,Card,OptionSheet,Text,useTheme}from"@webority/mobile-ui";import{useState}from"react";import{Text as RNText,View}from"react-native";import{openExternalUrl,WEB_STRONG,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https?:\/\//i,inlineNodes=(e,t)=>e.map(e=>{if("text"===e.type||"code"===e.type||"citation"===e.type)return e.text;if("link"===e.type){const n=inlineNodes(e.children,t);return SAFE_LINK.test(e.href)?_jsx(RNText,{accessibilityRole:"link",style:{color:t.colors.link,textDecorationLine:"underline"},onPress:()=>openExternalUrl(e.href),children:n},e.key):_jsx(RNText,{children:n},e.key)}if("image"===e.type)return null;const n="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return _jsx(RNText,{style:n,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${formatChatDate(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat(formatChatDate(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const n=useTheme(),{labels:i,features:r}=t,[a,o]=useState(null),[l,s]=useState(""),[c,d]=useState(!1),run=async(e,t)=>{o(e),s("");try{await t()}catch(t){Logger.error(`[chat] action ${e} failed`,t),s(t instanceof ChatApiError&&""!==t.message?t.message:i.actionFailed),o(null)}},p=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=r.LeadRecap&&e.actionKind===LEAD_CAPTURE,u=m&&p.length>0,x=m&&e.confirmLabel||i.actionConfirm,h=m&&e.rejectLabel||i.actionDismiss,f=null!==a;return _jsxs(Card,{variant:"outline",padding:"sm",children:[_jsxs(View,{style:{gap:n.space.sm},children:[_jsx(Text,{variant:"label",...WEB_STRONG,children:e.title}),e.lines.map(e=>{if(!m)return _jsx(Text,{variant:"bodySmall",children:e},e);const{term:t,detail:i}=splitLine(e);return _jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:n.space.xs},children:[_jsx(Text,{variant:"label",...webProps({role:"term"}),children:t}),null!==i?_jsx(Text,{variant:"bodySmall",...webProps({role:"definition"}),children:i}):null]},e)}),m&&e.consentText?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:inlineNodes(parseInline(e.consentText),n)}):null,e.note?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:e.note}):null,"Pending"===e.state?_jsxs(_Fragment,{children:[""!==l?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:l}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:n.space.sm},children:[_jsx(Button,{label:"confirm"===a?i.actionWorking:x,loading:"confirm"===a,disabled:f,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),_jsx(Button,{label:h,variant:"ghost",disabled:f,onPress:()=>{run("reject",()=>t.rejectAction(e.actionId))}})]})]}):_jsx(Text,{variant:"bodySmall",color:"Done"===e.state||"Confirmed"===e.state||"Repeat"===e.state?"success":"secondary",...webProps({role:"paragraph"}),children:statusLine(e,i)}),u?_jsx(Button,{label:i.editSomething,variant:"ghost",disabled:f||"Pending"!==e.state,onPress:()=>d(!0)}):null]}),u?_jsx(OptionSheet,{open:c,onClose:()=>d(!1),title:i.editSomething,options:p,onChange:(e,n)=>{d(!1),t.chooseQuickReply({id:`lead.edit:${String(n.value)}`,label:n.label,action:"Send",target:null,navigateAfterMs:null,icon:null,variant:null})}}):null]})}export function ActionPart({part:e,turn:t}){return _jsx(ActionBody,{part:e,turn:t},e.actionId)}
@@ -1 +1 @@
1
- "use strict";import{Button,Card,Checkbox,Chip,ChoiceGroup,Input,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useRef,useState}from"react";import{View}from"react-native";import{focusForAccessibility,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const fileNameOf=(e,t)=>{const r="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof r&&""!==r?r:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` (${t.inputOptional})`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:r}){const i=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,b]=useState({}),[h,m]=useState({}),[x,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),w=useRef(!1),S=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const r=g.current[e];r&&focusForAccessibility(r)},[]);useEffect(()=>{if(p||!w.current)return;w.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(r=>({...r,[e]:t})),commitUploads=e=>{j.current=e,b(e)},patchUpload=(e,t)=>{const r=j.current[e];r&&commitUploads({...j.current,[e]:{...r,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,T=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},C=a.LeadShortcuts,O=e.fields[0];if(C&&1===e.fields.length&&void 0===O)throw new Error("A one-field form has no field.");const R=C&&1===e.fields.length&&void 0!==O&&!O.required,E=C&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...webProps({role:"form","aria-label":e.title||e.submitLabel}),children:_jsxs(View,{style:{gap:i.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",...webProps({"aria-level":3}),children:e.title}):null,e.allowTyped?_jsx(Text,{variant:"caption",color:"secondary",children:s.typeAnswer}):null,e.fields.map(a=>{const l=n[a.key]??"",c=o[a.key];if("File"===a.type){const e=f[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{...webProps({role:"group","aria-label":a.label}),children:e?_jsxs(View,{style:{gap:i.space.xxs},children:[_jsx(Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=a.key,commitUploads(Object.fromEntries(Object.entries(j.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:s.inputRemoveFile}}),"Uploading"===e.status?_jsx(ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:s.attachmentUploading,height:4}):null,"Failed"===e.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:s.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===r,onPress:()=>{(async e=>{if(!r)return;let i;try{i=await r(e.accept??void 0)}catch{return void d(s.errorGeneric)}const a=i[0];if(!a)return;_.current+=1;const n=_.current;commitUploads({...j.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const r=await t.uploadInputFile(a,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,r),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(a)}})})}),c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},a.key)}if("MultiChoice"===a.type){const e=(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},...webProps({role:"group","aria-label":a.label}),children:_jsx(ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(a.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Choice"===a.type||"TimeSlot"===a.type){const e="TimeSlot"===a.type?(a.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},children:_jsx(ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Consent"===a.type)return _jsx(Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,...void 0===c?{}:{error:c},disabled:p},a.key);const u=_jsx(Input,{ref:e=>{v.current[a.key]=e},label:a.label,..."string"==typeof a.placeholder?{placeholder:a.placeholder}:{},value:l,onChangeText:e=>setValue(a.key,e),..."number"==typeof a.maxLength?{maxLength:a.maxLength}:{},required:a.required,...void 0===c?{}:{error:c},...a.required?{}:{help:s.inputOptional},labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",..."Email"===a.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[a.type]?{}:{autoComplete:AUTO_COMPLETE[a.type]}},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const y=x[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[u,_jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Button,{label:s.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async r=>{if("Otp"===r.verify)try{await t.sendOtp(e.requestId,{fieldKey:r.key,value:(n[r.key]??"").trim()}),k(e=>({...e,[r.key]:"sent"}))}catch{k(e=>({...e,[r.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),_jsx(Input,{label:s.inputEnterCode,value:h[a.key]??"",onChangeText:e=>m(t=>({...t,[a.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),y?_jsx(Text,{variant:"caption",color:"failed"===y?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===y?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.key)}),""!==u?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[_jsx(Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||T,onPress:()=>{(async()=>{if(T)return;const r={},i={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(r[t.key]=s.inputConsentRequired),i[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(r[t.key]=s.inputRequired),i[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(r[t.key]=s.inputRequired),i[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(h[t.key]??"").trim();""===e&&(r[t.key]=s.inputRequired),a[t.key]=e}if(c(r),Object.keys(r).length>0){const t=firstErrorKey(e.fields,r);return void(void 0!==t&&S(t))}y(!0),d("");try{const r=await t.answerInput(e.requestId,i,Object.keys(a).length>0?a:null);if(r.ok)return;c(r.errors),w.current=!0,d(r.message??"")}catch{d(s.errorGeneric)}y(!1)})()}}),T?_jsx(Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,R?_jsx(Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,E?_jsx(Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]})]})})}export function InputRequestPart({part:e,turn:t,pickAttachments:r}){return"Answered"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):_jsx(OpenRequest,{part:e,turn:t,pickAttachments:r},e.requestId)}
1
+ "use strict";import{Button,Card,Checkbox,Chip,ChoiceGroup,Input,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useRef,useState}from"react";import{View}from"react-native";import{focusForAccessibility,webProps}from"../chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const fileNameOf=(e,t)=>{const r="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof r&&""!==r?r:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` ${t.inputOptional}`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:r}){const i=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,b]=useState({}),[h,m]=useState({}),[x,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),w=useRef(!1),T=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const r=g.current[e];r&&focusForAccessibility(r)},[]);useEffect(()=>{if(p||!w.current)return;w.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&T(t)},[p,o,e.fields,T]);const setValue=(e,t)=>l(r=>({...r,[e]:t})),commitUploads=e=>{j.current=e,b(e)},patchUpload=(e,t)=>{const r=j.current[e];r&&commitUploads({...j.current,[e]:{...r,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,C=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},S=a.LeadShortcuts,O=e.fields[0];if(S&&1===e.fields.length&&void 0===O)throw new Error("A one-field form has no field.");const R=S&&1===e.fields.length&&void 0!==O&&!O.required,E=S&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},...webProps({role:"form","aria-label":e.title||e.submitLabel}),children:_jsxs(View,{style:{gap:i.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",...webProps({"aria-level":3}),children:e.title}):null,e.fields.map(a=>{const l=n[a.key]??"",c=o[a.key];if("File"===a.type){const e=f[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{...webProps({role:"group","aria-label":a.label}),children:e?_jsxs(View,{style:{gap:i.space.xxs},children:[_jsx(Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=a.key,commitUploads(Object.fromEntries(Object.entries(j.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:s.inputRemoveFile}}),"Uploading"===e.status?_jsx(ProgressBar,{..."number"==typeof e.progress?{progress:e.progress}:{},label:s.attachmentUploading,height:4}):null,"Failed"===e.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:s.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===r,onPress:()=>{(async e=>{if(!r)return;let i;try{i=await r(e.accept??void 0)}catch{return void d(s.errorGeneric)}const a=i[0];if(!a)return;_.current+=1;const n=_.current;commitUploads({...j.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const r=await t.uploadInputFile(a,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,r),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(a)}})})}),c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},a.key)}if("MultiChoice"===a.type){const e=(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},...webProps({role:"group","aria-label":a.label}),children:_jsx(ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(a.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Choice"===a.type||"TimeSlot"===a.type){const e="TimeSlot"===a.type?(a.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(a.options??[]).map(e=>({label:e.label,value:e.id}));return _jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),_jsx(View,{ref:e=>{g.current[a.key]=e},children:_jsx(ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,...void 0===c?{}:{error:c},disabled:p})})]},a.key)}if("Consent"===a.type)return _jsx(Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,...void 0===c?{}:{error:c},disabled:p},a.key);const u=_jsx(Input,{ref:e=>{v.current[a.key]=e},label:a.label,..."string"==typeof a.placeholder?{placeholder:a.placeholder}:{},value:l,onChangeText:e=>setValue(a.key,e),..."number"==typeof a.maxLength?{maxLength:a.maxLength}:{},showCounter:!1,required:a.required,...void 0===c?{}:{error:c},...a.required?{}:{help:_jsx(Text,{variant:"caption",color:"secondary",children:s.inputOptional})},labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",..."Email"===a.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[a.type]?{}:{autoComplete:AUTO_COMPLETE[a.type]}},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const y=x[a.key];return _jsxs(View,{style:{gap:i.space.xs},children:[u,_jsxs(View,{style:{gap:i.space.xs},children:[_jsx(Button,{label:s.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async r=>{if("Otp"===r.verify)try{await t.sendOtp(e.requestId,{fieldKey:r.key,value:(n[r.key]??"").trim()}),k(e=>({...e,[r.key]:"sent"}))}catch{k(e=>({...e,[r.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),_jsx(Input,{label:s.inputEnterCode,value:h[a.key]??"",onChangeText:e=>m(t=>({...t,[a.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),y?_jsx(Text,{variant:"caption",color:"failed"===y?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===y?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.key)}),""!==u?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[_jsx(Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||C,onPress:()=>{(async()=>{if(C)return;const r={},i={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(r[t.key]=s.inputConsentRequired),i[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(r[t.key]=s.inputRequired),i[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(r[t.key]=s.inputRequired),i[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(r[t.key]=s.inputRequired),i[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(h[t.key]??"").trim();""===e&&(r[t.key]=s.inputRequired),a[t.key]=e}if(c(r),Object.keys(r).length>0){const t=firstErrorKey(e.fields,r);return void(void 0!==t&&T(t))}y(!0),d("");try{const r=await t.answerInput(e.requestId,i,Object.keys(a).length>0?a:null);if(r.ok)return;c(r.errors),w.current=!0,d(r.message??"")}catch{d(s.errorGeneric)}y(!1)})()}}),C?_jsx(Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,R?_jsx(Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,E?_jsx(Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]}),e.allowTyped?_jsx(Text,{variant:"caption",color:"secondary",...webProps({role:"paragraph"}),children:s.typeAnswer}):null]})})}export function InputRequestPart({part:e,turn:t,pickAttachments:r}){return"Answered"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):_jsx(OpenRequest,{part:e,turn:t,pickAttachments:r},e.requestId)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-chat",
3
- "version": "0.146.1",
3
+ "version": "0.147.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.146.1",
46
- "@webority/markdown-core": "^0.164.0",
47
- "@webority/mobile-core": "^0.164.0",
48
- "@webority/mobile-ui": "^0.164.0",
45
+ "@webority/chat-core": "0.147.0",
46
+ "@webority/markdown-core": "^0.165.0",
47
+ "@webority/mobile-core": "^0.165.0",
48
+ "@webority/mobile-ui": "^0.165.0",
49
49
  "expo-audio": ">=58.0.0",
50
50
  "expo-file-system": ">=58.0.0",
51
51
  "react": "^19.3.0",
@@ -95,14 +95,14 @@
95
95
  "@react-native/babel-preset": "0.88.1",
96
96
  "@react-native/jest-preset": "0.88.1",
97
97
  "@react-native/metro-config": "0.88.1",
98
- "@testing-library/react-native": "12.9.0",
98
+ "@testing-library/react-native": "14.1.0",
99
99
  "@types/jest": "29.5.14",
100
100
  "@types/react": "19.3.0",
101
- "@webority/canvas-kit": "0.164.0",
102
- "@webority/chat-core": "0.146.1",
103
- "@webority/markdown-core": "0.164.0",
104
- "@webority/mobile-core": "0.164.0",
105
- "@webority/mobile-ui": "0.164.0",
101
+ "@webority/canvas-kit": "0.165.0",
102
+ "@webority/chat-core": "0.147.0",
103
+ "@webority/markdown-core": "0.165.0",
104
+ "@webority/mobile-core": "0.165.0",
105
+ "@webority/mobile-ui": "0.165.0",
106
106
  "babel-jest": "29.7.0",
107
107
  "expo": "58.0.23",
108
108
  "expo-application": "58.1.2",
@@ -126,8 +126,8 @@
126
126
  "react-native-safe-area-context": "5.11.1",
127
127
  "react-native-svg": "15.16.0",
128
128
  "react-native-worklets": "0.13.0",
129
- "react-test-renderer": "19.3.0",
130
129
  "terser": "5.49.1",
130
+ "test-renderer": "1.3.1",
131
131
  "typescript": "7.0.2"
132
132
  },
133
133
  "scripts": {