@webority/mobile-chat 0.136.0 → 0.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/ChatFrame.js +1 -1
- package/lib/commonjs/ChatLauncher.js +1 -1
- package/lib/commonjs/ChatLiveBar.js +1 -1
- package/lib/commonjs/ChatMessageActions.js +1 -1
- package/lib/commonjs/ChatSheet.js +1 -1
- package/lib/commonjs/ChatThread.js +1 -1
- package/lib/commonjs/chatShared.js +1 -1
- package/lib/commonjs/loaders/ReplyRing.js +1 -0
- package/lib/commonjs/renderers/ActionPart.js +1 -1
- package/lib/commonjs/renderers/InputRequestPart.js +1 -1
- package/lib/commonjs/renderers/QuickRepliesPart.js +1 -1
- package/lib/commonjs/renderers/TextPart.js +1 -1
- package/lib/commonjs/speech/azureSpeech.js +1 -1
- package/lib/commonjs/useChat.js +1 -1
- package/lib/commonjs/useTranscriptActions.js +1 -1
- package/lib/module/ChatFrame.js +1 -1
- package/lib/module/ChatLauncher.js +1 -1
- package/lib/module/ChatLiveBar.js +1 -1
- package/lib/module/ChatMessageActions.js +1 -1
- package/lib/module/ChatSheet.js +1 -1
- package/lib/module/ChatThread.js +1 -1
- package/lib/module/chatShared.js +1 -1
- package/lib/module/loaders/ReplyRing.js +1 -0
- package/lib/module/renderers/ActionPart.js +1 -1
- package/lib/module/renderers/InputRequestPart.js +1 -1
- package/lib/module/renderers/QuickRepliesPart.js +1 -1
- package/lib/module/renderers/TextPart.js +1 -1
- package/lib/module/speech/azureSpeech.js +1 -1
- package/lib/module/useChat.js +1 -1
- package/lib/module/useTranscriptActions.js +1 -1
- package/lib/typescript/commonjs/ChatComposer.d.ts +3 -2
- package/lib/typescript/commonjs/ChatFrame.d.ts +3 -3
- package/lib/typescript/commonjs/ChatLauncher.d.ts +3 -1
- package/lib/typescript/commonjs/ChatThread.d.ts +6 -4
- package/lib/typescript/commonjs/chatShared.d.ts +1 -0
- package/lib/typescript/commonjs/loaders/ReplyRing.d.ts +9 -0
- package/lib/typescript/commonjs/types.d.ts +6 -1
- package/lib/typescript/commonjs/useChat.d.ts +3 -1
- package/lib/typescript/module/ChatComposer.d.ts +3 -2
- package/lib/typescript/module/ChatFrame.d.ts +3 -3
- package/lib/typescript/module/ChatLauncher.d.ts +3 -1
- package/lib/typescript/module/ChatThread.d.ts +6 -4
- package/lib/typescript/module/chatShared.d.ts +1 -0
- package/lib/typescript/module/loaders/ReplyRing.d.ts +9 -0
- package/lib/typescript/module/types.d.ts +6 -1
- package/lib/typescript/module/useChat.d.ts +3 -1
- package/package.json +12 -11
|
@@ -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"),_useChatHaptics=require("./useChatHaptics.js"),_useChatSound=require("./useChatSound.js"),_jsxRuntime=require("react/jsx-runtime");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)(),
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLauncher=ChatLauncher;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_jsxRuntime=require("react/jsx-runtime");const RISE_MS=900,RISE_DELAY_MS=400,ENTRANCE_MS=800,ENTRANCE_DELAY_MS=1e3,FLOAT_HALF_MS=1600,FLOAT_PX=4,RISE_FROM_PX=116;function entranceStyle(e,t){const range=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:range([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:range([0,1],[0,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[100,0]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[.8,1]})}]};case"BounceIn":return{transform:[{scale:range([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:range([0,.5,1],[0,1,1]),transform:[{scale:range([0,.5,1],[1,1.1,1])}]};case"SpinScale":return{transform:[{rotate:t.interpolate({inputRange:[0,1],outputRange:["-180deg","0deg"]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[0,1]})}]};case"WiggleIn":return{transform:[{translateY:range([0,.4,1],[100,0,0])},{rotate:range([0,.4,.6,.8,1],["-10deg","5deg","-3deg","1deg","0deg"])}]};case"ElasticIn":return{transform:[{scale:range([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}}const OVERSHOOT=new Set(["Rise","SlideUp","SpinScale"]);function ChatLauncher({look:e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLauncher=ChatLauncher;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_reactNativeSafeAreaContext=require("react-native-safe-area-context"),_jsxRuntime=require("react/jsx-runtime");const RISE_MS=900,RISE_DELAY_MS=400,ENTRANCE_MS=800,ENTRANCE_DELAY_MS=1e3,FLOAT_HALF_MS=1600,FLOAT_PX=4,RISE_FROM_PX=116,SHRINK_MS=320,SHRINK_EASING=_reactNative.Easing.bezier(.4,0,.2,1);function entranceStyle(e,t){const range=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:range([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:range([0,1],[0,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[100,0]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[.8,1]})}]};case"BounceIn":return{transform:[{scale:range([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:range([0,.5,1],[0,1,1]),transform:[{scale:range([0,.5,1],[1,1.1,1])}]};case"SpinScale":return{transform:[{rotate:t.interpolate({inputRange:[0,1],outputRange:["-180deg","0deg"]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[0,1]})}]};case"WiggleIn":return{transform:[{translateY:range([0,.4,1],[100,0,0])},{rotate:range([0,.4,.6,.8,1],["-10deg","5deg","-3deg","1deg","0deg"])}]};case"ElasticIn":return{transform:[{scale:range([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}}const OVERSHOOT=new Set(["Rise","SlideUp","SpinScale"]);function ChatLauncher({look:e,hidden:t,label:a,side:n,offsetX:r,offsetY:i,enter:s,reduced:o,mark:u="Icon",avatar:c=null,buttonRef:l,onPress:_,testID:m}){const d=(0,_mobileUi.useTheme)(),p=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),S=e.launcher.entrance,g="Avatar"===u&&c?c:null,v=d.components["floating-action-button"].md.diameter,[N]=(0,_react.useState)(()=>s&&!o&&"None"!==S),f=t&&e.expressive&&!o,R=!o&&!t&&"FloatAndPulse"===e.launcher.idle,[A]=(0,_react.useState)(()=>new _reactNative.Animated.Value(N?0:1)),[E]=(0,_react.useState)(()=>new _reactNative.Animated.Value(0)),[b]=(0,_react.useState)(()=>new _reactNative.Animated.Value(1)),[h,I]=(0,_react.useState)(!1);if((0,_react.useEffect)(()=>{if(!t)return b.setValue(1),void I(!1);if(!f)return;const e=_reactNative.Animated.timing(b,{toValue:0,duration:SHRINK_MS,easing:SHRINK_EASING,useNativeDriver:!0});return e.start(({finished:e})=>{e&&I(!0)}),()=>e.stop()},[t,f,b]),(0,_react.useEffect)(()=>{if(!N)return void A.setValue(1);const e="Rise"===S,t=_reactNative.Animated.timing(A,{toValue:1,duration:e?RISE_MS:ENTRANCE_MS,delay:e?RISE_DELAY_MS:ENTRANCE_DELAY_MS,easing:OVERSHOOT.has(S)?_reactNative.Easing.bezier(.34,e?1.4:1.56,.64,1):_reactNative.Easing.linear,useNativeDriver:!0});return t.start(),()=>t.stop()},[N,S,A]),(0,_react.useEffect)(()=>{if(!R)return void E.setValue(0);const e=_reactNative.Animated.loop(_reactNative.Animated.sequence([_reactNative.Animated.timing(E,{toValue:1,duration:FLOAT_HALF_MS,easing:_reactNative.Easing.inOut(_reactNative.Easing.ease),useNativeDriver:!0}),_reactNative.Animated.timing(E,{toValue:0,duration:FLOAT_HALF_MS,easing:_reactNative.Easing.inOut(_reactNative.Easing.ease),useNativeDriver:!0})]));return e.start(),()=>e.stop()},[R,E]),t&&(!f||h))return null;const x="Pill"===e.launcher.style&&!e.launcher.compact,y=d.space[d.components["floating-action-button"]["edge-offset"]]+r,L={position:"absolute",bottom:i+p.bottom,..."start"===n?{left:y}:{right:y}},M=entranceStyle(S,A);return(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{pointerEvents:"box-none",style:_reactNative.StyleSheet.absoluteFill,children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[L,{opacity:_reactNative.Animated.multiply(M.opacity??1,b),transform:[...M.transform,{scale:b},{translateY:E.interpolate({inputRange:[0,1],outputRange:[0,-FLOAT_PX]})}]}],children:(0,_jsxRuntime.jsx)(_mobileUi.FloatingActionButton,{ref:l,icon:g?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{dimension:v,name:a,source:{uri:g}}):"messages",label:x?a:void 0,collapsed:!x,accessibilityLabel:a,onPress:_,testID:m})})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLiveBar=ChatLiveBar;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLiveBar=ChatLiveBar;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function ChatLiveBar({chat:e,labels:i,testID:t="chat-live-bar"}){const n=(0,_mobileUi.useTheme)();if(!e.features.HumanHandoff||null===e.conversationId)return null;const s=e.conversationState;if("Closed"===s)return null;if("Open"===s){return e.features.HumanHandoff&&e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind)&&!e.streaming&&!e.thinking?(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:n.space.md,paddingVertical:n.space.xs},testID:t,children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.talkToPerson,variant:"soft",size:"sm",leftIcon:"user",loading:e.handoffPending,onPress:()=>{e.requestHandoff()},testID:`${t}-talk`}),null!==e.handoffError?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:i.errorGeneric}):null]}):null}return"Lost"!==e.live?null:(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:n.space.md,paddingVertical:n.space.xs},testID:t,children:(0,_jsxRuntime.jsx)(_mobileUi.Banner,{tone:"warning",message:i.liveLost,actions:[{label:i.retry,onPress:()=>e.resumeLive()}],testID:`${t}-lost`})})}
|
|
@@ -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"),_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)(),[l,o]=(0,_react.useState)(!1),[c,u]=(0,_react.useState)("idle"),
|
|
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"),_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)(),[l,o]=(0,_react.useState)(!1),[c,u]=(0,_react.useState)("idle"),m=(0,_react.useRef)(null),d=(0,_useTranscriptActions.default)(e,i),_=(0,_react.useMemo)(()=>TEXT_AUTHORS.has(t.author.kind)&&(0,_chatCore.buildTranscript)([t],{labels:i,title:null,figureText:!1,assistantName:e.profile?.assistant.name}).entries.length>0,[t,i,e.profile]);if((0,_react.useEffect)(()=>()=>{null!==m.current&&clearTimeout(m.current)},[]),t.streaming)return null;const h=(0,_chatCore.messagePlainText)(t.parts),g=TEXT_AUTHORS.has(t.author.kind)&&""!==h,x=t.stored&&RATED_AUTHORS.has(t.author.kind),p=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==(0,_chatCore.messagePlainText)(t.parts).trim(),b=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 g&&e.features.Copy||_&&e.features.Share&&d.canShare||p||b||R||x&&e.features.Rating?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[g&&e.features.Copy?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:l?i.copied:i.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await(0,_clipboard.copyText)(h)&&(o(!0),null!==m.current&&clearTimeout(m.current),m.current=setTimeout(()=>o(!1),2e3))})()},testID:`${r}-copy`}):null,_&&e.features.Share&&d.canShare?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{d.shareReply(t)},testID:`${r}-share`}):null,p?(0,_jsxRuntime.jsx)(_ReadAloudButton.ReadAloudButton,{chat:e,message:t,labels:i}):null,b?(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,x&&e.features.Rating?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"summary",accessibilityLabel:i.rating,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!==d.notice?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:d.notice}):null]}):null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatSheet=ChatSheet;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatAppearanceScope=require("./ChatAppearanceScope.js"),_ChatFrame=require("./ChatFrame.js"),_ChatLauncher=require("./ChatLauncher.js"),_ChatNudge=require("./ChatNudge.js"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;function ChatSheet({chat:e,labels:t,renderers:r,layoutParts:a,loader:s="Steps",look:n,appearance:o,pickAttachments:c,onOpenAttachment:i,onOpenTarget:u,onNavigate:l,keyboardOffset:h,open:p,defaultOpen:f=!1,onOpenChange:_,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:m,handoffHosts:b,resolveLink:C,conversationId:g,onClose:j,testID:x="chat-sheet"}){const S=(0,_mobileUi.useTheme)(),v=(0,_chatCore.mergeLabels)(t),T=(0,_react.useMemo)(()=>(0,_chatCore.mergeLook)(n),[n]),O=(0,_mobileUi.useReducedMotion)(),k="Reduced"===T.motion||O,R=o?.position??"end",y=void 0!==p,A=y?p:e.open,N=(0,_react.useRef)(null),E=(0,_react.useRef)(!1),F=(0,_react.useRef)(g??null),L=e.setChatVisible,P=(0,_react.useRef)(!1),q=!P.current,[D,I]=(0,_react.useState)(0),U=(0,_react.useRef)(A);(0,_react.useEffect)(()=>{A&&(P.current=!0)},[A]),(0,_react.useEffect)(()=>{A&&!U.current&&I(e=>e+1),U.current=A},[A]),(0,_react.useEffect)(()=>{E.current||(E.current=!0,y||!f||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[y,f,e.profile,e.open,e.session]),(0,_react.useEffect)(()=>{y&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[y,p,e.open,e.session]);const w=(0,_react.useRef)(A);if((0,_react.useEffect)(()=>{w.current&&!A&&(0,_chatShared.focusForAccessibility)(N.current),w.current=A},[A]),(0,_react.useEffect)(()=>{L(A)},[L,A]),(0,_react.useEffect)(()=>{!y&&g&&g!==F.current&&null!==e.profile&&(F.current=g,e.open||(e.session.open({trigger:"manual"}),_?.(!0)))},[y,g,e.profile,e.open,e.session,_]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),_?.(t)},closeSheet=()=>{setOpen(!1),j?.()},M=o?.offsetY??DEFAULT_BOTTOM_OFFSET;return(0,_jsxRuntime.jsx)(_reactNative.View,{testID:x,style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",children:(0,_jsxRuntime.jsxs)(_ChatAppearanceScope.ChatAppearanceScope,{appearance:o,children:[
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatSheet=ChatSheet;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatAppearanceScope=require("./ChatAppearanceScope.js"),_ChatFrame=require("./ChatFrame.js"),_ChatLauncher=require("./ChatLauncher.js"),_ChatNudge=require("./ChatNudge.js"),_chatShared=require("./chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;function ChatSheet({chat:e,labels:t,renderers:r,layoutParts:a,loader:s="Steps",look:n,appearance:o,pickAttachments:c,onOpenAttachment:i,onOpenTarget:u,onNavigate:l,keyboardOffset:h,open:p,defaultOpen:f=!1,onOpenChange:_,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:m,handoffHosts:b,resolveLink:C,conversationId:g,onClose:j,testID:x="chat-sheet"}){const S=(0,_mobileUi.useTheme)(),v=(0,_chatCore.mergeLabels)(t),T=(0,_react.useMemo)(()=>(0,_chatCore.mergeLook)(n),[n]),O=(0,_mobileUi.useReducedMotion)(),k="Reduced"===T.motion||O,R=o?.position??"end",y=void 0!==p,A=y?p:e.open,N=(0,_react.useRef)(null),E=(0,_react.useRef)(!1),F=(0,_react.useRef)(g??null),L=e.setChatVisible,P=(0,_react.useRef)(!1),q=!P.current,[D,I]=(0,_react.useState)(0),U=(0,_react.useRef)(A);(0,_react.useEffect)(()=>{A&&(P.current=!0)},[A]),(0,_react.useEffect)(()=>{A&&!U.current&&I(e=>e+1),U.current=A},[A]),(0,_react.useEffect)(()=>{E.current||(E.current=!0,y||!f||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[y,f,e.profile,e.open,e.session]),(0,_react.useEffect)(()=>{y&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[y,p,e.open,e.session]);const w=(0,_react.useRef)(A);if((0,_react.useEffect)(()=>{w.current&&!A&&(0,_chatShared.focusForAccessibility)(N.current),w.current=A},[A]),(0,_react.useEffect)(()=>{L(A)},[L,A]),(0,_react.useEffect)(()=>{!y&&g&&g!==F.current&&null!==e.profile&&(F.current=g,e.open||(e.session.open({trigger:"manual"}),_?.(!0)))},[y,g,e.profile,e.open,e.session,_]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),_?.(t)},closeSheet=()=>{setOpen(!1),j?.()},M=o?.offsetY??DEFAULT_BOTTOM_OFFSET;return(0,_jsxRuntime.jsx)(_reactNative.View,{testID:x,style:_reactNative.StyleSheet.absoluteFill,pointerEvents:"box-none",children:(0,_jsxRuntime.jsxs)(_ChatAppearanceScope.ChatAppearanceScope,{appearance:o,children:[(0,_jsxRuntime.jsx)(_ChatLauncher.ChatLauncher,{look:T,hidden:A,label:e.profile?.experience.launcher?.hoverLabel||v.launcher,side:R,offsetX:o?.offsetX??0,offsetY:M,enter:q,reduced:k,mark:T.launcher.mark,avatar:T.avatar,buttonRef:N,onPress:()=>setOpen(!0),testID:`${x}-launcher`}),(0,_jsxRuntime.jsx)(_ChatNudge.ChatNudge,{chat:e,labels:v,enabled:!A&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:M,position:R,testID:`${x}-nudge`}),(0,_jsxRuntime.jsx)(_mobileUi.BottomSheet,{open:A,onClose:closeSheet,snapPoints:d,keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:v.panelTitle,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,backgroundColor:S.colors.bg},children:(0,_jsxRuntime.jsx)(_ChatFrame.ChatFrame,{chat:e,labels:v,renderers:r,layoutParts:a,loader:s,look:n,pickAttachments:c,onOpenAttachment:i,onOpenTarget:u,onNavigate:l,openTicket:m,handoffHosts:b,resolveLink:C,keyboardOffset:h,onClose:closeSheet,layout:"sheet",enterKey:D,testID:`${x}-frame`})})})]})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.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"),_TypingPill=require("./loaders/TypingPill.js"),_index=require("./renderers/index.js"),_NoticePart=require("./renderers/NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");const MINE=new Set(["Visitor","Customer"]),joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n"),renderPart=(e,t,s,a,i,r)=>{const n=e[t.kind];if(n)return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:a,pickAttachments:i});const o={kind:"Notice",code:"NeedsNewerApp",text:a.labels.needsNewerApp};return(0,_react.createElement)(_NoticePart.NoticePart,{key:r,part:o,message:s,turn: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.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:u,onNavigate:d,openTicket:m,handoffHosts:g,resolveLink:h,focusComposer:p,byline:_,avatar:x,replyAvatars:y,avatarStart:f,sourceRows:j,testID:v}){const T=(0,_mobileUi.useTheme)(),b=Object.assign((0,_chatCore.createTurnApi)(e.session,{messageId:t.id,labels:s,openAttachment:c,openTarget:u??_chatShared.defaultOpenTarget,onNavigate:d??e.onNavigate,openTicket:m,handoffHosts:g,openCitation:e=>{return t=String(e),void(0,_chatShared.focusForAccessibility)(j.current.get(t));var t}}),{resolveLink:h,focusComposer:p,registerSourceRow:(e,t)=>{t?j.current.set(e,t):j.current.delete(e)}});let A=0;const nextSlot=()=>(A+=1,A),k=(0,_jsxRuntime.jsx)(_ChatMessageActions.ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${v}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind),i=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:T.space.xs},children:[e.map(e=>renderPart(a,e,t,b,l,`${t.id}-file-${nextSlot()}`)),k]});return(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:s.you},groupPosition:r,footer:i,testID:v})}const N="Agent"===t.author.kind,R=t.author.displayName||s.agent,w=(i?i(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:T.space.xs},children:e.map(e=>renderPart(a,e,t,b,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,b,l,`${t.id}-item-${nextSlot()}`)),P=N&&_?(0,_jsxRuntime.jsx)(_AgentByline.AgentByline,{author:t.author,labels:s,showAvatar:y},`${t.id}-byline`):null,M=P?[P,...w]:w,S=(0,_chatCore.messagePlainText)(t.parts),C=(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"theirs",author:N?void 0:t.author.displayName||s.assistant,text:N?`${s.agentSays(R)} ${S}`:S,streaming:t.streaming,groupPosition:r,footer:k,testID:v,children:M});if(!y||!x||"Assistant"!==t.author.kind)return C;const I=t.author.displayName||s.assistant;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"flex-end",gap:T.space.xs},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:f?void 0:{opacity:0},children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:I,source:f?{uri:x}:void 0})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,minWidth:0},children:C})]})}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,pickAttachments:l,onOpenAttachment:c,onOpenTarget:u,onNavigate:d,openTicket:m,handoffHosts:g,resolveLink:h,focusComposer:p,keyboardAware:_,keyboardOffset:x,empty:y,style:f,testID:j="chat-thread"}){const v=(0,_mobileUi.useTheme)(),T=(0,_react.useMemo)(()=>({..._index.defaultRenderers,...s}),[s]),b=e.messages[0],A=e.greeting??"",k=(0,_react.useMemo)(()=>""!==A&&void 0!==b&&MINE.has(b.author.kind)?{...b,id:"greeting",author:{...b.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:A}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[A,b]),N=(0,_react.useMemo)(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return k?[...t,k]:t},[e.messages,k]),R=e.messages[e.messages.length-1]?.id,w=(0,_react.useRef)(new Map),P=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(null!==P.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||P.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;P.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 P.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const M=(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]),S=(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]),C=(0,_react.useMemo)(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return k&&t.add(k.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,k]),I=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),L=e.turnError,V="daily_limit"===L?.code,$=null!==L&&/feature_off$/.test(L.code),D=V&&L?.resetsDateTimeUtc?` ${t.dailyLimitRefresh((0,_chatCore.formatChatDateTime)(L.resetsDateTimeUtc))}`:"",O=e.streaming||null===L&&!e.stopped?null:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:v.space.xs},testID:`${j}-error`,children:[null!==L?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityRole:V?void 0:"alert",accessibilityLiveRegion:V?"polite":void 0,children:`${L.message}${D}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||V||$?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`})})]}),U=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,E=!0===e.pending?.typing?(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(TypingMark,{size:"Orb"===i?TYPING_ORB_MARK:TYPING_ASSISTANT_MARK})}):null,q=null!==e.agentTyping&&"WithAgent"===e.conversationState?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:v.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=E||U||O||q?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:v.space.sm},children:[E,U,q,O]}):void 0;return(0,_jsxRuntime.jsx)(_mobileUi.MessageList,{messages:N,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:i})=>(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:T,layoutParts:a,groupPosition:i,isLast:s.id===R,isLastVisitor:s.id===M,handoffSettled:I.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:l,onOpenAttachment:c,onOpenTarget:u,onNavigate:d,openTicket:m,handoffHosts:g,resolveLink:h,focusComposer:p,byline:S.has(s.id),avatar:n,replyAvatars:o,avatarStart:C.has(s.id),sourceRows:w,testID:`${j}-${s.id}`})}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:B,empty:y,ItemSeparatorComponent:TurnGap,keyboardAware:_,keyboardOffset:x,accessibilityLabel:t.thread,style:f,testID:j})}
|
|
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"),_NoticePart=require("./renderers/NoticePart.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"),renderPart=(e,t,s,a,i,r)=>{const n=e[t.kind];if(n)return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:a,pickAttachments:i});const o={kind:"Notice",code:"NeedsNewerApp",text:a.labels.needsNewerApp};return(0,_react.createElement)(_NoticePart.NoticePart,{key:r,part:o,message:s,turn: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:a,layoutParts:i,groupPosition:r,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:c,onOpenTarget:d,onNavigate:u,openTicket:m,handoffHosts:g,resolveLink:h,focusComposer:p,byline:_,avatar:x,replyAvatars:y,avatarStart:f,expressive:j,reduced:v,sourceRows:R,testID:b}){const T=(0,_mobileUi.useTheme)(),A=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:h,focusComposer:p,registerSourceRow:(e,t)=>{t?R.current.set(e,t):R.current.delete(e)}});let k=0;const nextSlot=()=>(k+=1,k),N=(0,_jsxRuntime.jsx)(_ChatMessageActions.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=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:T.space.xs},children:[e.map(e=>renderPart(a,e,t,A,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:b})}const w="Agent"===t.author.kind,M=t.author.displayName||s.agent,P=(i?i(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:T.space.xs},children:e.map(e=>renderPart(a,e,t,A,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,A,l,`${t.id}-item-${nextSlot()}`)),S=w&&_?(0,_jsxRuntime.jsx)(_AgentByline.AgentByline,{author:t.author,labels:s,showAvatar:y},`${t.id}-byline`):null,C=S?[S,...P]:P,I=(0,_chatCore.messagePlainText)(t.parts),L=(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"theirs",author:w?void 0:t.author.displayName||(e.profile?.assistant.name??s.assistant),text:w?`${s.agentSays(M)} ${I}`:I,streaming:t.streaming,groupPosition:r,footer:N,testID:b,children:C});if(!y||!x||"Assistant"!==t.author.kind)return L;const V=t.author.displayName||(e.profile?.assistant.name??s.assistant);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"flex-end",gap:T.space.xs},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:f?void 0:{opacity:0},children:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:j&&t.streaming&&f,reduced:v,children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:V,source:f?{uri:x}:void 0})})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,minWidth:0},children:L})]})}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:h,resolveLink:p,focusComposer:_,keyboardAware:x,keyboardOffset:y,empty:f,style:j,testID:v="chat-thread"}){const R=(0,_mobileUi.useTheme)(),b=(0,_mobileUi.useReducedMotion)(),T="Reduced"===r||b,A=(0,_react.useMemo)(()=>({..._index.defaultRenderers,...s}),[s]),k=e.messages[0],N=e.greeting??"",w=(0,_react.useMemo)(()=>""!==N&&void 0!==k&&MINE.has(k.author.kind)?{...k,id:"greeting",author:{...k.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:N}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[N,k]),M=(0,_react.useMemo)(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return w?[...t,w]:t},[e.messages,w]),P=e.messages[e.messages.length-1]?.id,S=(0,_react.useRef)(new Map),C=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(null!==C.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||C.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;C.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 C.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const I=(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]),L=(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]),V=(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]),$=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),D=e.turnError,O="daily_limit"===D?.code,U=null!==D&&/feature_off$/.test(D.code),E=O&&D?.resetsDateTimeUtc?` ${t.dailyLimitRefresh((0,_chatCore.formatChatDateTime)(D.resetsDateTimeUtc))}`:"",q=e.streaming||null===D&&!e.stopped?null:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs},testID:`${v}-error`,children:[null!==D?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityRole:O?void 0:"alert",accessibilityLiveRegion:O?"polite":void 0,children:`${D.message}${E}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||O||U?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:`${v}-retry`})})]}),B=e.thinking&&null!==e.profile?(0,_jsxRuntime.jsx)(_ChatLoader.ChatLoader,{style:i,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:r}):null,H=!0===e.pending?.typing?(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:l,reduced:T,children:n?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:n}}):(0,_jsxRuntime.jsx)(TypingMark,{size:"Orb"===i?TYPING_ORB_MARK:TYPING_ASSISTANT_MARK})})}):null,G=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,z=H||B||q||G?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.sm},children:[H,B,G,q]}):void 0,K=(0,_jsxRuntime.jsx)(_mobileUi.MessageList,{messages:M,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:i})=>(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:A,layoutParts:a,groupPosition:i,isLast:s.id===P,isLastVisitor:s.id===I,handoffSettled:$.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:h,resolveLink:p,focusComposer:_,byline:L.has(s.id),avatar:n,replyAvatars:o,avatarStart:V.has(s.id),expressive:l,reduced:T,sourceRows:S,testID:`${v}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:z,empty:f,ItemSeparatorComponent:TurnGap,keyboardAware:x,keyboardOffset:y,accessibilityLabel:t.thread,accessibilityRole:"list",style:j,testID:v});return"web"!==_reactNative.Platform.OS?K:(0,_jsxRuntime.jsx)(_reactNative.View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:K})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.defaultOpenTarget=defaultOpenTarget,exports.focusForAccessibility=focusForAccessibility,exports.messageSignature=messageSignature;var _reactNative=require("react-native");function focusForAccessibility(e){if(null==e)return;if("web"===_reactNative.Platform.OS)return void e.focus?.();const t=(0,_reactNative.findNodeHandle)(e);null!==t&&_reactNative.AccessibilityInfo.setAccessibilityFocus(t)}function messageSignature(e){let t=0;for(const i of e.parts)"Text"===i.kind&&(t+=i.text.length);return`${e.id}|${e.parts.length}|${t}`}const ABSOLUTE_WEB_URL=/^https?:\/\//i;function defaultOpenTarget(e){ABSOLUTE_WEB_URL.test(e)&&_reactNative.Linking.openURL(e).catch(()=>{})}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WEB_STRONG=void 0,exports.defaultOpenTarget=defaultOpenTarget,exports.focusForAccessibility=focusForAccessibility,exports.messageSignature=messageSignature;var _reactNative=require("react-native");function focusForAccessibility(e){if(null==e)return;if("web"===_reactNative.Platform.OS)return void e.focus?.();const t=(0,_reactNative.findNodeHandle)(e);null!==t&&_reactNative.AccessibilityInfo.setAccessibilityFocus(t)}function messageSignature(e){let t=0;for(const i of e.parts)"Text"===i.kind&&(t+=i.text.length);return`${e.id}|${e.parts.length}|${t}`}const ABSOLUTE_WEB_URL=/^https?:\/\//i;function defaultOpenTarget(e){ABSOLUTE_WEB_URL.test(e)&&_reactNative.Linking.openURL(e).catch(()=>{})}const WEB_STRONG=exports.WEB_STRONG="web"===_reactNative.Platform.OS?{role:"strong"}:{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ReplyRing=ReplyRing;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const TURN_MS=1400;function ReplyRing({active:e,reduced:t,children:i}){return!e||t?(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:i}):(0,_jsxRuntime.jsx)(TurningRing,{children:i})}const TurningRing=({children:e})=>{const t=(0,_mobileUi.useTheme)(),i=(0,_react.useRef)(new _reactNative.Animated.Value(0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.loop(_reactNative.Animated.timing(i,{toValue:1,duration:1400,easing:_reactNative.Easing.linear,useNativeDriver:!0}));return e.start(),()=>e.stop()},[i]);const r=-t.space.xxs,n=i.interpolate({inputRange:[0,1],outputRange:["0deg","360deg"]});return(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[e,(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{position:"absolute",top:r,right:r,bottom:r,left:r,borderWidth:t.space.xxs,borderRadius:t.radius.pill,borderColor:t.colors.primary,borderTopColor:t.colors.info,transform:[{rotate:n}]}})]})};
|
|
@@ -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"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_NoticePart=require("./NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionPart=ActionPart;var _chatCore=require("@webority/chat-core"),_markdownCore=require("@webority/markdown-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_NoticePart=require("./NoticePart.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:()=>{_reactNative.Linking.openURL(e.href).catch(()=>{})},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:a}=t,[r,o]=(0,_react.useState)(null),[s,l]=(0,_react.useState)(""),[c,d]=(0,_react.useState)(!1),run=async(e,t)=>{o(e),l("");try{await t()}catch(e){const t=e?.message;l("string"==typeof t&&""!==t?t:n.actionFailed),o(null)}},u=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=a.LeadRecap&&e.actionKind===LEAD_CAPTURE,x=m&&u.length>0,_=m&&e.confirmLabel||n.actionConfirm,j=m&&e.rejectLabel||n.actionDismiss,p=null!==r;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",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",children:t}),null!==n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:n}):null]},e)}),m&&e.consentText?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:inlineNodes((0,_markdownCore.parseInline)(e.consentText),i)}):null,"Pending"===e.state?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[""!==s?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:s}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:"confirm"===r?n.actionWorking:_,loading:"confirm"===r,disabled:p,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:j,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",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",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(e){const{part:t,message:i,turn:n}=e;if("Action"!==t.kind){const e={kind:"Notice",code:"NeedsNewerApp",text:n.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:n})}return(0,_jsxRuntime.jsx)(ActionBody,{part:t,turn:n},t.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"),_NoticePart=require("./NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");const FIELD_TYPES=new Set(["Email","Phone","Name","Company","Text","LongText","Choice","MultiChoice","TimeSlot","File","Consent"]),isUndrawnField=e=>!FIELD_TYPES.has(e.type),fileNameOf=(e,t)=>{const i=e.name;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),selectedIds=e=>""===e?[]:JSON.parse(e),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:s,features:a}=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,j]=(0,_react.useState)({}),h=(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=h.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,T=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(s.errorGeneric),m(!1)}},U=a.LeadShortcuts,w=U&&1===e.fields.length&&!e.fields[0].required,C=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLabel:e.title||void 0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",children:e.title}):null,e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.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=y[a.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),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=a.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:s.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:e.progress??void 0,label:s.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i()}catch{return void d(s.errorGeneric)}const a=r[0];if(!a)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(a,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}))}})(a)}})}),c?(0,_jsxRuntime.jsx)(_mobileUi.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(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.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,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(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,value:""===l?void 0:l,onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,error:c,disabled:p})})]},a.key)}if("Consent"===a.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,error:c,disabled:p},a.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{h.current[a.key]=e},label:a.label,placeholder:a.placeholder??void 0,value:l,onChangeText:e=>setValue(a.key,e),maxLength:a.maxLength??void 0,required:a.required,error:c,help:a.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",autoCapitalize:"Email"===a.type?"none":void 0,autoComplete:AUTO_COMPLETE[a.type]},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const m=f[a.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:s.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()}),j(e=>({...e,[i.key]:"sent"}))}catch{j(e=>({...e,[i.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:s.inputEnterCode,value:_[a.key]??"",onChangeText:e=>b(t=>({...t,[a.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?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.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?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||T,onPress:()=>{(async()=>{if(T)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(i[t.key]=s.inputConsentRequired),r[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(i[t.key]=s.inputRequired),r[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(_[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),a[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(a).length>0?a:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}m(!1)})()}}),T?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,w?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]})]})})}function InputRequestPart(e){const{part:t,message:i,turn:r,pickAttachments:s}=e;if("InputRequest"!==t.kind||t.fields.some(isUndrawnField)){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:r})}return"Answered"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary||r.labels.inputAnswered}):"Skipped"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputSkipped}):"Expired"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:t,turn:r,pickAttachments:s},t.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"),_NoticePart=require("./NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");const FIELD_TYPES=new Set(["Email","Phone","Name","Company","Text","LongText","Choice","MultiChoice","TimeSlot","File","Consent"]),isUndrawnField=e=>!FIELD_TYPES.has(e.type),fileNameOf=(e,t)=>{const i=e.name;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),selectedIds=e=>""===e?[]:JSON.parse(e),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:s,features:a}=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,j]=(0,_react.useState)({}),h=(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=h.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,T=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(s.errorGeneric),m(!1)}},U=a.LeadShortcuts,w=U&&1===e.fields.length&&!e.fields[0].required,C=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLabel:e.title||void 0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",children:e.title}):null,e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.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=y[a.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),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=a.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:s.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:e.progress??void 0,label:s.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.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(s.errorGeneric)}const a=r[0];if(!a)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(a,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}))}})(a)}})}),c?(0,_jsxRuntime.jsx)(_mobileUi.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(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.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,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(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,value:""===l?void 0:l,onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,error:c,disabled:p})})]},a.key)}if("Consent"===a.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,error:c,disabled:p},a.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{h.current[a.key]=e},label:a.label,placeholder:a.placeholder??void 0,value:l,onChangeText:e=>setValue(a.key,e),maxLength:a.maxLength??void 0,required:a.required,error:c,help:a.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",autoCapitalize:"Email"===a.type?"none":void 0,autoComplete:AUTO_COMPLETE[a.type]},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const m=f[a.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:s.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()}),j(e=>({...e,[i.key]:"sent"}))}catch{j(e=>({...e,[i.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:s.inputEnterCode,value:_[a.key]??"",onChangeText:e=>b(t=>({...t,[a.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?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.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?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||T,onPress:()=>{(async()=>{if(T)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(i[t.key]=s.inputConsentRequired),r[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(i[t.key]=s.inputRequired),r[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(_[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),a[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(a).length>0?a:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}m(!1)})()}}),T?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,w?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]})]})})}function InputRequestPart(e){const{part:t,message:i,turn:r,pickAttachments:s}=e;if("InputRequest"!==t.kind||t.fields.some(isUndrawnField)){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:r})}return"Answered"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary||r.labels.inputAnswered}):"Skipped"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputSkipped}):"Expired"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:t,turn:r,pickAttachments:s},t.requestId)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.QuickRepliesPart=QuickRepliesPart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_ChatEntrance=require("../ChatEntrance.js"),_chatShared=require("../chatShared.js"),_chipLook=require("./chipLook.js"),_jsxRuntime=require("react/jsx-runtime");const QUIET_LOOK={variant:"outline"};function QuickRepliesPart({part:e,turn:i}){const t=(0,_mobileUi.useTheme)();if(!i.features.SuggestedReplies||!i.isLast||i.busy||0===e.replies.length)return null;const n=i.openTarget,a=i.onNavigate,r=void 0!==n&&n!==_chatShared.defaultOpenTarget,o="Composer"===e.placement,s=e.replies.filter(e=>"Send"===e.action||"Open"===e.action&&e.target&&n||"Navigate"===e.action&&i.features.LinkHandoff);if(0===s.length)return null;const l=o?void 0:s.find(e=>e.id===_chatCore.CHAT_HANDOFF_REQUEST_ID&&"Send"===e.action),c=l?s.filter(e=>e!==l):s,u=l?1:0,sendChip=(e,t)=>(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:t.variant,tone:t.tone,leftIcon:e.icon?e.icon:void 0,onPress:()=>{i.chooseQuickReply(e),i.focusComposer?.()}});return(0,_jsxRuntime.jsxs)(_reactNative.View,{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.QuickRepliesPart=QuickRepliesPart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_ChatEntrance=require("../ChatEntrance.js"),_chatShared=require("../chatShared.js"),_chipLook=require("./chipLook.js"),_jsxRuntime=require("react/jsx-runtime");const QUIET_LOOK={variant:"outline"};function QuickRepliesPart({part:e,turn:i}){const t=(0,_mobileUi.useTheme)();if(!i.features.SuggestedReplies||!i.isLast||i.busy||0===e.replies.length)return null;const n=i.openTarget,a=i.onNavigate,r=void 0!==n&&n!==_chatShared.defaultOpenTarget,o="Composer"===e.placement,s=e.replies.filter(e=>"Send"===e.action||"Open"===e.action&&e.target&&n||"Navigate"===e.action&&i.features.LinkHandoff);if(0===s.length)return null;const l=o?void 0:s.find(e=>e.id===_chatCore.CHAT_HANDOFF_REQUEST_ID&&"Send"===e.action),c=l?s.filter(e=>e!==l):s,u=l?1:0,sendChip=(e,t)=>(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:t.variant,tone:t.tone,leftIcon:e.icon?e.icon:void 0,onPress:()=>{i.chooseQuickReply(e),i.focusComposer?.()}});return(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"group",accessibilityLabel:i.labels.quickReplies,accessibilityLiveRegion:i.handoffPause?"polite":void 0,style:{flexDirection:"row",flexWrap:"wrap",gap:t.space.xs,...o?{paddingHorizontal:t.space.md}:null},children:[l?(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexBasis:"100%",alignItems:"flex-start",gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:l.label}),sendChip(l,(0,_chipLook.chipLook)("Primary"))]})},l.id):null,c.map((e,t)=>{const o=t+u,s=l?QUIET_LOOK:(0,_chipLook.chipLook)(e.variant),c=e.icon?e.icon:void 0;if("Send"===e.action)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:o,children:sendChip(e,s)},e.id);const d=e.target;if("Open"===e.action&&d&&n)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:o,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:s.variant,tone:s.tone,leftIcon:c,onPress:()=>n(d)})},e.id);if("Navigate"===e.action){const t=(e=>{if(!e)return null;if((0,_chatCore.isHandoffTarget)(e,i.handoffHosts))return e;const t=i.resolveLink?.(e);return"string"==typeof t&&""!==t?t:null})(d),l=null===t?void 0:(e=>e.startsWith("/")?n&&r?()=>n(e):a?()=>a(e):void 0:n?()=>n(e):void 0)(t);return null===t||void 0===l?(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:o,children:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:e.label})},e.id):(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:o,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:i.handoffPause?i.labels.handoffMoment:e.label,variant:i.handoffPause?QUIET_LOOK.variant:s.variant,tone:i.handoffPause?void 0:s.tone,leftIcon:c,disabled:i.handoffPause,onPress:()=>i.beginHandoff(e,l)})},e.id)}return null})]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextPart=TextPart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const CITATION=/^\d
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextPart=TextPart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const CITATION=/^\d+$/,PARAGRAPH_ROLE="paragraph";function TextPart({part:e,message:t,turn:r}){const i="Visitor"===t.author.kind||"Customer"===t.author.kind;return(0,_jsxRuntime.jsx)(_reactNative.View,{role:PARAGRAPH_ROLE,children:i?r.features.FigureText?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.text,variant:"body",color:"primary"}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:e.text}):(0,_jsxRuntime.jsx)(_mobileUi.Markdown,{links:"app",headings:"text",resolveLink:e=>r.openTarget&&(0,_chatCore.isHandoffTarget)(e,r.handoffHosts)?e:null,onAppLinkPress:e=>r.openTarget?.(e),isCitation:e=>CITATION.test(e),figureText:r.features.FigureText?_chatCore.toFigureRuns:void 0,onOpenCitation:r.openCitation?e=>r.openCitation?.(Number(e)):void 0,children:e.text})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SpeechRequestError=void 0,exports.synthesizeSpeech=synthesizeSpeech,exports.transcribeClip=transcribeClip;var _chatCore=require("@webority/chat-core"),_speechText=require("./speechText.js");const TRANSCRIBE_API_VERSION="2024-11-15",TTS_OUTPUT_FORMAT="audio-24khz-48kbitrate-mono-mp3",REQUEST_TIMEOUT_MS=15e3,REGION_PATTERN=/^[a-z0-9]+$/;class SpeechRequestError extends Error{constructor(e){super(`Speech request failed with status ${e}`),this.name="SpeechRequestError",this.status=e}}exports.SpeechRequestError=SpeechRequestError;const assertRegion=e=>{if(!REGION_PATTERN.test(e))throw new _chatCore.ChatSpeechError("Unavailable","Speech is not available.")},withTimeout=async(e,t)=>{const r=new AbortController,abort=()=>r.abort(),o=setTimeout(abort,15e3);e?.aborted&&r.abort(),e?.addEventListener("abort",abort);try{return await t(r.signal)}finally{clearTimeout(o),e?.removeEventListener("abort",abort)}};async function transcribeClip(e){const{token:t,uri:r,language:o,signal:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SpeechRequestError=void 0,exports.synthesizeSpeech=synthesizeSpeech,exports.transcribeClip=transcribeClip;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_speechText=require("./speechText.js");const TRANSCRIBE_API_VERSION="2024-11-15",TTS_OUTPUT_FORMAT="audio-24khz-48kbitrate-mono-mp3",REQUEST_TIMEOUT_MS=15e3,REGION_PATTERN=/^[a-z0-9]+$/;class SpeechRequestError extends Error{constructor(e){super(`Speech request failed with status ${e}`),this.name="SpeechRequestError",this.status=e}}exports.SpeechRequestError=SpeechRequestError;const assertRegion=e=>{if(!REGION_PATTERN.test(e))throw new _chatCore.ChatSpeechError("Unavailable","Speech is not available.")},withTimeout=async(e,t)=>{const r=new AbortController,abort=()=>r.abort(),o=setTimeout(abort,15e3);e?.aborted&&r.abort(),e?.addEventListener("abort",abort);try{return await t(r.signal)}finally{clearTimeout(o),e?.removeEventListener("abort",abort)}};async function transcribeClip(e){const{token:t,uri:r,language:o,signal:i,fetchImpl:s=fetch}=e;assertRegion(t.region);const a=new FormData;return a.append("audio",{uri:r,name:"dictation.m4a",type:"audio/mp4"}),a.append("definition",JSON.stringify({locales:[o]})),withTimeout(i,async e=>{const r=await(0,_mobileCore.fetchWithRetry)(s,`https://${t.region}.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=${TRANSCRIBE_API_VERSION}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`},body:a,signal:e});if(!r.ok)throw new SpeechRequestError(r.status);return((await r.json()).combinedPhrases??[]).map(e=>e.text??"").join(" ").trim()})}async function synthesizeSpeech(e){const{token:t,text:r,language:o,voice:i,signal:s,fetchImpl:a=fetch}=e;return assertRegion(t.region),withTimeout(s,async e=>{const s=await(0,_mobileCore.fetchWithRetry)(a,`https://${t.region}.tts.speech.microsoft.com/cognitiveservices/v1`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":TTS_OUTPUT_FORMAT,"User-Agent":"webority-chat"},body:(0,_speechText.buildSsml)((0,_speechText.clampSpeakText)(r),o,i),signal:e});if(!s.ok)throw new SpeechRequestError(s.status);return new Uint8Array(await s.arrayBuffer())})}
|
package/lib/commonjs/useChat.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChat=useChat;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native");const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze((0,_chatCore.emptyFeatures)()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});function useChat(e){const{client:t,screen:r,layout:n,narrow:a,conversationId:c,pageContext:o,behaviour:s,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChat=useChat;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native");const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze((0,_chatCore.emptyFeatures)()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffContactRequestId:null,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});function useChat(e){const{client:t,screen:r,layout:n,narrow:a,conversationId:c,pageContext:o,behaviour:s,attribution:u,prefs:i,getCaptchaToken:l,onEvent:f,onError:_,onNavigate:d}=e,p=JSON.stringify(a??{}),v=(0,_react.useRef)(d);v.current=d;const m=(0,_react.useCallback)(e=>v.current?.(e),[]),h=(0,_react.useRef)(c);h.current=c;const E=(0,_react.useRef)(o);E.current=o;const g=(0,_react.useRef)(s);g.current=s;const S=(0,_react.useRef)(u);S.current=u;const C=(0,_react.useRef)(l);C.current=l;const y=(0,_react.useRef)(f);y.current=f;const b=(0,_react.useRef)(_);b.current=_;const I=(0,_react.useRef)(i);I.current=i;const R=(0,_mobileUi.useReducedMotion)(),A=(0,_react.useRef)(R);A.current=R;const[N,L]=(0,_react.useState)(null),[O,T]=(0,_react.useState)(null);(0,_react.useEffect)(()=>{const e=(0,_chatCore.createChatSession)(t,{screen:r,layout:n,pathname:()=>r||"/",narrow:JSON.parse(p),conversationId:h.current??void 0,pageContext:()=>E.current,behaviour:()=>g.current?.()??null,attribution:()=>S.current?.()??null,prefs:I.current,getCaptchaToken:e=>C.current?.(e)??Promise.reject(new Error("No captcha handler.")),onEvent:(e,t)=>y.current?.(e,t),onError:e=>b.current?.(e),schedule:requestFrame,reducedMotion:()=>A.current});return L({client:t,screen:r,layout:n,narrowKey:p,session:e}),()=>e.dispose()},[t,r,n,p]);const w=null!==N&&N.client===t&&N.screen===r&&N.layout===n&&N.narrowKey===p?N.session:IDLE_SESSION,k=(0,_react.useSyncExternalStore)(w.subscribe,w.getState),q=(0,_react.useMemo)(()=>({load:()=>w.load(),submit:e=>w.submit(e),chooseQuickReply:e=>w.chooseQuickReply(e),answerInput:(e,t)=>w.answerInput(e,t),confirmAction:e=>w.confirmAction(e),rejectAction:(e,t)=>w.rejectAction(e,t),stop:()=>w.stop(),retry:()=>w.retry(),regenerate:()=>w.regenerate(),startEdit:e=>w.startEdit(e),cancelEdit:()=>w.cancelEdit(),attach:e=>w.attach(e),removeAttachment:e=>w.removeAttachment(e),openConversation:e=>w.openConversation(e),resumeLast:()=>w.resumeLast(),newConversation:()=>w.newConversation(),rate:(e,t,r)=>w.rate(e,t,r),reset:()=>w.reset(),requestHandoff:async e=>{T(null);try{await w.requestHandoff(e)}catch(e){const t=e instanceof Error&&""!==e.message?e.message:_chatCore.DEFAULT_CHAT_LABELS.errorGeneric;throw T(t),e}},notifyTyping:()=>w.notifyTyping(),resumeLive:()=>w.resumeLive()}),[w]),P=(0,_react.useRef)(c);(0,_react.useEffect)(()=>{w!==IDLE_SESSION&&c&&c!==P.current&&(P.current=c,w.openConversation(c))},[c,w]);const j=(0,_react.useRef)("active"===_reactNative.AppState.currentState),x=(0,_react.useRef)(!0),D=(0,_react.useCallback)(()=>w.setLiveActive(j.current&&x.current),[w]),F=(0,_react.useCallback)(e=>{x.current=e,D()},[D]);(0,_react.useEffect)(()=>{D();const e=_reactNative.AppState.addEventListener("change",e=>{"active"===e?(j.current=!0,w.endHandoffPause()):j.current=!1,D()});return()=>e.remove()},[D,w]);const U=(0,_react.useCallback)((e,t)=>{y.current?.(e,t)},[]);return{...k,...q,session:w,client:t,emit:U,setChatVisible:F,handoffError:O,onNavigate:d?m:void 0}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=useTranscriptActions;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native");const NOTICE_MS=3e3;async function shareMessages(e,r,t,a){const s=(0,_chatCore.buildTranscript)(e,r);if(0===s.entries.length)return;const c=(0,_chatCore.transcriptToText)(s,{heading:t,speakers:t});try{await _reactNative.Share.share({message:c,title:s.title})}catch(e){_mobileCore.Logger.error("[chat] share failed",e),a()}}function useTranscriptActions(e,r){const[t,a]=(0,_react.useState)(null),s=(0,_react.useRef)(null),c=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>(c.current=!0,()=>{c.current=!1,null!==s.current&&clearTimeout(s.current)}),[]);const i=(0,_react.useCallback)(e=>{c.current&&(null!==s.current&&clearTimeout(s.current),a(e),s.current=setTimeout(()=>a(null),NOTICE_MS))},[]),{messages:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=useTranscriptActions;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_react=require("react"),_reactNative=require("react-native");const NOTICE_MS=3e3;async function shareMessages(e,r,t,a){const s=(0,_chatCore.buildTranscript)(e,r);if(0===s.entries.length)return;const c=(0,_chatCore.transcriptToText)(s,{heading:t,speakers:t});try{await _reactNative.Share.share({message:c,title:s.title})}catch(e){_mobileCore.Logger.error("[chat] share failed",e),a()}}function useTranscriptActions(e,r){const[t,a]=(0,_react.useState)(null),s=(0,_react.useRef)(null),c=(0,_react.useRef)(!1);(0,_react.useEffect)(()=>(c.current=!0,()=>{c.current=!1,null!==s.current&&clearTimeout(s.current)}),[]);const i=(0,_react.useCallback)(e=>{c.current&&(null!==s.current&&clearTimeout(s.current),a(e),s.current=setTimeout(()=>a(null),NOTICE_MS))},[]),{messages:n,title:u}=e,l=e.features.FigureText,o=e.profile?.assistant.name,h=(0,_react.useCallback)(e=>shareMessages([e],{labels:r,title:u,figureText:l,assistantName:o},!1,()=>i(r.shareFailed)),[r,u,l,o,i]),_=(0,_react.useCallback)(()=>shareMessages(n,{labels:r,title:u,figureText:l,assistantName:o},!0,()=>i(r.shareFailed)),[n,r,u,l,o,i]);return{canShare:e.features.Share,notice:t,shareReply:h,shareConversation:_}}
|
package/lib/module/ChatFrame.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{mergeLook}from"@webority/chat-core";import{Avatar,Banner,IconButton,Spinner,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useMemo,useRef,useState}from"react";import{View}from"react-native";import{ChatComposer}from"./ChatComposer.js";import{ChatConversationActions}from"./ChatConversationActions.js";import{ChatHistory}from"./ChatHistory.js";import{ChatLiveBar}from"./ChatLiveBar.js";import{ChatPanelGrow,ChatReveal,panelRun}from"./ChatPanel.js";import{ChatStarters}from"./ChatStarters.js";import{ChatThread}from"./ChatThread.js";import{useChatHaptics}from"./useChatHaptics.js";import{useChatSound}from"./useChatSound.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";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:
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";import{Avatar,FloatingActionButton,useTheme}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{Animated,Easing,StyleSheet}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{jsx as _jsx}from"react/jsx-runtime";const RISE_MS=900,RISE_DELAY_MS=400,ENTRANCE_MS=800,ENTRANCE_DELAY_MS=1e3,FLOAT_HALF_MS=1600,FLOAT_PX=4,RISE_FROM_PX=116;function entranceStyle(e,t){const range=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:range([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:range([0,1],[0,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[100,0]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[.8,1]})}]};case"BounceIn":return{transform:[{scale:range([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:range([0,.5,1],[0,1,1]),transform:[{scale:range([0,.5,1],[1,1.1,1])}]};case"SpinScale":return{transform:[{rotate:t.interpolate({inputRange:[0,1],outputRange:["-180deg","0deg"]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[0,1]})}]};case"WiggleIn":return{transform:[{translateY:range([0,.4,1],[100,0,0])},{rotate:range([0,.4,.6,.8,1],["-10deg","5deg","-3deg","1deg","0deg"])}]};case"ElasticIn":return{transform:[{scale:range([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}}const OVERSHOOT=new Set(["Rise","SlideUp","SpinScale"]);export function ChatLauncher({look:e,
|
|
1
|
+
"use strict";import{Avatar,FloatingActionButton,useTheme}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{Animated,Easing,StyleSheet}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{jsx as _jsx}from"react/jsx-runtime";const RISE_MS=900,RISE_DELAY_MS=400,ENTRANCE_MS=800,ENTRANCE_DELAY_MS=1e3,FLOAT_HALF_MS=1600,FLOAT_PX=4,RISE_FROM_PX=116,SHRINK_MS=320,SHRINK_EASING=Easing.bezier(.4,0,.2,1);function entranceStyle(e,t){const range=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:range([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:range([0,1],[0,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[100,0]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[.8,1]})}]};case"BounceIn":return{transform:[{scale:range([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:range([0,.5,1],[0,1,1]),transform:[{scale:range([0,.5,1],[1,1.1,1])}]};case"SpinScale":return{transform:[{rotate:t.interpolate({inputRange:[0,1],outputRange:["-180deg","0deg"]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[0,1]})}]};case"WiggleIn":return{transform:[{translateY:range([0,.4,1],[100,0,0])},{rotate:range([0,.4,.6,.8,1],["-10deg","5deg","-3deg","1deg","0deg"])}]};case"ElasticIn":return{transform:[{scale:range([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}}const OVERSHOOT=new Set(["Rise","SlideUp","SpinScale"]);export function ChatLauncher({look:e,hidden:t,label:a,side:n,offsetX:i,offsetY:r,enter:s,reduced:o,mark:u="Icon",avatar:l=null,buttonRef:c,onPress:m,testID:p}){const d=useTheme(),f=useSafeAreaInsets(),g=e.launcher.entrance,S="Avatar"===u&&l?l:null,A=d.components["floating-action-button"].md.diameter,[R]=useState(()=>s&&!o&&"None"!==g),E=t&&e.expressive&&!o,v=!o&&!t&&"FloatAndPulse"===e.launcher.idle,[_]=useState(()=>new Animated.Value(R?0:1)),[h]=useState(()=>new Animated.Value(0)),[I]=useState(()=>new Animated.Value(1)),[b,y]=useState(!1);if(useEffect(()=>{if(!t)return I.setValue(1),void y(!1);if(!E)return;const e=Animated.timing(I,{toValue:0,duration:320,easing:SHRINK_EASING,useNativeDriver:!0});return e.start(({finished:e})=>{e&&y(!0)}),()=>e.stop()},[t,E,I]),useEffect(()=>{if(!R)return void _.setValue(1);const e="Rise"===g,t=Animated.timing(_,{toValue:1,duration:e?900:800,delay:e?400:1e3,easing:OVERSHOOT.has(g)?Easing.bezier(.34,e?1.4:1.56,.64,1):Easing.linear,useNativeDriver:!0});return t.start(),()=>t.stop()},[R,g,_]),useEffect(()=>{if(!v)return void h.setValue(0);const e=Animated.loop(Animated.sequence([Animated.timing(h,{toValue:1,duration:1600,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}),Animated.timing(h,{toValue:0,duration:1600,easing:Easing.inOut(Easing.ease),useNativeDriver:!0})]));return e.start(),()=>e.stop()},[v,h]),t&&(!E||b))return null;const N="Pill"===e.launcher.style&&!e.launcher.compact,V=d.space[d.components["floating-action-button"]["edge-offset"]]+i,x={position:"absolute",bottom:r+f.bottom,..."start"===n?{left:V}:{right:V}},O=entranceStyle(g,_);return _jsx(Animated.View,{pointerEvents:"box-none",style:StyleSheet.absoluteFill,children:_jsx(Animated.View,{style:[x,{opacity:Animated.multiply(O.opacity??1,I),transform:[...O.transform,{scale:I},{translateY:h.interpolate({inputRange:[0,1],outputRange:[0,-4]})}]}],children:_jsx(FloatingActionButton,{ref:c,icon:S?_jsx(Avatar,{dimension:A,name:a,source:{uri:S}}):"messages",label:N?a:void 0,collapsed:!N,accessibilityLabel:a,onPress:m,testID:p})})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Banner,Button,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";
|
|
1
|
+
"use strict";import{Banner,Button,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function ChatLiveBar({chat:e,labels:t,testID:s="chat-live-bar"}){const i=useTheme();if(!e.features.HumanHandoff||null===e.conversationId)return null;const n=e.conversationState;if("Closed"===n)return null;if("Open"===n){return e.features.HumanHandoff&&e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind)&&!e.streaming&&!e.thinking?_jsxs(View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:i.space.md,paddingVertical:i.space.xs},testID:s,children:[_jsx(Button,{label:t.talkToPerson,variant:"soft",size:"sm",leftIcon:"user",loading:e.handoffPending,onPress:()=>{e.requestHandoff()},testID:`${s}-talk`}),null!==e.handoffError?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:t.errorGeneric}):null]}):null}return"Lost"!==e.live?null:_jsx(View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:i.space.md,paddingVertical:i.space.xs},testID:s,children:_jsx(Banner,{tone:"warning",message:t.liveLost,actions:[{label:t.retry,onPress:()=>e.resumeLive()}],testID:`${s}-lost`})})}
|
|
@@ -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{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:i,isLastVisitor:a,testID:n}){const r=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),m=useRef(null),d=useTranscriptActions(e,s),
|
|
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{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:i,isLastVisitor:a,testID:n}){const r=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),m=useRef(null),d=useTranscriptActions(e,s),p=useMemo(()=>TEXT_AUTHORS.has(t.author.kind)&&buildTranscript([t],{labels:s,title:null,figureText:!1,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=i&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),b=a&&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||p&&e.features.Share&&d.canShare||x||T||b||f&&e.features.Rating?_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:r.space.xs},testID:n,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:`${n}-copy`}):null,p&&e.features.Share&&d.canShare?_jsx(Button,{label:s.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{d.shareReply(t)},testID:`${n}-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:`${n}-regenerate`}):null,b?_jsx(Button,{label:s.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${n}-edit`}):null,f&&e.features.Rating?_jsxs(_Fragment,{children:[_jsxs(View,{accessibilityRole:"summary",accessibilityLabel:s.rating,style:{flexDirection:"row",alignItems:"center",gap:r.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:`${n}-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:`${n}-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!==d.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:d.notice}):null]}):null}
|
package/lib/module/ChatSheet.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{mergeLabels,mergeLook}from"@webority/chat-core";import{BottomSheet,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{ChatLauncher}from"./ChatLauncher.js";import{ChatNudge}from"./ChatNudge.js";import{focusForAccessibility}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;export function ChatSheet({chat:e,labels:t,renderers:o,layoutParts:s,loader:r="Steps",look:n,appearance:a,pickAttachments:i,onOpenAttachment:
|
|
1
|
+
"use strict";import{mergeLabels,mergeLook}from"@webority/chat-core";import{BottomSheet,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{ChatLauncher}from"./ChatLauncher.js";import{ChatNudge}from"./ChatNudge.js";import{focusForAccessibility}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;export function ChatSheet({chat:e,labels:t,renderers:o,layoutParts:s,loader:r="Steps",look:n,appearance:a,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,keyboardOffset:f,open:p,defaultOpen:h=!1,onOpenChange:m,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:b,handoffHosts:g,resolveLink:C,conversationId:S,onClose:k,testID:j="chat-sheet"}){const y=useTheme(),x=mergeLabels(t),T=useMemo(()=>mergeLook(n),[n]),A=useReducedMotion(),_="Reduced"===T.motion||A,L=a?.position??"end",O=void 0!==p,v=O?p:e.open,E=useRef(null),F=useRef(!1),P=useRef(S??null),R=e.setChatVisible,N=useRef(!1),D=!N.current,[I,w]=useState(0),M=useRef(v);useEffect(()=>{v&&(N.current=!0)},[v]),useEffect(()=>{v&&!M.current&&w(e=>e+1),M.current=v},[v]),useEffect(()=>{F.current||(F.current=!0,O||!h||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[O,h,e.profile,e.open,e.session]),useEffect(()=>{O&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[O,p,e.open,e.session]);const V=useRef(v);if(useEffect(()=>{V.current&&!v&&focusForAccessibility(E.current),V.current=v},[v]),useEffect(()=>{R(v)},[R,v]),useEffect(()=>{!O&&S&&S!==P.current&&null!==e.profile&&(P.current=S,e.open||(e.session.open({trigger:"manual"}),m?.(!0)))},[O,S,e.profile,e.open,e.session,m]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),m?.(t)},closeSheet=()=>{setOpen(!1),k?.()},B=a?.offsetY??16;return _jsx(View,{testID:j,style:StyleSheet.absoluteFill,pointerEvents:"box-none",children:_jsxs(ChatAppearanceScope,{appearance:a,children:[_jsx(ChatLauncher,{look:T,hidden:v,label:e.profile?.experience.launcher?.hoverLabel||x.launcher,side:L,offsetX:a?.offsetX??0,offsetY:B,enter:D,reduced:_,mark:T.launcher.mark,avatar:T.avatar,buttonRef:E,onPress:()=>setOpen(!0),testID:`${j}-launcher`}),_jsx(ChatNudge,{chat:e,labels:x,enabled:!v&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:B,position:L,testID:`${j}-nudge`}),_jsx(BottomSheet,{open:v,onClose:closeSheet,snapPoints:d,keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:x.panelTitle,children:_jsx(View,{style:{flex:1,backgroundColor:y.colors.bg},children:_jsx(ChatFrame,{chat:e,labels:x,renderers:o,layoutParts:s,loader:r,look:n,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,openTicket:b,handoffHosts:g,resolveLink:C,keyboardOffset:f,onClose:closeSheet,layout:"sheet",enterKey:I,testID:`${j}-frame`})})})]})})}
|
package/lib/module/ChatThread.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createTurnApi,formatChatDateTime,handoffSettledIds,messagePlainText}from"@webority/chat-core";import{Avatar,Button,MessageBubble,MessageList,Text,useTheme}from"@webority/mobile-ui";import{createElement,memo,useEffect,useMemo,useRef}from"react";import{AccessibilityInfo,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{TypingPill}from"./loaders/TypingPill.js";import{defaultRenderers}from"./renderers/index.js";import{NoticePart}from"./renderers/NoticePart.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MINE=new Set(["Visitor","Customer"]),joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n"),renderPart=(e,t,s,a,r
|
|
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{NoticePart}from"./renderers/NoticePart.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"),renderPart=(e,t,s,a,i,r)=>{const n=e[t.kind];if(n)return createElement(n,{key:r,part:t,message:s,turn:a,pickAttachments:i});const o={kind:"Notice",code:"NeedsNewerApp",text:a.labels.needsNewerApp};return createElement(NoticePart,{key:r,part:o,message:s,turn: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:a,layoutParts:i,groupPosition:r,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:d,onOpenTarget:c,onNavigate:g,openTicket:m,handoffHosts:p,resolveLink:u,focusComposer:h,byline:f,avatar:y,replyAvatars:x,avatarStart:v,expressive:T,reduced:k,sourceRows:A,testID:b}){const j=useTheme(),w=Object.assign(createTurnApi(e.session,{messageId:t.id,labels:s,openAttachment:d,openTarget:c??defaultOpenTarget,onNavigate:g??e.onNavigate,openTicket:m,handoffHosts:p,openCitation:e=>{return t=String(e),void focusForAccessibility(A.current.get(t));var t}}),{resolveLink:u,focusComposer:h,registerSourceRow:(e,t)=>{t?A.current.set(e,t):A.current.delete(e)}});let _=0;const nextSlot=()=>(_+=1,_),M=_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:j.space.xs},children:[e.map(e=>renderPart(a,e,t,w,l,`${t.id}-file-${nextSlot()}`)),M]});return _jsx(MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:r,footer:s,testID:b})}const N="Agent"===t.author.kind,P=t.author.displayName||s.agent,R=(i?i(t):t.parts).map(e=>Array.isArray(e)?_jsx(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:j.space.xs},children:e.map(e=>renderPart(a,e,t,w,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(a,e,t,w,l,`${t.id}-item-${nextSlot()}`)),S=N&&f?_jsx(AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=S?[S,...R]:R,L=messagePlainText(t.parts),V=_jsx(MessageBubble,{side:"theirs",author:N?void 0:t.author.displayName||(e.profile?.assistant.name??s.assistant),text:N?`${s.agentSays(P)} ${L}`:L,streaming:t.streaming,groupPosition:r,footer:M,testID:b,children:I});if(!x||!y||"Assistant"!==t.author.kind)return V;const C=t.author.displayName||(e.profile?.assistant.name??s.assistant);return _jsxs(View,{style:{flexDirection:"row",alignItems:"flex-end",gap:j.space.xs},children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:v?void 0:{opacity:0},children:_jsx(ReplyRing,{active:T&&t.streaming&&v,reduced:k,children:_jsx(Avatar,{size:"xs",name:C,source:v?{uri:y}:void 0})})}),_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:i="Steps",motion:r="On",avatar:n,replyAvatars:o=!0,expressive:l=!1,pickAttachments:d,onOpenAttachment:c,onOpenTarget:g,onNavigate:m,openTicket:p,handoffHosts:u,resolveLink:h,focusComposer:f,keyboardAware:y,keyboardOffset:x,empty:v,style:T,testID:k="chat-thread"}){const A=useTheme(),b=useReducedMotion(),j="Reduced"===r||b,w=useMemo(()=>({...defaultRenderers,...s}),[s]),_=e.messages[0],M=e.greeting??"",N=useMemo(()=>""!==M&&void 0!==_&&MINE.has(_.author.kind)?{..._,id:"greeting",author:{..._.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:M}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[M,_]),P=useMemo(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return N?[...t,N]:t},[e.messages,N]),R=e.messages[e.messages.length-1]?.id,S=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 L=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 i=e.messages[a-1];"Agent"===i?.author.kind&&(i.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),C=useMemo(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return N&&t.add(N.id),s.forEach((e,a)=>{"Assistant"===e.author.kind&&"Assistant"!==s[a-1]?.author.kind&&t.add(e.id)}),t},[e.messages,N]),$=useMemo(()=>handoffSettledIds(e.messages),[e.messages]),D=e.turnError,O="daily_limit"===D?.code,E=null!==D&&/feature_off$/.test(D.code),B=O&&D?.resetsDateTimeUtc?` ${t.dailyLimitRefresh(formatChatDateTime(D.resetsDateTimeUtc))}`:"",H=e.streaming||null===D&&!e.stopped?null:_jsxs(View,{style:{gap:A.space.xs},testID:`${k}-error`,children:[_jsx(Text,null!==D?{variant:"bodySmall",color:"danger",accessibilityRole:O?void 0:"alert",accessibilityLiveRegion:O?"polite":void 0,children:`${D.message}${B}`}:{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||O||E?null:_jsx(View,{style:{flexDirection:"row"},children:_jsx(Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${k}-retry`})})]}),z=e.thinking&&null!==e.profile?_jsx(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,F=!0===e.pending?.typing?_jsx(TypingPill,{motion:r,mark:_jsx(ReplyRing,{active:l,reduced:j,children:n?_jsx(Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:n}}):_jsx(TypingMark,{size:"Orb"===i?14:8})})}):null,G=null!==e.agentTyping&&"WithAgent"===e.conversationState?_jsxs(View,{style:{gap:A.space.xs,alignSelf:"flex-start"},children:[_jsx(TypingPill,{motion:r,mark:_jsx(TypingDots,{})}),_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,U=F||z||H||G?_jsxs(View,{style:{gap:A.space.sm},children:[F,z,G,H]}):void 0,K=_jsx(MessageList,{messages:P,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:i})=>_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:w,layoutParts:a,groupPosition:i,isLast:s.id===R,isLastVisitor:s.id===L,handoffSettled:$.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:d,onOpenAttachment:c,onOpenTarget:g,onNavigate:m,openTicket:p,handoffHosts:u,resolveLink:h,focusComposer:f,byline:V.has(s.id),avatar:n,replyAvatars:o,avatarStart:C.has(s.id),expressive:l,reduced:j,sourceRows:S,testID:`${k}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:U,empty:v,ItemSeparatorComponent:TurnGap,keyboardAware:y,keyboardOffset:x,accessibilityLabel:t.thread,accessibilityRole:"list",style:T,testID:k});return"web"!==Platform.OS?K:_jsx(View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:K})}
|
package/lib/module/chatShared.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{AccessibilityInfo,findNodeHandle,Linking,Platform}from"react-native";export function focusForAccessibility(t){if(null==t)return;if("web"===Platform.OS)return void t.focus?.();const e=findNodeHandle(t);null!==e&&AccessibilityInfo.setAccessibilityFocus(e)}export function messageSignature(t){let e=0;for(const
|
|
1
|
+
"use strict";import{AccessibilityInfo,findNodeHandle,Linking,Platform}from"react-native";export function focusForAccessibility(t){if(null==t)return;if("web"===Platform.OS)return void t.focus?.();const e=findNodeHandle(t);null!==e&&AccessibilityInfo.setAccessibilityFocus(e)}export function messageSignature(t){let e=0;for(const n of t.parts)"Text"===n.kind&&(e+=n.text.length);return`${t.id}|${t.parts.length}|${e}`}const ABSOLUTE_WEB_URL=/^https?:\/\//i;export function defaultOpenTarget(t){ABSOLUTE_WEB_URL.test(t)&&Linking.openURL(t).catch(()=>{})}export const WEB_STRONG="web"===Platform.OS?{role:"strong"}:{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{useTheme}from"@webority/mobile-ui";import{useEffect,useRef}from"react";import{Animated,Easing,View}from"react-native";import{Fragment as _Fragment,jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TURN_MS=1400;export function ReplyRing({active:e,reduced:t,children:r}){return _jsx(!e||t?_Fragment:TurningRing,{children:r})}const TurningRing=({children:e})=>{const t=useTheme(),r=useRef(new Animated.Value(0)).current;useEffect(()=>{const e=Animated.loop(Animated.timing(r,{toValue:1,duration:1400,easing:Easing.linear,useNativeDriver:!0}));return e.start(),()=>e.stop()},[r]);const i=-t.space.xxs,n=r.interpolate({inputRange:[0,1],outputRange:["0deg","360deg"]});return _jsxs(View,{children:[e,_jsx(Animated.View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{position:"absolute",top:i,right:i,bottom:i,left:i,borderWidth:t.space.xxs,borderRadius:t.radius.pill,borderColor:t.colors.primary,borderTopColor:t.colors.info,transform:[{rotate:n}]}})]})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatChatDate}from"@webority/chat-core";import{parseInline}from"@webority/markdown-core";import{Button,Card,OptionSheet,Text,useTheme}from"@webority/mobile-ui";import{useState}from"react";import{Linking,Text as RNText,View}from"react-native";import{NoticePart}from"./NoticePart.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https
|
|
1
|
+
"use strict";import{formatChatDate}from"@webority/chat-core";import{parseInline}from"@webority/markdown-core";import{Button,Card,OptionSheet,Text,useTheme}from"@webority/mobile-ui";import{useState}from"react";import{Linking,Text as RNText,View}from"react-native";import{NoticePart}from"./NoticePart.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:()=>{Linking.openURL(e.href).catch(()=>{})},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:a}=t,[r,o]=useState(null),[s,l]=useState(""),[c,d]=useState(!1),run=async(e,t)=>{o(e),l("");try{await t()}catch(e){const t=e?.message;l("string"==typeof t&&""!==t?t:i.actionFailed),o(null)}},u=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=a.LeadRecap&&e.actionKind===LEAD_CAPTURE,p=m&&u.length>0,x=m&&e.confirmLabel||i.actionConfirm,h=m&&e.rejectLabel||i.actionDismiss,f=null!==r;return _jsxs(Card,{variant:"outline",padding:"sm",children:[_jsxs(View,{style:{gap:n.space.sm},children:[_jsx(Text,{variant:"label",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",children:t}),null!==i?_jsx(Text,{variant:"bodySmall",children:i}):null]},e)}),m&&e.consentText?_jsx(Text,{variant:"caption",color:"secondary",children:inlineNodes(parseInline(e.consentText),n)}):null,"Pending"===e.state?_jsxs(_Fragment,{children:[""!==s?_jsx(Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:s}):null,_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",gap:n.space.sm},children:[_jsx(Button,{label:"confirm"===r?i.actionWorking:x,loading:"confirm"===r,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",children:statusLine(e,i)}),p?_jsx(Button,{label:i.editSomething,variant:"ghost",disabled:f||"Pending"!==e.state,onPress:()=>d(!0)}):null,e.note?_jsx(Text,{variant:"caption",color:"secondary",children:e.note}):null]}),p?_jsx(OptionSheet,{open:c,onClose:()=>d(!1),title:i.editSomething,options:u,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(e){const{part:t,message:n,turn:i}=e;if("Action"!==t.kind){const e={kind:"Notice",code:"NeedsNewerApp",text:i.labels.needsNewerApp};return _jsx(NoticePart,{part:e,message:n,turn:i})}return _jsx(ActionBody,{part:t,turn:i},t.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}from"../chatShared.js";import{NoticePart}from"./NoticePart.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const FIELD_TYPES=new Set(["Email","Phone","Name","Company","Text","LongText","Choice","MultiChoice","TimeSlot","File","Consent"]),isUndrawnField=e=>!FIELD_TYPES.has(e.type),fileNameOf=(e,t)=>{const i=e.name;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),selectedIds=e=>""===e?[]:JSON.parse(e),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=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,m]=useState({}),[x,h]=useState({}),[b,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),T=useRef(!1),C=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const i=g.current[e];i&&focusForAccessibility(i)},[]);useEffect(()=>{if(p||!T.current)return;T.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&C(t)},[p,o,e.fields,C]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{j.current=e,m(e)},patchUpload=(e,t)=>{const i=j.current[e];i&&commitUploads({...j.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,S=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},w=a.LeadShortcuts,R=w&&1===e.fields.length&&!e.fields[0].required,E=w&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",accessibilityLabel:e.title||void 0,children:_jsxs(View,{style:{gap:r.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",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:r.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),e?_jsxs(View,{style:{gap:r.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,{progress:e.progress??void 0,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===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i()}catch{return void d(s.errorGeneric)}const a=r[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 i=await t.uploadInputFile(a,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}))}})(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:r.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,{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,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:r.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,value:""===l?void 0:l,onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,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,error:c,disabled:p},a.key);const u=_jsx(Input,{ref:e=>{v.current[a.key]=e},label:a.label,placeholder:a.placeholder??void 0,value:l,onChangeText:e=>setValue(a.key,e),maxLength:a.maxLength??void 0,required:a.required,error:c,help:a.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",autoCapitalize:"Email"===a.type?"none":void 0,autoComplete:AUTO_COMPLETE[a.type]},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const y=b[a.key];return _jsxs(View,{style:{gap:r.space.xs},children:[u,_jsxs(View,{style:{gap:r.space.xs},children:[_jsx(Button,{label:s.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()}),k(e=>({...e,[i.key]:"sent"}))}catch{k(e=>({...e,[i.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),_jsx(Input,{label:s.inputEnterCode,value:x[a.key]??"",onChangeText:e=>h(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:r.space.sm},children:[_jsx(Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||S,onPress:()=>{(async()=>{if(S)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(i[t.key]=s.inputConsentRequired),r[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(i[t.key]=s.inputRequired),r[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(x[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),a[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&C(t))}y(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(a).length>0?a:null);if(i.ok)return;c(i.errors),T.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}y(!1)})()}}),S?_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(e){const{part:t,message:i,turn:r,pickAttachments:s}=e;if("InputRequest"!==t.kind||t.fields.some(isUndrawnField)){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return _jsx(NoticePart,{part:e,message:i,turn:r})}return"Answered"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary||r.labels.inputAnswered}):"Skipped"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputSkipped}):"Expired"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputExpired}):_jsx(OpenRequest,{part:t,turn:r,pickAttachments:s},t.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}from"../chatShared.js";import{NoticePart}from"./NoticePart.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const FIELD_TYPES=new Set(["Email","Phone","Name","Company","Text","LongText","Choice","MultiChoice","TimeSlot","File","Consent"]),isUndrawnField=e=>!FIELD_TYPES.has(e.type),fileNameOf=(e,t)=>{const i=e.name;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),selectedIds=e=>""===e?[]:JSON.parse(e),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=useTheme(),{labels:s,features:a}=t,[n,l]=useState({}),[o,c]=useState({}),[u,d]=useState(""),[p,y]=useState(!1),[f,m]=useState({}),[x,h]=useState({}),[b,k]=useState({}),v=useRef({}),g=useRef({}),j=useRef(f),_=useRef(0),T=useRef(!1),C=useCallback(e=>{const t=v.current[e];if(t)return void t.focus();const i=g.current[e];i&&focusForAccessibility(i)},[]);useEffect(()=>{if(p||!T.current)return;T.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&C(t)},[p,o,e.fields,C]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{j.current=e,m(e)},patchUpload=(e,t)=>{const i=j.current[e];i&&commitUploads({...j.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>j.current[e]?.token===t,S=Object.values(f).some(e=>"Ready"!==e.status),leave=async e=>{y(!0),d("");try{await e()}catch{d(s.errorGeneric),y(!1)}},w=a.LeadShortcuts,R=w&&1===e.fields.length&&!e.fields[0].required,E=w&&e.cancellable;return _jsx(Card,{variant:"outline",padding:"sm",accessibilityLabel:e.title||void 0,children:_jsxs(View,{style:{gap:r.space.sm},children:[e.title?_jsx(Text,{variant:"label",accessibilityRole:"header",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:r.space.xs},children:[_jsx(Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),e?_jsxs(View,{style:{gap:r.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,{progress:e.progress??void 0,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===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i(e.accept??void 0)}catch{return void d(s.errorGeneric)}const a=r[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 i=await t.uploadInputFile(a,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}))}})(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:r.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,{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,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:r.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,value:""===l?void 0:l,onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,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,error:c,disabled:p},a.key);const u=_jsx(Input,{ref:e=>{v.current[a.key]=e},label:a.label,placeholder:a.placeholder??void 0,value:l,onChangeText:e=>setValue(a.key,e),maxLength:a.maxLength??void 0,required:a.required,error:c,help:a.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",autoCapitalize:"Email"===a.type?"none":void 0,autoComplete:AUTO_COMPLETE[a.type]},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const y=b[a.key];return _jsxs(View,{style:{gap:r.space.xs},children:[u,_jsxs(View,{style:{gap:r.space.xs},children:[_jsx(Button,{label:s.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()}),k(e=>({...e,[i.key]:"sent"}))}catch{k(e=>({...e,[i.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),_jsx(Input,{label:s.inputEnterCode,value:x[a.key]??"",onChangeText:e=>h(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:r.space.sm},children:[_jsx(Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||S,onPress:()=>{(async()=>{if(S)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(i[t.key]=s.inputConsentRequired),r[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(i[t.key]=s.inputRequired),r[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(x[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),a[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&C(t))}y(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(a).length>0?a:null);if(i.ok)return;c(i.errors),T.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}y(!1)})()}}),S?_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(e){const{part:t,message:i,turn:r,pickAttachments:s}=e;if("InputRequest"!==t.kind||t.fields.some(isUndrawnField)){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return _jsx(NoticePart,{part:e,message:i,turn:r})}return"Answered"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary||r.labels.inputAnswered}):"Skipped"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputSkipped}):"Expired"===t.state?_jsx(Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputExpired}):_jsx(OpenRequest,{part:t,turn:r,pickAttachments:s},t.requestId)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{CHAT_HANDOFF_REQUEST_ID,isHandoffTarget}from"@webority/chat-core";import{Chip,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatEntrance}from"../ChatEntrance.js";import{defaultOpenTarget}from"../chatShared.js";import{chipLook}from"./chipLook.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const QUIET_LOOK={variant:"outline"};export function QuickRepliesPart({part:e,turn:
|
|
1
|
+
"use strict";import{CHAT_HANDOFF_REQUEST_ID,isHandoffTarget}from"@webority/chat-core";import{Chip,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatEntrance}from"../ChatEntrance.js";import{defaultOpenTarget}from"../chatShared.js";import{chipLook}from"./chipLook.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const QUIET_LOOK={variant:"outline"};export function QuickRepliesPart({part:e,turn:n}){const i=useTheme();if(!n.features.SuggestedReplies||!n.isLast||n.busy||0===e.replies.length)return null;const t=n.openTarget,a=n.onNavigate,r=void 0!==t&&t!==defaultOpenTarget,o="Composer"===e.placement,s=e.replies.filter(e=>"Send"===e.action||"Open"===e.action&&e.target&&t||"Navigate"===e.action&&n.features.LinkHandoff);if(0===s.length)return null;const l=o?void 0:s.find(e=>e.id===CHAT_HANDOFF_REQUEST_ID&&"Send"===e.action),c=l?s.filter(e=>e!==l):s,d=l?1:0,sendChip=(e,i)=>_jsx(Chip,{label:e.label,variant:i.variant,tone:i.tone,leftIcon:e.icon?e.icon:void 0,onPress:()=>{n.chooseQuickReply(e),n.focusComposer?.()}});return _jsxs(View,{role:"group",accessibilityLabel:n.labels.quickReplies,accessibilityLiveRegion:n.handoffPause?"polite":void 0,style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.xs,...o?{paddingHorizontal:i.space.md}:null},children:[l?_jsx(ChatEntrance,{index:0,children:_jsxs(View,{style:{flexBasis:"100%",alignItems:"flex-start",gap:i.space.xs},children:[_jsx(Text,{variant:"label",children:l.label}),sendChip(l,chipLook("Primary"))]})},l.id):null,c.map((e,i)=>{const o=i+d,s=l?QUIET_LOOK:chipLook(e.variant),c=e.icon?e.icon:void 0;if("Send"===e.action)return _jsx(ChatEntrance,{index:o,children:sendChip(e,s)},e.id);const f=e.target;if("Open"===e.action&&f&&t)return _jsx(ChatEntrance,{index:o,children:_jsx(Chip,{label:e.label,variant:s.variant,tone:s.tone,leftIcon:c,onPress:()=>t(f)})},e.id);if("Navigate"===e.action){const i=(e=>{if(!e)return null;if(isHandoffTarget(e,n.handoffHosts))return e;const i=n.resolveLink?.(e);return"string"==typeof i&&""!==i?i:null})(f),l=null===i?void 0:(e=>e.startsWith("/")?t&&r?()=>t(e):a?()=>a(e):void 0:t?()=>t(e):void 0)(i);return _jsx(ChatEntrance,null===i||void 0===l?{index:o,children:_jsx(Text,{variant:"bodySmall",color:"primary",children:e.label})}:{index:o,children:_jsx(Chip,{label:n.handoffPause?n.labels.handoffMoment:e.label,variant:n.handoffPause?QUIET_LOOK.variant:s.variant,tone:n.handoffPause?void 0:s.tone,leftIcon:c,disabled:n.handoffPause,onPress:()=>n.beginHandoff(e,l)})},e.id)}return null})]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{isHandoffTarget}from"@webority/chat-core";import{Markdown,Text}from"@webority/mobile-ui";import{FigureText}from"./FigureText.js";import{jsx as _jsx}from"react/jsx-runtime";const CITATION=/^\d
|
|
1
|
+
"use strict";import{isHandoffTarget,toFigureRuns}from"@webority/chat-core";import{Markdown,Text}from"@webority/mobile-ui";import{View}from"react-native";import{FigureText}from"./FigureText.js";import{jsx as _jsx}from"react/jsx-runtime";const CITATION=/^\d+$/,PARAGRAPH_ROLE="paragraph";export function TextPart({part:t,message:e,turn:r}){const i="Visitor"===e.author.kind||"Customer"===e.author.kind;return _jsx(View,{role:"paragraph",children:i?r.features.FigureText?_jsx(FigureText,{text:t.text,variant:"body",color:"primary"}):_jsx(Text,{variant:"body",children:t.text}):_jsx(Markdown,{links:"app",headings:"text",resolveLink:t=>r.openTarget&&isHandoffTarget(t,r.handoffHosts)?t:null,onAppLinkPress:t=>r.openTarget?.(t),isCitation:t=>CITATION.test(t),figureText:r.features.FigureText?toFigureRuns:void 0,onOpenCitation:r.openCitation?t=>r.openCitation?.(Number(t)):void 0,children:t.text})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{ChatSpeechError}from"@webority/chat-core";import{buildSsml,clampSpeakText}from"./speechText.js";const TRANSCRIBE_API_VERSION="2024-11-15",TTS_OUTPUT_FORMAT="audio-24khz-48kbitrate-mono-mp3",REQUEST_TIMEOUT_MS=15e3,REGION_PATTERN=/^[a-z0-9]+$/;export class SpeechRequestError extends Error{constructor(e){super(`Speech request failed with status ${e}`),this.name="SpeechRequestError",this.status=e}}const assertRegion=e=>{if(!REGION_PATTERN.test(e))throw new ChatSpeechError("Unavailable","Speech is not available.")},withTimeout=async(e,t)=>{const r=new AbortController,abort=()=>r.abort(),o=setTimeout(abort,15e3);e?.aborted&&r.abort(),e?.addEventListener("abort",abort);try{return await t(r.signal)}finally{clearTimeout(o),e?.removeEventListener("abort",abort)}};export async function transcribeClip(e){const{token:t,uri:r,language:o,signal:
|
|
1
|
+
"use strict";import{ChatSpeechError}from"@webority/chat-core";import{fetchWithRetry}from"@webority/mobile-core";import{buildSsml,clampSpeakText}from"./speechText.js";const TRANSCRIBE_API_VERSION="2024-11-15",TTS_OUTPUT_FORMAT="audio-24khz-48kbitrate-mono-mp3",REQUEST_TIMEOUT_MS=15e3,REGION_PATTERN=/^[a-z0-9]+$/;export class SpeechRequestError extends Error{constructor(e){super(`Speech request failed with status ${e}`),this.name="SpeechRequestError",this.status=e}}const assertRegion=e=>{if(!REGION_PATTERN.test(e))throw new ChatSpeechError("Unavailable","Speech is not available.")},withTimeout=async(e,t)=>{const r=new AbortController,abort=()=>r.abort(),o=setTimeout(abort,15e3);e?.aborted&&r.abort(),e?.addEventListener("abort",abort);try{return await t(r.signal)}finally{clearTimeout(o),e?.removeEventListener("abort",abort)}};export async function transcribeClip(e){const{token:t,uri:r,language:o,signal:i,fetchImpl:a=fetch}=e;assertRegion(t.region);const n=new FormData;return n.append("audio",{uri:r,name:"dictation.m4a",type:"audio/mp4"}),n.append("definition",JSON.stringify({locales:[o]})),withTimeout(i,async e=>{const r=await fetchWithRetry(a,`https://${t.region}.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=2024-11-15`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`},body:n,signal:e});if(!r.ok)throw new SpeechRequestError(r.status);return((await r.json()).combinedPhrases??[]).map(e=>e.text??"").join(" ").trim()})}export async function synthesizeSpeech(e){const{token:t,text:r,language:o,voice:i,signal:a,fetchImpl:n=fetch}=e;return assertRegion(t.region),withTimeout(a,async e=>{const a=await fetchWithRetry(n,`https://${t.region}.tts.speech.microsoft.com/cognitiveservices/v1`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":TTS_OUTPUT_FORMAT,"User-Agent":"webority-chat"},body:buildSsml(clampSpeakText(r),o,i),signal:e});if(!a.ok)throw new SpeechRequestError(a.status);return new Uint8Array(await a.arrayBuffer())})}
|
package/lib/module/useChat.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createChatSession,DEFAULT_CHAT_LABELS,emptyFeatures}from"@webority/chat-core";import{useReducedMotion}from"@webority/mobile-ui";import{useCallback,useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{AppState}from"react-native";const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze(emptyFeatures()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});export function useChat(e){const{client:t,screen:r,layout:n,narrow:
|
|
1
|
+
"use strict";import{createChatSession,DEFAULT_CHAT_LABELS,emptyFeatures}from"@webority/chat-core";import{useReducedMotion}from"@webority/mobile-ui";import{useCallback,useEffect,useMemo,useRef,useState,useSyncExternalStore}from"react";import{AppState}from"react-native";const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze(emptyFeatures()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffContactRequestId:null,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});export function useChat(e){const{client:t,screen:r,layout:n,narrow:o,conversationId:s,pageContext:a,behaviour:u,attribution:c,prefs:i,getCaptchaToken:l,onEvent:f,onError:p,onNavigate:m}=e,d=JSON.stringify(o??{}),S=useRef(m);S.current=m;const E=useCallback(e=>S.current?.(e),[]),v=useRef(s);v.current=s;const g=useRef(a);g.current=a;const h=useRef(u);h.current=u;const y=useRef(c);y.current=c;const C=useRef(l);C.current=l;const b=useRef(f);b.current=f;const R=useRef(p);R.current=p;const A=useRef(i);A.current=i;const I=useReducedMotion(),L=useRef(I);L.current=I;const[T,w]=useState(null),[O,N]=useState(null);useEffect(()=>{const e=createChatSession(t,{screen:r,layout:n,pathname:()=>r||"/",narrow:JSON.parse(d),conversationId:v.current??void 0,pageContext:()=>g.current,behaviour:()=>h.current?.()??null,attribution:()=>y.current?.()??null,prefs:A.current,getCaptchaToken:e=>C.current?.(e)??Promise.reject(new Error("No captcha handler.")),onEvent:(e,t)=>b.current?.(e,t),onError:e=>R.current?.(e),schedule:requestFrame,reducedMotion:()=>L.current});return w({client:t,screen:r,layout:n,narrowKey:d,session:e}),()=>e.dispose()},[t,r,n,d]);const k=null!==T&&T.client===t&&T.screen===r&&T.layout===n&&T.narrowKey===d?T.session:IDLE_SESSION,_=useSyncExternalStore(k.subscribe,k.getState),F=useMemo(()=>({load:()=>k.load(),submit:e=>k.submit(e),chooseQuickReply:e=>k.chooseQuickReply(e),answerInput:(e,t)=>k.answerInput(e,t),confirmAction:e=>k.confirmAction(e),rejectAction:(e,t)=>k.rejectAction(e,t),stop:()=>k.stop(),retry:()=>k.retry(),regenerate:()=>k.regenerate(),startEdit:e=>k.startEdit(e),cancelEdit:()=>k.cancelEdit(),attach:e=>k.attach(e),removeAttachment:e=>k.removeAttachment(e),openConversation:e=>k.openConversation(e),resumeLast:()=>k.resumeLast(),newConversation:()=>k.newConversation(),rate:(e,t,r)=>k.rate(e,t,r),reset:()=>k.reset(),requestHandoff:async e=>{N(null);try{await k.requestHandoff(e)}catch(e){const t=e instanceof Error&&""!==e.message?e.message:DEFAULT_CHAT_LABELS.errorGeneric;throw N(t),e}},notifyTyping:()=>k.notifyTyping(),resumeLive:()=>k.resumeLive()}),[k]),P=useRef(s);useEffect(()=>{k!==IDLE_SESSION&&s&&s!==P.current&&(P.current=s,k.openConversation(s))},[s,k]);const D=useRef("active"===AppState.currentState),q=useRef(!0),x=useCallback(()=>k.setLiveActive(D.current&&q.current),[k]),j=useCallback(e=>{q.current=e,x()},[x]);useEffect(()=>{x();const e=AppState.addEventListener("change",e=>{"active"===e?(D.current=!0,k.endHandoffPause()):D.current=!1,x()});return()=>e.remove()},[x,k]);const H=useCallback((e,t)=>{b.current?.(e,t)},[]);return{..._,...F,session:k,client:t,emit:H,setChatVisible:j,handoffError:O,onNavigate:m?E:void 0}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{buildTranscript,transcriptToText}from"@webority/chat-core";import{Logger}from"@webority/mobile-core";import{useCallback,useEffect,useRef,useState}from"react";import{Share}from"react-native";const NOTICE_MS=3e3;async function shareMessages(e,r,
|
|
1
|
+
"use strict";import{buildTranscript,transcriptToText}from"@webority/chat-core";import{Logger}from"@webority/mobile-core";import{useCallback,useEffect,useRef,useState}from"react";import{Share}from"react-native";const NOTICE_MS=3e3;async function shareMessages(e,t,r,s){const a=buildTranscript(e,t);if(0===a.entries.length)return;const i=transcriptToText(a,{heading:r,speakers:r});try{await Share.share({message:i,title:a.title})}catch(e){Logger.error("[chat] share failed",e),s()}}export default function useTranscriptActions(e,t){const[r,s]=useState(null),a=useRef(null),i=useRef(!1);useEffect(()=>(i.current=!0,()=>{i.current=!1,null!==a.current&&clearTimeout(a.current)}),[]);const n=useCallback(e=>{i.current&&(null!==a.current&&clearTimeout(a.current),s(e),a.current=setTimeout(()=>s(null),3e3))},[]),{messages:c,title:u}=e,l=e.features.FigureText,o=e.profile?.assistant.name,f=useCallback(e=>shareMessages([e],{labels:t,title:u,figureText:l,assistantName:o},!1,()=>n(t.shareFailed)),[t,u,l,o,n]),h=useCallback(()=>shareMessages(c,{labels:t,title:u,figureText:l,assistantName:o},!0,()=>n(t.shareFailed)),[c,t,u,l,o,n]);return{canShare:e.features.Share,notice:r,shareReply:f,shareConversation:h}}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ChatLabels, type ChatLook
|
|
1
|
+
import { type ChatLabels, type ChatLook } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
|
+
import type { PickAttachments } from "./types";
|
|
3
4
|
import type { UseChatResult } from "./useChat";
|
|
4
5
|
export interface ChatComposerProps {
|
|
5
6
|
chat: UseChatResult;
|
|
6
7
|
labels: ChatLabels;
|
|
7
|
-
pickAttachments?:
|
|
8
|
+
pickAttachments?: PickAttachments;
|
|
8
9
|
keyboardOffset?: number;
|
|
9
10
|
keyboardAware?: boolean;
|
|
10
11
|
safeArea?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ChatLabels, type ChatLoaderStyle, type ChatLookInput, type ChatPart
|
|
1
|
+
import { type ChatLabels, type ChatLoaderStyle, type ChatLookInput, type ChatPart } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
|
-
import type { ChatAppearance, ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers } from "./types";
|
|
3
|
+
import type { ChatAppearance, ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers, PickAttachments } from "./types";
|
|
4
4
|
import type { UseChatResult } from "./useChat";
|
|
5
5
|
export type ChatLayout = "screen" | "sheet" | "embedded";
|
|
6
6
|
/** The props every shell passes down to its frame. */
|
|
@@ -12,7 +12,7 @@ export interface ChatCommonProps {
|
|
|
12
12
|
loader?: ChatLoaderStyle;
|
|
13
13
|
/** The look: its input ring and send reveal, its panel motion and its motion switch. Unset values take the defaults. */
|
|
14
14
|
look?: ChatLookInput;
|
|
15
|
-
pickAttachments?:
|
|
15
|
+
pickAttachments?: PickAttachments;
|
|
16
16
|
onOpenAttachment?: (part: Extract<ChatPart, {
|
|
17
17
|
kind: "File";
|
|
18
18
|
}>) => void;
|
|
@@ -3,6 +3,8 @@ import type React from "react";
|
|
|
3
3
|
import { type View } from "react-native";
|
|
4
4
|
export interface ChatLauncherProps {
|
|
5
5
|
look: ChatLook;
|
|
6
|
+
/** The chat is open. The launcher leaves: at once, or by shrinking first when the look is expressive. */
|
|
7
|
+
hidden: boolean;
|
|
6
8
|
label: string;
|
|
7
9
|
side: "start" | "end";
|
|
8
10
|
offsetX: number;
|
|
@@ -20,5 +22,5 @@ export interface ChatLauncherProps {
|
|
|
20
22
|
* The floating launcher as the look draws it: round or pill, with its label, the chosen entrance and the
|
|
21
23
|
* float idle. The entrance moves the button's own wrapper, so a scale or a turn happens around the button.
|
|
22
24
|
*/
|
|
23
|
-
export declare function ChatLauncher({ look, label, side, offsetX, offsetY, enter, reduced, mark, avatar, buttonRef, onPress, testID, }: ChatLauncherProps): React.ReactElement;
|
|
25
|
+
export declare function ChatLauncher({ look, hidden, label, side, offsetX, offsetY, enter, reduced, mark, avatar, buttonRef, onPress, testID, }: ChatLauncherProps): React.ReactElement | null;
|
|
24
26
|
//# sourceMappingURL=ChatLauncher.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ChatLabels, ChatLoaderStyle, ChatMotion, ChatPart
|
|
1
|
+
import type { ChatLabels, ChatLoaderStyle, ChatMotion, ChatPart } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
4
|
-
import type { ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers } from "./types";
|
|
4
|
+
import type { ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers, PickAttachments } from "./types";
|
|
5
5
|
import type { UseChatResult } from "./useChat";
|
|
6
6
|
export interface ChatThreadProps {
|
|
7
7
|
chat: UseChatResult;
|
|
@@ -14,7 +14,9 @@ export interface ChatThreadProps {
|
|
|
14
14
|
avatar?: string | null;
|
|
15
15
|
/** False hides the pictures beside replies. */
|
|
16
16
|
replyAvatars?: boolean;
|
|
17
|
-
|
|
17
|
+
/** A ring turns around the thinking mark and the streaming reply's picture. Off unless the look sets it. */
|
|
18
|
+
expressive?: boolean;
|
|
19
|
+
pickAttachments?: PickAttachments;
|
|
18
20
|
onOpenAttachment?: (part: Extract<ChatPart, {
|
|
19
21
|
kind: "File";
|
|
20
22
|
}>) => void;
|
|
@@ -36,5 +38,5 @@ export interface ChatThreadProps {
|
|
|
36
38
|
* pill while a paced reply is held, the loader while a reply is awaited and the error row after a
|
|
37
39
|
* failed or stopped turn.
|
|
38
40
|
*/
|
|
39
|
-
export declare function ChatThread({ chat, labels, renderers, layoutParts, loader, motion, avatar, replyAvatars, pickAttachments, onOpenAttachment, onOpenTarget, onNavigate, openTicket, handoffHosts, resolveLink, focusComposer, keyboardAware, keyboardOffset, empty, style, testID, }: ChatThreadProps): React.ReactElement;
|
|
41
|
+
export declare function ChatThread({ chat, labels, renderers, layoutParts, loader, motion, avatar, replyAvatars, expressive, pickAttachments, onOpenAttachment, onOpenTarget, onNavigate, openTicket, handoffHosts, resolveLink, focusComposer, keyboardAware, keyboardOffset, empty, style, testID, }: ChatThreadProps): React.ReactElement;
|
|
40
42
|
//# sourceMappingURL=ChatThread.d.ts.map
|
|
@@ -3,4 +3,5 @@ import type { ChatLiveMessage } from "@webority/chat-core";
|
|
|
3
3
|
export declare function focusForAccessibility(node: unknown): void;
|
|
4
4
|
export declare function messageSignature(message: ChatLiveMessage): string;
|
|
5
5
|
export declare function defaultOpenTarget(target: string): void;
|
|
6
|
+
export declare const WEB_STRONG: object;
|
|
6
7
|
//# sourceMappingURL=chatShared.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
export interface ReplyRingProps {
|
|
3
|
+
active: boolean;
|
|
4
|
+
reduced: boolean;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/** A two-tone ring that turns around its children while a reply is in progress; plain children otherwise. */
|
|
8
|
+
export declare function ReplyRing({ active, reduced, children }: ReplyRingProps): React.JSX.Element;
|
|
9
|
+
//# sourceMappingURL=ReplyRing.d.ts.map
|
|
@@ -27,11 +27,16 @@ export interface ChatTurnHostApi {
|
|
|
27
27
|
/** Moves focus to the composer input after a quick reply is chosen. */
|
|
28
28
|
focusComposer?: () => void;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Opens the app's file picker. accept lists the media types a file question takes;
|
|
32
|
+
* an app may ignore it, the server checks every upload.
|
|
33
|
+
*/
|
|
34
|
+
export type PickAttachments = (accept?: readonly string[]) => Promise<ChatUploadFile[]>;
|
|
30
35
|
export type ChatPartRendererProps<P extends ChatPart = ChatPart> = {
|
|
31
36
|
part: P;
|
|
32
37
|
message: ChatLiveMessage;
|
|
33
38
|
turn: ChatTurnApi & ChatTurnHostApi;
|
|
34
|
-
pickAttachments?:
|
|
39
|
+
pickAttachments?: PickAttachments;
|
|
35
40
|
};
|
|
36
41
|
export type ChatRenderers = Partial<{
|
|
37
42
|
[K in ChatPartKind]: React.ComponentType<ChatPartRendererProps<Extract<ChatPart, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatBehaviour, ChatClient, ChatFeature, ChatSession, ChatSessionState } from "@webority/chat-core";
|
|
1
|
+
import type { ChatAttribution, ChatBehaviour, ChatClient, ChatFeature, ChatSession, ChatSessionState } from "@webority/chat-core";
|
|
2
2
|
import type { ChatLayout } from "./ChatFrame";
|
|
3
3
|
export interface ChatPrefs {
|
|
4
4
|
get(key: string): string | null;
|
|
@@ -18,6 +18,8 @@ export interface UseChatOptions {
|
|
|
18
18
|
pageContext?: unknown;
|
|
19
19
|
/** The behaviour the host app measured; read at the moment of sending. */
|
|
20
20
|
behaviour?: () => ChatBehaviour | null;
|
|
21
|
+
/** The campaign touch a lead captured in the chat carries; read at the moment of sending. */
|
|
22
|
+
attribution?: () => ChatAttribution | null;
|
|
21
23
|
/** Where the session keeps the mute choice (key wchat:muted). */
|
|
22
24
|
prefs: ChatPrefs;
|
|
23
25
|
getCaptchaToken?: (action: string) => Promise<string | null>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ChatLabels, type ChatLook
|
|
1
|
+
import { type ChatLabels, type ChatLook } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
|
+
import type { PickAttachments } from "./types.js";
|
|
3
4
|
import type { UseChatResult } from "./useChat.js";
|
|
4
5
|
export interface ChatComposerProps {
|
|
5
6
|
chat: UseChatResult;
|
|
6
7
|
labels: ChatLabels;
|
|
7
|
-
pickAttachments?:
|
|
8
|
+
pickAttachments?: PickAttachments;
|
|
8
9
|
keyboardOffset?: number;
|
|
9
10
|
keyboardAware?: boolean;
|
|
10
11
|
safeArea?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ChatLabels, type ChatLoaderStyle, type ChatLookInput, type ChatPart
|
|
1
|
+
import { type ChatLabels, type ChatLoaderStyle, type ChatLookInput, type ChatPart } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
|
-
import type { ChatAppearance, ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers } from "./types.js";
|
|
3
|
+
import type { ChatAppearance, ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers, PickAttachments } from "./types.js";
|
|
4
4
|
import type { UseChatResult } from "./useChat.js";
|
|
5
5
|
export type ChatLayout = "screen" | "sheet" | "embedded";
|
|
6
6
|
/** The props every shell passes down to its frame. */
|
|
@@ -12,7 +12,7 @@ export interface ChatCommonProps {
|
|
|
12
12
|
loader?: ChatLoaderStyle;
|
|
13
13
|
/** The look: its input ring and send reveal, its panel motion and its motion switch. Unset values take the defaults. */
|
|
14
14
|
look?: ChatLookInput;
|
|
15
|
-
pickAttachments?:
|
|
15
|
+
pickAttachments?: PickAttachments;
|
|
16
16
|
onOpenAttachment?: (part: Extract<ChatPart, {
|
|
17
17
|
kind: "File";
|
|
18
18
|
}>) => void;
|
|
@@ -3,6 +3,8 @@ import type React from "react";
|
|
|
3
3
|
import { type View } from "react-native";
|
|
4
4
|
export interface ChatLauncherProps {
|
|
5
5
|
look: ChatLook;
|
|
6
|
+
/** The chat is open. The launcher leaves: at once, or by shrinking first when the look is expressive. */
|
|
7
|
+
hidden: boolean;
|
|
6
8
|
label: string;
|
|
7
9
|
side: "start" | "end";
|
|
8
10
|
offsetX: number;
|
|
@@ -20,5 +22,5 @@ export interface ChatLauncherProps {
|
|
|
20
22
|
* The floating launcher as the look draws it: round or pill, with its label, the chosen entrance and the
|
|
21
23
|
* float idle. The entrance moves the button's own wrapper, so a scale or a turn happens around the button.
|
|
22
24
|
*/
|
|
23
|
-
export declare function ChatLauncher({ look, label, side, offsetX, offsetY, enter, reduced, mark, avatar, buttonRef, onPress, testID, }: ChatLauncherProps): React.ReactElement;
|
|
25
|
+
export declare function ChatLauncher({ look, hidden, label, side, offsetX, offsetY, enter, reduced, mark, avatar, buttonRef, onPress, testID, }: ChatLauncherProps): React.ReactElement | null;
|
|
24
26
|
//# sourceMappingURL=ChatLauncher.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ChatLabels, ChatLoaderStyle, ChatMotion, ChatPart
|
|
1
|
+
import type { ChatLabels, ChatLoaderStyle, ChatMotion, ChatPart } from "@webority/chat-core";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
4
|
-
import type { ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers } from "./types.js";
|
|
4
|
+
import type { ChatLayoutParts, ChatOpenTicketHandler, ChatRenderers, PickAttachments } from "./types.js";
|
|
5
5
|
import type { UseChatResult } from "./useChat.js";
|
|
6
6
|
export interface ChatThreadProps {
|
|
7
7
|
chat: UseChatResult;
|
|
@@ -14,7 +14,9 @@ export interface ChatThreadProps {
|
|
|
14
14
|
avatar?: string | null;
|
|
15
15
|
/** False hides the pictures beside replies. */
|
|
16
16
|
replyAvatars?: boolean;
|
|
17
|
-
|
|
17
|
+
/** A ring turns around the thinking mark and the streaming reply's picture. Off unless the look sets it. */
|
|
18
|
+
expressive?: boolean;
|
|
19
|
+
pickAttachments?: PickAttachments;
|
|
18
20
|
onOpenAttachment?: (part: Extract<ChatPart, {
|
|
19
21
|
kind: "File";
|
|
20
22
|
}>) => void;
|
|
@@ -36,5 +38,5 @@ export interface ChatThreadProps {
|
|
|
36
38
|
* pill while a paced reply is held, the loader while a reply is awaited and the error row after a
|
|
37
39
|
* failed or stopped turn.
|
|
38
40
|
*/
|
|
39
|
-
export declare function ChatThread({ chat, labels, renderers, layoutParts, loader, motion, avatar, replyAvatars, pickAttachments, onOpenAttachment, onOpenTarget, onNavigate, openTicket, handoffHosts, resolveLink, focusComposer, keyboardAware, keyboardOffset, empty, style, testID, }: ChatThreadProps): React.ReactElement;
|
|
41
|
+
export declare function ChatThread({ chat, labels, renderers, layoutParts, loader, motion, avatar, replyAvatars, expressive, pickAttachments, onOpenAttachment, onOpenTarget, onNavigate, openTicket, handoffHosts, resolveLink, focusComposer, keyboardAware, keyboardOffset, empty, style, testID, }: ChatThreadProps): React.ReactElement;
|
|
40
42
|
//# sourceMappingURL=ChatThread.d.ts.map
|
|
@@ -3,4 +3,5 @@ import type { ChatLiveMessage } from "@webority/chat-core";
|
|
|
3
3
|
export declare function focusForAccessibility(node: unknown): void;
|
|
4
4
|
export declare function messageSignature(message: ChatLiveMessage): string;
|
|
5
5
|
export declare function defaultOpenTarget(target: string): void;
|
|
6
|
+
export declare const WEB_STRONG: object;
|
|
6
7
|
//# sourceMappingURL=chatShared.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
export interface ReplyRingProps {
|
|
3
|
+
active: boolean;
|
|
4
|
+
reduced: boolean;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/** A two-tone ring that turns around its children while a reply is in progress; plain children otherwise. */
|
|
8
|
+
export declare function ReplyRing({ active, reduced, children }: ReplyRingProps): React.JSX.Element;
|
|
9
|
+
//# sourceMappingURL=ReplyRing.d.ts.map
|
|
@@ -27,11 +27,16 @@ export interface ChatTurnHostApi {
|
|
|
27
27
|
/** Moves focus to the composer input after a quick reply is chosen. */
|
|
28
28
|
focusComposer?: () => void;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Opens the app's file picker. accept lists the media types a file question takes;
|
|
32
|
+
* an app may ignore it, the server checks every upload.
|
|
33
|
+
*/
|
|
34
|
+
export type PickAttachments = (accept?: readonly string[]) => Promise<ChatUploadFile[]>;
|
|
30
35
|
export type ChatPartRendererProps<P extends ChatPart = ChatPart> = {
|
|
31
36
|
part: P;
|
|
32
37
|
message: ChatLiveMessage;
|
|
33
38
|
turn: ChatTurnApi & ChatTurnHostApi;
|
|
34
|
-
pickAttachments?:
|
|
39
|
+
pickAttachments?: PickAttachments;
|
|
35
40
|
};
|
|
36
41
|
export type ChatRenderers = Partial<{
|
|
37
42
|
[K in ChatPartKind]: React.ComponentType<ChatPartRendererProps<Extract<ChatPart, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatBehaviour, ChatClient, ChatFeature, ChatSession, ChatSessionState } from "@webority/chat-core";
|
|
1
|
+
import type { ChatAttribution, ChatBehaviour, ChatClient, ChatFeature, ChatSession, ChatSessionState } from "@webority/chat-core";
|
|
2
2
|
import type { ChatLayout } from "./ChatFrame.js";
|
|
3
3
|
export interface ChatPrefs {
|
|
4
4
|
get(key: string): string | null;
|
|
@@ -18,6 +18,8 @@ export interface UseChatOptions {
|
|
|
18
18
|
pageContext?: unknown;
|
|
19
19
|
/** The behaviour the host app measured; read at the moment of sending. */
|
|
20
20
|
behaviour?: () => ChatBehaviour | null;
|
|
21
|
+
/** The campaign touch a lead captured in the chat carries; read at the moment of sending. */
|
|
22
|
+
attribution?: () => ChatAttribution | null;
|
|
21
23
|
/** Where the session keeps the mute choice (key wchat:muted). */
|
|
22
24
|
prefs: ChatPrefs;
|
|
23
25
|
getCaptchaToken?: (action: string) => Promise<string | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.137.0",
|
|
4
4
|
"description": "Webority Chat for React Native apps: the chat screen, sheet and embedded shells, thread, composer, one renderer per message part kind and the useChat hook, built on @webority/chat-core and @webority/mobile-ui.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"!**/*.map"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@webority/chat-core": "0.
|
|
46
|
-
"@webority/markdown-core": "^0.
|
|
47
|
-
"@webority/mobile-core": "^0.
|
|
48
|
-
"@webority/mobile-ui": "^0.
|
|
45
|
+
"@webority/chat-core": "0.137.0",
|
|
46
|
+
"@webority/markdown-core": "^0.134.0",
|
|
47
|
+
"@webority/mobile-core": "^0.134.0",
|
|
48
|
+
"@webority/mobile-ui": "^0.134.0",
|
|
49
49
|
"expo-audio": ">=57.0.0",
|
|
50
50
|
"expo-file-system": ">=57.0.0",
|
|
51
51
|
"react": "^19.1.0",
|
|
@@ -96,12 +96,13 @@
|
|
|
96
96
|
"@react-native/jest-preset": "0.86.3",
|
|
97
97
|
"@react-native/metro-config": "0.86.3",
|
|
98
98
|
"@testing-library/react-native": "12.9.0",
|
|
99
|
+
"@types/jest": "29.5.14",
|
|
99
100
|
"@types/react": "19.2.18",
|
|
100
|
-
"@webority/canvas-kit": "0.
|
|
101
|
-
"@webority/chat-core": "0.
|
|
102
|
-
"@webority/markdown-core": "0.
|
|
103
|
-
"@webority/mobile-core": "0.
|
|
104
|
-
"@webority/mobile-ui": "0.
|
|
101
|
+
"@webority/canvas-kit": "0.134.0",
|
|
102
|
+
"@webority/chat-core": "0.137.0",
|
|
103
|
+
"@webority/markdown-core": "0.134.0",
|
|
104
|
+
"@webority/mobile-core": "0.134.0",
|
|
105
|
+
"@webority/mobile-ui": "0.134.0",
|
|
105
106
|
"babel-jest": "29.7.0",
|
|
106
107
|
"expo": "57.0.31",
|
|
107
108
|
"expo-application": "57.0.3",
|
|
@@ -134,7 +135,7 @@
|
|
|
134
135
|
"clean": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\"",
|
|
135
136
|
"lint": "biome lint ./src",
|
|
136
137
|
"lint:fix": "biome lint --write ./src",
|
|
137
|
-
"test": "jest",
|
|
138
|
+
"test": "tsc -p tsconfig.test.json && jest",
|
|
138
139
|
"typecheck": "tsc --noEmit"
|
|
139
140
|
}
|
|
140
141
|
}
|