@webority/mobile-chat 0.141.0 → 0.143.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.
Files changed (99) hide show
  1. package/lib/commonjs/AgentByline.js +1 -1
  2. package/lib/commonjs/ChatComposer.js +1 -1
  3. package/lib/commonjs/ChatConversationActions.js +1 -1
  4. package/lib/commonjs/ChatLauncher.js +1 -1
  5. package/lib/commonjs/ChatMessageActions.js +1 -1
  6. package/lib/commonjs/ChatOpenTickets.js +1 -1
  7. package/lib/commonjs/ChatPastChats.js +1 -1
  8. package/lib/commonjs/ChatSheet.js +1 -1
  9. package/lib/commonjs/ChatStarters.js +1 -1
  10. package/lib/commonjs/ChatThread.js +1 -1
  11. package/lib/commonjs/chatShared.js +1 -1
  12. package/lib/commonjs/expoModules.js +1 -0
  13. package/lib/commonjs/iconName.js +1 -0
  14. package/lib/commonjs/loaders/ChatLoader.js +1 -1
  15. package/lib/commonjs/renderers/ActionPart.js +1 -1
  16. package/lib/commonjs/renderers/ChartPart.js +1 -1
  17. package/lib/commonjs/renderers/FigureText.js +1 -1
  18. package/lib/commonjs/renderers/FilePart.js +1 -1
  19. package/lib/commonjs/renderers/HandoffPart.js +1 -1
  20. package/lib/commonjs/renderers/InputRequestPart.js +1 -1
  21. package/lib/commonjs/renderers/NoticePart.js +1 -1
  22. package/lib/commonjs/renderers/QuickRepliesPart.js +1 -1
  23. package/lib/commonjs/renderers/SourcesPart.js +1 -1
  24. package/lib/commonjs/renderers/TextPart.js +1 -1
  25. package/lib/commonjs/renderers/VoiceClipPart.js +1 -1
  26. package/lib/commonjs/speech/azureSpeech.js +1 -1
  27. package/lib/commonjs/speech/expoAudio.js +1 -1
  28. package/lib/commonjs/speech/phoneSpeech.js +1 -1
  29. package/lib/commonjs/useChat.js +1 -1
  30. package/lib/commonjs/useChatSound.js +1 -1
  31. package/lib/commonjs/useTranscriptActions.js +1 -1
  32. package/lib/module/AgentByline.js +1 -1
  33. package/lib/module/ChatComposer.js +1 -1
  34. package/lib/module/ChatConversationActions.js +1 -1
  35. package/lib/module/ChatLauncher.js +1 -1
  36. package/lib/module/ChatMessageActions.js +1 -1
  37. package/lib/module/ChatOpenTickets.js +1 -1
  38. package/lib/module/ChatPastChats.js +1 -1
  39. package/lib/module/ChatSheet.js +1 -1
  40. package/lib/module/ChatStarters.js +1 -1
  41. package/lib/module/ChatThread.js +1 -1
  42. package/lib/module/chatShared.js +1 -1
  43. package/lib/module/expoModules.js +1 -0
  44. package/lib/module/iconName.js +1 -0
  45. package/lib/module/loaders/ChatLoader.js +1 -1
  46. package/lib/module/renderers/ActionPart.js +1 -1
  47. package/lib/module/renderers/ChartPart.js +1 -1
  48. package/lib/module/renderers/FigureText.js +1 -1
  49. package/lib/module/renderers/FilePart.js +1 -1
  50. package/lib/module/renderers/HandoffPart.js +1 -1
  51. package/lib/module/renderers/InputRequestPart.js +1 -1
  52. package/lib/module/renderers/NoticePart.js +1 -1
  53. package/lib/module/renderers/QuickRepliesPart.js +1 -1
  54. package/lib/module/renderers/SourcesPart.js +1 -1
  55. package/lib/module/renderers/TextPart.js +1 -1
  56. package/lib/module/renderers/VoiceClipPart.js +1 -1
  57. package/lib/module/speech/azureSpeech.js +1 -1
  58. package/lib/module/speech/expoAudio.js +1 -1
  59. package/lib/module/speech/phoneSpeech.js +1 -1
  60. package/lib/module/useChat.js +1 -1
  61. package/lib/module/useChatSound.js +1 -1
  62. package/lib/module/useTranscriptActions.js +1 -1
  63. package/lib/typescript/commonjs/ChatAppearanceScope.d.ts +1 -1
  64. package/lib/typescript/commonjs/ChatComposer.d.ts +6 -6
  65. package/lib/typescript/commonjs/ChatFrame.d.ts +17 -17
  66. package/lib/typescript/commonjs/ChatOpenTickets.d.ts +1 -1
  67. package/lib/typescript/commonjs/ChatSheet.d.ts +3 -3
  68. package/lib/typescript/commonjs/ChatStarters.d.ts +1 -1
  69. package/lib/typescript/commonjs/ChatThread.d.ts +13 -13
  70. package/lib/typescript/commonjs/chatShared.d.ts +2 -1
  71. package/lib/typescript/commonjs/expoModules.d.ts +58 -0
  72. package/lib/typescript/commonjs/iconName.d.ts +3 -0
  73. package/lib/typescript/commonjs/renderers/ActionPart.d.ts +6 -1
  74. package/lib/typescript/commonjs/renderers/FilePart.d.ts +4 -1
  75. package/lib/typescript/commonjs/renderers/InputRequestPart.d.ts +6 -1
  76. package/lib/typescript/commonjs/renderers/NoticePart.d.ts +1 -1
  77. package/lib/typescript/commonjs/renderers/index.d.ts +40 -2
  78. package/lib/typescript/commonjs/types.d.ts +1 -1
  79. package/lib/typescript/commonjs/useChat.d.ts +2 -2
  80. package/lib/typescript/commonjs/useChatSound.d.ts +1 -1
  81. package/lib/typescript/module/ChatAppearanceScope.d.ts +1 -1
  82. package/lib/typescript/module/ChatComposer.d.ts +6 -6
  83. package/lib/typescript/module/ChatFrame.d.ts +17 -17
  84. package/lib/typescript/module/ChatOpenTickets.d.ts +1 -1
  85. package/lib/typescript/module/ChatSheet.d.ts +3 -3
  86. package/lib/typescript/module/ChatStarters.d.ts +1 -1
  87. package/lib/typescript/module/ChatThread.d.ts +13 -13
  88. package/lib/typescript/module/chatShared.d.ts +2 -1
  89. package/lib/typescript/module/expoModules.d.ts +58 -0
  90. package/lib/typescript/module/iconName.d.ts +3 -0
  91. package/lib/typescript/module/renderers/ActionPart.d.ts +6 -1
  92. package/lib/typescript/module/renderers/FilePart.d.ts +4 -1
  93. package/lib/typescript/module/renderers/InputRequestPart.d.ts +6 -1
  94. package/lib/typescript/module/renderers/NoticePart.d.ts +1 -1
  95. package/lib/typescript/module/renderers/index.d.ts +40 -2
  96. package/lib/typescript/module/types.d.ts +1 -1
  97. package/lib/typescript/module/useChat.d.ts +2 -2
  98. package/lib/typescript/module/useChatSound.d.ts +1 -1
  99. package/package.json +11 -11
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AgentByline=AgentByline;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function AgentByline({author:e,labels:i,showAvatar:t=!0}){const r=(0,_mobileUi.useTheme)(),a=e.displayName||i.agent,n=e.avatarUrl?{uri:e.avatarUrl}:void 0;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row",alignItems:"center",gap:r.space.xs},children:[t?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:a,source:n}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:i.agent})]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AgentByline=AgentByline;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function AgentByline({author:e,labels:i,showAvatar:t=!0}){const r=(0,_mobileUi.useTheme)(),a=e.displayName||i.agent,n=e.avatarUrl?{uri:e.avatarUrl}:void 0;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row",alignItems:"center",gap:r.space.xs},children:[t?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:a,...void 0===n?{}:{source:n}}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:i.agent})]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatComposer=ChatComposer;var _chatCore=require("@webority/chat-core"),_permissions=require("@webority/mobile-core/permissions"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatDictationButton=require("./ChatDictationButton.js"),_ChatFooter=require("./ChatFooter.js"),_speechText=require("./speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:i,safeArea:n,testID:o="chat-composer",focusRef:r,look:l=_chatCore.defaultChatLook,sendIcon:c}){const u=(0,_mobileUi.useTheme)(),m=(0,_react.useMemo)(()=>buildStyles(u),[u]),[h,d]=(0,_react.useState)(""),[p,_]=(0,_react.useState)(null),x=e.editing,f=(0,_react.useRef)(null),g=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(r)return r.current=()=>g.current?.focus(),()=>{r.current=null}},[r]),(0,_react.useEffect)(()=>{x&&f.current?.(),d(x?x.text:"")},[x]);const b=e.attachments,j=b.some(e=>"Uploading"===e.status),v=b.some(e=>"Ready"===e.status),y=e.messagesLeftToday,R=e.profile?.limits.maxMessageLength??DEFAULT_MAX_LENGTH,C=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,A=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),T=C&&!e.handoffPause?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${o}-attach`}):void 0,S=x?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${o}-editing`}):null,D=b.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.tray,testID:`${o}-attachments`,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.row,children:b.map(s=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.item,children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{remove:t.removeAttachment},removeTestID:`${o}-remove-${s.key}`,testID:`${o}-chip-${s.key}`}),"Uploading"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:s.progress??void 0,label:t.attachmentUploading,height:4,containerStyle:m.progress}):null,"Failed"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.error??t.attachmentFailed}):null]},s.key))})}):null,U=null!==y&&y<=ALLOWANCE_SHOWN_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:0===y?"danger":"secondary",accessibilityLiveRegion:"polite",testID:`${o}-allowance`,children:t.allowance(y)}):null,w=p?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:p.message,tone:p.tone,dismissible:!0,onClose:()=>_(null),actions:p.openSettings?[{label:t.dictateOpenSettings,onPress:()=>{_permissions.Permissions.openSettings()}}]:void 0,testID:`${o}-voice-notice`}):null,L=h.length>0,N=h.length>R*COUNTER_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",testID:`${o}-counter`,children:t.counter(h.length,R)}):null,I=S||D||U||N||w?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[S,D,U,N,w]}):void 0,k=!j&&(!!v||void 0);return(0,_jsxRuntime.jsx)(_mobileUi.Composer,{ref:g,onSend:t=>{f.current?.(),e.submit(t)},value:h,onChangeText:t=>{f.current?.(),d(t),A&&t.length>0&&e.notifyTyping()},loading:e.streaming&&e.features.Stop,ring:l.input.ring&&(L||e.streaming),sendReveal:"Always"===l.input.sendReveal?"always":"onText",sendIcon:c||void 0,onStop:e.features.Stop?()=>e.stop():void 0,stopLabel:t.stop,disabled:0===y||e.handoffPause,maxLength:R,canSend:k,placeholder:e.handoffPause?t.handoffMoment:openQuestion(e.messages)??t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:T,trailing:(0,_jsxRuntime.jsx)(_ChatDictationButton.ChatDictationButton,{chat:e,labels:t,disabled:0===y||e.handoffPause,onText:e=>d(t=>(0,_speechText.joinDictation)(t,e,R)),onNotice:_,stopRef:f}),above:I,below:(0,_jsxRuntime.jsx)(_ChatFooter.ChatFooter,{chat:e,labels:t}),keyboardAware:i,keyboardOffset:a,safeArea:n,testID:o})}const buildStyles=e=>_reactNative.StyleSheet.create({tray:{gap:e.space.xs},row:{flexDirection:"row",flexWrap:"wrap",gap:e.space.xs},item:{gap:e.space.xxs,maxWidth:"100%"},progress:{minWidth:120}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatComposer=ChatComposer;var _chatCore=require("@webority/chat-core"),_permissions=require("@webority/mobile-core/permissions"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatDictationButton=require("./ChatDictationButton.js"),_ChatFooter=require("./ChatFooter.js"),_iconName=require("./iconName.js"),_speechText=require("./speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const ALLOWANCE_SHOWN_AT=10,COUNTER_AT=.9,DEFAULT_MAX_LENGTH=4e3,openQuestion=e=>{for(let t=e.length-1;t>=0;t-=1){const s=e[t];for(const e of[...s?.parts??[]].reverse())if("InputRequest"===e.kind&&"Open"===e.state)return e.fields[0]?.label||e.title||null}return null};function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:i,safeArea:n,testID:o="chat-composer",focusRef:r,look:l=_chatCore.defaultChatLook,sendIcon:c}){const u=(0,_mobileUi.useTheme)(),m=(0,_react.useMemo)(()=>buildStyles(u),[u]),[h,d]=(0,_react.useState)(""),[p,_]=(0,_react.useState)(null),x=e.editing,g=(0,_react.useRef)(null),f=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(r)return r.current=()=>f.current?.focus(),()=>{r.current=null}},[r]),(0,_react.useEffect)(()=>{x&&g.current?.(),d(x?x.text:"")},[x]);const b=e.attachments,j=b.some(e=>"Uploading"===e.status),v=b.some(e=>"Ready"===e.status),y=e.messagesLeftToday,R=e.profile?.limits.maxMessageLength??DEFAULT_MAX_LENGTH,C=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,A=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),T=C&&!e.handoffPause?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${o}-attach`}):void 0,N=x?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${o}-editing`}):null,S=b.length>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.tray,testID:`${o}-attachments`,children:(0,_jsxRuntime.jsx)(_reactNative.View,{style:m.row,children:b.map(s=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:m.item,children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{remove:t.removeAttachment},removeTestID:`${o}-remove-${s.key}`,testID:`${o}-chip-${s.key}`}),"Uploading"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{...null===s.progress||void 0===s.progress?{}:{progress:s.progress},label:t.attachmentUploading,height:4,containerStyle:m.progress}):null,"Failed"===s.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.error??t.attachmentFailed}):null]},s.key))})}):null,D=null!==y&&y<=ALLOWANCE_SHOWN_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:0===y?"danger":"secondary",accessibilityLiveRegion:"polite",testID:`${o}-allowance`,children:t.allowance(y)}):null,U=p?(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:p.message,tone:p.tone,dismissible:!0,onClose:()=>_(null),...p.openSettings?{actions:[{label:t.dictateOpenSettings,onPress:()=>{_permissions.Permissions.openSettings()}}]}:{},testID:`${o}-voice-notice`}):null,w=h.length>0,L=h.length>R*COUNTER_AT?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",testID:`${o}-counter`,children:t.counter(h.length,R)}):null,I=N||S||D||L||U?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[N,S,D,L,U]}):void 0,k=!j&&(!!v||void 0),O=(0,_iconName.iconNameOf)(c);return(0,_jsxRuntime.jsx)(_mobileUi.Composer,{ref:f,onSend:t=>{g.current?.(),e.submit(t)},value:h,onChangeText:t=>{g.current?.(),d(t),A&&t.length>0&&e.notifyTyping()},loading:e.streaming&&e.features.Stop,ring:l.input.ring&&(w||e.streaming),sendReveal:"Always"===l.input.sendReveal?"always":"onText",...O?{sendIcon:O}:{},...e.features.Stop?{onStop:()=>e.stop()}:{},stopLabel:t.stop,disabled:0===y||e.handoffPause,maxLength:R,...void 0===k?{}:{canSend:k},placeholder:e.handoffPause?t.handoffMoment:openQuestion(e.messages)??t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:T,trailing:(0,_jsxRuntime.jsx)(_ChatDictationButton.ChatDictationButton,{chat:e,labels:t,disabled:0===y||e.handoffPause,onText:e=>d(t=>(0,_speechText.joinDictation)(t,e,R)),onNotice:_,stopRef:g}),above:I,below:(0,_jsxRuntime.jsx)(_ChatFooter.ChatFooter,{chat:e,labels:t}),...void 0===i?{}:{keyboardAware:i},...void 0===a?{}:{keyboardOffset:a},...void 0===n?{}:{safeArea:n},testID:o})}const buildStyles=e=>_reactNative.StyleSheet.create({tray:{gap:e.space.xs},row:{flexDirection:"row",flexWrap:"wrap",gap:e.space.xs},item:{gap:e.space.xxs,maxWidth:"100%"},progress:{minWidth:120}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatConversationActions=ChatConversationActions;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_useTranscriptActions=_interopRequireDefault(require("./useTranscriptActions.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const REPLY_AUTHORS=new Set(["Assistant","Agent","Script"]);function ChatConversationActions({chat:e,labels:t,testID:i}){const n=(0,_useTranscriptActions.default)(e,t),s=e.messages.some(e=>e.stored&&REPLY_AUTHORS.has(e.author.kind)&&""!==(0,_chatCore.messagePlainText)(e.parts));return e.streaming||e.thinking||e.loading||null===e.conversationId||!s||!n.canShare?null:(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"share",variant:"ghost",size:"sm",accessibilityLabel:t.shareConversation,onPress:()=>{n.shareConversation()},testID:i}),null!==n.notice?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:n.notice}):null]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatConversationActions=ChatConversationActions;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_useTranscriptActions=_interopRequireDefault(require("./useTranscriptActions.js")),_jsxRuntime=require("react/jsx-runtime");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const REPLY_AUTHORS=new Set(["Assistant","Agent","Script"]);function ChatConversationActions({chat:e,labels:t,testID:i}){const n=(0,_useTranscriptActions.default)(e,t),s=e.messages.some(e=>e.stored&&REPLY_AUTHORS.has(e.author.kind)&&""!==(0,_chatCore.messagePlainText)(e.parts));return e.streaming||e.thinking||e.loading||null===e.conversationId||!s||!n.canShare?null:(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"share",variant:"ghost",size:"sm",accessibilityLabel:t.shareConversation,onPress:()=>{n.shareConversation()},...void 0===i?{}:{testID:i}}),null!==n.notice?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:n.notice}):null]})}
@@ -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,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
+ "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 rangeNumber=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:rangeNumber([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:rangeNumber([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:rangeNumber([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:rangeNumber([0,.5,1],[0,1,1]),transform:[{scale:rangeNumber([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:rangeNumber([0,.4,1],[100,0,0])},{rotate:(a=[0,.4,.6,.8,1],n=["-10deg","5deg","-3deg","1deg","0deg"],t.interpolate({inputRange:a,outputRange:n,extrapolate:"clamp"}))}]};case"ElasticIn":return{transform:[{scale:rangeNumber([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}var a,n}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:p}){const m=(0,_mobileUi.useTheme)(),d=(0,_reactNativeSafeAreaContext.useSafeAreaInsets)(),g=e.launcher.entrance,S="Avatar"===u&&c?c:null,v=m.components["floating-action-button"].md.diameter,[N]=(0,_react.useState)(()=>s&&!o&&"None"!==g),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,x]=(0,_react.useState)(!1);if((0,_react.useEffect)(()=>{if(!t)return b.setValue(1),void x(!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&&x(!0)}),()=>e.stop()},[t,f,b]),(0,_react.useEffect)(()=>{if(!N)return void A.setValue(1);const e="Rise"===g,t=_reactNative.Animated.timing(A,{toValue:1,duration:e?RISE_MS:ENTRANCE_MS,delay:e?RISE_DELAY_MS:ENTRANCE_DELAY_MS,easing:OVERSHOOT.has(g)?_reactNative.Easing.bezier(.34,e?1.4:1.56,.64,1):_reactNative.Easing.linear,useNativeDriver:!0});return t.start(),()=>t.stop()},[N,g,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 I="Pill"===e.launcher.style&&!e.launcher.compact,y=m.space[m.components["floating-action-button"]["edge-offset"]]+r,L={position:"absolute",bottom:i+d.bottom,..."start"===n?{left:y}:{right:y}},M=entranceStyle(g,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:S?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{dimension:v,name:a,source:{uri:S}}):"messages",...I?{label:a}:{},collapsed:!I,accessibilityLabel:a,onPress:_,testID:p})})})}
@@ -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"),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
+ "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:n}){const r=(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,...void 0===e.profile?.assistant.name?{}:{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,p=t.stored&&RATED_AUTHORS.has(t.author.kind),x=("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||x||b||R||p&&e.features.Rating?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:r.space.xs},testID:n,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:`${n}-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:`${n}-share`}):null,x?(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:`${n}-regenerate`}):null,R?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:i.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${n}-edit`}):null,p&&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:r.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:`${n}-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:`${n}-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.ChatOpenTickets=ChatOpenTickets;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const SHOWN_AT_MOST=3;function ChatOpenTickets({chat:e,labels:t,onOpenTicket:i,testID:s="chat-open-tickets"}){const n=(0,_mobileUi.useTheme)();return e.features.OpenTickets&&0!==e.openTickets.length?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.openTickets,style:{gap:n.space.xs},testID:s,children:e.openTickets.slice(0,SHOWN_AT_MOST).map(e=>{const n=i?()=>i({ticketId:e.ticketId,number:e.number}):void 0;return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",interactive:void 0!==n,onPress:n,testID:`${s}-${e.ticketId}`,children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:t.ticketAria(e.number)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",numberOfLines:1,children:e.subject}),(0,_jsxRuntime.jsx)(_mobileUi.Chip,{size:"sm",variant:"soft",label:t.ticketStatus(e.status)||e.status})]},e.ticketId)})}):null}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatOpenTickets=ChatOpenTickets;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const SHOWN_AT_MOST=3;function ChatOpenTickets({chat:e,labels:t,onOpenTicket:i,testID:s="chat-open-tickets"}){const n=(0,_mobileUi.useTheme)();return e.features.OpenTickets&&0!==e.openTickets.length?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.openTickets,style:{gap:n.space.xs},testID:s,children:e.openTickets.slice(0,SHOWN_AT_MOST).map(e=>{const n=i?()=>i({ticketId:e.ticketId,number:e.number}):void 0;return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",interactive:void 0!==n,...void 0===n?{}:{onPress:n},testID:`${s}-${e.ticketId}`,children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:t.ticketAria(e.number)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",numberOfLines:1,children:e.subject}),(0,_jsxRuntime.jsx)(_mobileUi.Chip,{size:"sm",variant:"soft",label:t.ticketStatus(e.status)||e.status})]},e.ticketId)})}):null}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatPastChats=ChatPastChats,exports.ConversationRow=ConversationRow;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const PAGE_SIZE=20,EMPTY_LIST_STATE=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),NO_SUBSCRIPTION=()=>()=>{};function ChatPastChats({chat:e,labels:t,testID:i="chat-past-chats"}){const n=(0,_mobileUi.useTheme)(),s=!0===e.features.History,[a,l]=(0,_react.useState)(null),r=s&&null!==a&&a.client===e.client?a.list:null,o=(0,_react.useCallback)(e=>r?r.subscribe(e):NO_SUBSCRIPTION(),[r]),c=(0,_react.useCallback)(()=>r?r.getState():EMPTY_LIST_STATE,[r]),u=(0,_react.useSyncExternalStore)(o,c);if((0,_react.useEffect)(()=>{if(!s)return;const t=(0,_chatCore.createConversationList)({client:e.client});return l({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client,s]),!s||0===u.items.length)return null;const open=t=>{e.openConversation(t.publicId)};return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{gap:n.space.sm},testID:i,children:u.items.slice(0,PAGE_SIZE).map(n=>(0,_jsxRuntime.jsx)(ConversationRow,{conversation:n,list:r,chat:e,labels:t,testID:i,onOpen:open},n.publicId))})}function ConversationRow({conversation:e,list:t,chat:i,labels:n,testID:s,onOpen:a,untitledTitle:l}){const r=(0,_mobileUi.useTheme)(),[o,c]=(0,_react.useState)("idle"),[u,m]=(0,_react.useState)(""),[_,d]=(0,_react.useState)(""),[x,b]=(0,_react.useState)(!1),j=e.publicId,h=e.title||l||n.earlierChat,v=(0,_chatCore.formatChatDate)(e.lastActivityDateTimeUtc),cancel=()=>{d(""),c("idle")},saveRename=async()=>{const e=u.trim();if(!x&&t&&""!==e){b(!0),d("");try{await t.rename(j,e),c("idle")}catch{d(n.renameFailed)}finally{b(!1)}}};return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",onPress:"idle"===o?()=>a(e):void 0,accessibilityLabel:`${h}, ${v}`,testID:`${s}-item-${j}`,children:["idle"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:r.space.sm},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1,minWidth:0},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",numberOfLines:1,children:h}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:v})]}),i.features.Rename?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"edit",variant:"ghost",accessibilityLabel:n.rename,onPress:()=>{d(""),m(e.title??""),c("renaming")},testID:`${s}-rename-${j}`}):null,i.features.Delete?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"trash",tone:"danger",variant:"ghost",accessibilityLabel:n.deleteChat,onPress:()=>{d(""),c("deleting")},testID:`${s}-delete-${j}`}):null]}):null,"renaming"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:n.conversationTitle,value:u,onChangeText:m,maxLength:120,returnKeyType:"done",onSubmitEditing:()=>{saveRename()},testID:`${s}-rename-input-${j}`}),""!==_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",testID:`${s}-rename-error-${j}`,children:_}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.cancel,variant:"ghost",disabled:x,onPress:cancel,testID:`${s}-rename-cancel-${j}`}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.renameSave,disabled:""===u.trim()||x,loading:x,onPress:()=>{saveRename()},testID:`${s}-rename-save-${j}`})]})]}):null,"deleting"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:""!==_?"danger":"secondary",accessibilityLiveRegion:""!==_?"polite":void 0,testID:`${s}-delete-message-${j}`,children:""!==_?_:n.deleteConfirmMessage}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.cancel,variant:"ghost",disabled:x,onPress:cancel,testID:`${s}-delete-cancel-${j}`}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.deleteConfirm,tone:"danger",loading:x,onPress:()=>{(async()=>{if(!x&&t){b(!0),d("");try{await t.remove(j),j===i.conversationId&&i.newConversation(),c("idle")}catch{d(n.deleteFailed)}finally{b(!1)}}})()},testID:`${s}-delete-confirm-${j}`})]})]}):null]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatPastChats=ChatPastChats,exports.ConversationRow=ConversationRow;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const PAGE_SIZE=20,EMPTY_LIST_STATE=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),NO_SUBSCRIPTION=()=>()=>{};function ChatPastChats({chat:e,labels:t,testID:i="chat-past-chats"}){const n=(0,_mobileUi.useTheme)(),a=!0===e.features.History,[s,l]=(0,_react.useState)(null),r=a&&null!==s&&s.client===e.client?s.list:null,o=(0,_react.useCallback)(e=>r?r.subscribe(e):NO_SUBSCRIPTION(),[r]),c=(0,_react.useCallback)(()=>r?r.getState():EMPTY_LIST_STATE,[r]),u=(0,_react.useSyncExternalStore)(o,c);if((0,_react.useEffect)(()=>{if(!a)return;const t=(0,_chatCore.createConversationList)({client:e.client});return l({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client,a]),!a||0===u.items.length)return null;const open=t=>{e.openConversation(t.publicId)};return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{gap:n.space.sm},testID:i,children:u.items.slice(0,PAGE_SIZE).map(n=>(0,_jsxRuntime.jsx)(ConversationRow,{conversation:n,list:r,chat:e,labels:t,testID:i,onOpen:open},n.publicId))})}function ConversationRow({conversation:e,list:t,chat:i,labels:n,testID:a,onOpen:s,untitledTitle:l}){const r=(0,_mobileUi.useTheme)(),[o,c]=(0,_react.useState)("idle"),[u,m]=(0,_react.useState)(""),[_,d]=(0,_react.useState)(""),[x,b]=(0,_react.useState)(!1),h=e.publicId,j=e.title||l||n.earlierChat,v=(0,_chatCore.formatChatDate)(e.lastActivityDateTimeUtc),cancel=()=>{d(""),c("idle")},saveRename=async()=>{const e=u.trim();if(!x&&t&&""!==e){b(!0),d("");try{await t.rename(h,e),c("idle")}catch(e){_mobileCore.Logger.error("[chat] rename failed",e),d(n.renameFailed)}finally{b(!1)}}};return(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",..."idle"===o?{onPress:()=>s(e)}:{},accessibilityLabel:`${j}, ${v}`,testID:`${a}-item-${h}`,children:["idle"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:r.space.sm},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flex:1,minWidth:0},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",numberOfLines:1,children:j}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:v})]}),i.features.Rename?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"edit",variant:"ghost",accessibilityLabel:n.rename,onPress:()=>{d(""),m(e.title??""),c("renaming")},testID:`${a}-rename-${h}`}):null,i.features.Delete?(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:"trash",tone:"danger",variant:"ghost",accessibilityLabel:n.deleteChat,onPress:()=>{d(""),c("deleting")},testID:`${a}-delete-${h}`}):null]}):null,"renaming"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:n.conversationTitle,value:u,onChangeText:m,maxLength:120,returnKeyType:"done",onSubmitEditing:()=>{saveRename()},testID:`${a}-rename-input-${h}`}),""!==_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",testID:`${a}-rename-error-${h}`,children:_}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.cancel,variant:"ghost",disabled:x,onPress:cancel,testID:`${a}-rename-cancel-${h}`}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.renameSave,disabled:""===u.trim()||x,loading:x,onPress:()=>{saveRename()},testID:`${a}-rename-save-${h}`})]})]}):null,"deleting"===o?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:""!==_?"danger":"secondary",accessibilityLiveRegion:""!==_?"polite":void 0,testID:`${a}-delete-message-${h}`,children:""!==_?_:n.deleteConfirmMessage}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.cancel,variant:"ghost",disabled:x,onPress:cancel,testID:`${a}-delete-cancel-${h}`}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:n.deleteConfirm,tone:"danger",loading:x,onPress:()=>{(async()=>{if(!x&&t){b(!0),d("");try{await t.remove(h),h===i.conversationId&&i.newConversation(),c("idle")}catch(e){_mobileCore.Logger.error("[chat] delete failed",e),d(n.deleteFailed)}finally{b(!1)}}})()},testID:`${a}-delete-confirm-${h}`})]})]}):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:[(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
+ "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,...void 0===d?{}:{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.ChatStarters=ChatStarters;var _mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatEntrance=require("./ChatEntrance.js"),_ChatOpenTickets=require("./ChatOpenTickets.js"),_ChatPastChats=require("./ChatPastChats.js"),_TypingPill=require("./loaders/TypingPill.js"),_chipLook=require("./renderers/chipLook.js"),_jsxRuntime=require("react/jsx-runtime");function ChatStarters({chat:e,labels:t,openTicket:i,avatar:s,motion:a="On",greetingLoaderMs:r=0,testID:n="chat-starters"}){const l=(0,_mobileUi.useTheme)(),[c,o]=(0,_react.useState)(!(r>0));(0,_react.useEffect)(()=>{if(c)return;const e=setTimeout(()=>o(!0),r);return()=>clearTimeout(e)},[c,r]);const u=e.profile,m=e.greeting??"";if(!u)return null;const _=u.assistant.intro,x=e.features.Starters&&e.starters.length>0,j=e.lastConversation,h=e.features.ResumeLast&&!e.features.History&&null!==j;return(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:l.space.md,padding:l.space.md},testID:n,children:c?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[s?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"lg",name:e.profile?.assistant.name??t.panelTitle,source:{uri:s}})}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"h2",align:"center",children:m}),_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",color:"secondary",align:"center",children:_}):null,x?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"none",accessibilityLabel:t.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:l.space.xs},children:e.starters.map((t,i)=>(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{...t.variant?(0,_chipLook.chipLook)(t.variant):null,label:t.label,leftIcon:t.icon?t.icon:void 0,onPress:()=>{e.submit(t.message)},testID:`${n}-${t.id}`})},t.id))}):null,h&&j?(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",onPress:()=>{e.resumeLast()},testID:`${n}-resume`,children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:t.resumeLast}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",numberOfLines:1,children:j.title||t.untitled}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_mobileCore.formatDate)(j.lastActivityDateTimeUtc)})]}):null,e.features.History?(0,_jsxRuntime.jsx)(_ChatPastChats.ChatPastChats,{chat:e,labels:t,testID:`${n}-past-chats`}):null,(0,_jsxRuntime.jsx)(_ChatOpenTickets.ChatOpenTickets,{chat:e,labels:t,onOpenTicket:i})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{children:(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:a,mark:s?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:s}}):null})})})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatStarters=ChatStarters;var _mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_ChatEntrance=require("./ChatEntrance.js"),_ChatOpenTickets=require("./ChatOpenTickets.js"),_ChatPastChats=require("./ChatPastChats.js"),_iconName=require("./iconName.js"),_TypingPill=require("./loaders/TypingPill.js"),_chipLook=require("./renderers/chipLook.js"),_jsxRuntime=require("react/jsx-runtime");function ChatStarters({chat:e,labels:t,openTicket:i,avatar:s,motion:a="On",greetingLoaderMs:r=0,testID:n="chat-starters"}){const l=(0,_mobileUi.useTheme)(),[c,o]=(0,_react.useState)(!(r>0));(0,_react.useEffect)(()=>{if(c)return;const e=setTimeout(()=>o(!0),r);return()=>clearTimeout(e)},[c,r]);const u=e.profile,m=e.greeting??"";if(!u)return null;const _=u.assistant.intro,x=e.features.Starters&&e.starters.length>0,j=e.lastConversation,h=e.features.ResumeLast&&!e.features.History&&null!==j;return(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityLabel:t.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:l.space.md,padding:l.space.md},testID:n,children:c?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[s?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"lg",name:e.profile?.assistant.name??t.panelTitle,source:{uri:s}})}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"h2",align:"center",children:m}),_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",color:"secondary",align:"center",children:_}):null,x?(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"none",accessibilityLabel:t.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:l.space.xs},children:e.starters.map((t,i)=>{const s=(0,_iconName.iconNameOf)(t.icon);return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{...t.variant?(0,_chipLook.chipLook)(t.variant):null,label:t.label,...null===s?{}:{leftIcon:s},onPress:()=>{e.submit(t.message)},testID:`${n}-${t.id}`})},t.id)})}):null,h&&j?(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",onPress:()=>{e.resumeLast()},testID:`${n}-resume`,children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:t.resumeLast}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",numberOfLines:1,children:j.title||t.untitled}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_mobileCore.formatDate)(j.lastActivityDateTimeUtc)})]}):null,e.features.History?(0,_jsxRuntime.jsx)(_ChatPastChats.ChatPastChats,{chat:e,labels:t,testID:`${n}-past-chats`}):null,(0,_jsxRuntime.jsx)(_ChatOpenTickets.ChatOpenTickets,{chat:e,labels:t,onOpenTicket:i})]}):(0,_jsxRuntime.jsx)(_reactNative.View,{children:(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:a,mark:s?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:s}}):null})})})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatThread=ChatThread;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_AgentByline=require("./AgentByline.js"),_ChatEntrance=require("./ChatEntrance.js"),_ChatMessageActions=require("./ChatMessageActions.js"),_chatShared=require("./chatShared.js"),_ChatLoader=require("./loaders/ChatLoader.js"),_ReplyRing=require("./loaders/ReplyRing.js"),_TypingPill=require("./loaders/TypingPill.js"),_index=require("./renderers/index.js"),_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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatThread=ChatThread;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_AgentByline=require("./AgentByline.js"),_ChatEntrance=require("./ChatEntrance.js"),_ChatMessageActions=require("./ChatMessageActions.js"),_chatShared=require("./chatShared.js"),_ChatLoader=require("./loaders/ChatLoader.js"),_ReplyRing=require("./loaders/ReplyRing.js"),_TypingPill=require("./loaders/TypingPill.js"),_index=require("./renderers/index.js"),_jsxRuntime=require("react/jsx-runtime");const MINE=new Set(["Visitor","Customer"]),visuallyHidden={position:"absolute",left:-1e4,width:1,height:1,overflow:"hidden"},joinedText=e=>e.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n");function isKind(e,t){return e.kind===t}const kindWrappers=new WeakMap;function forKind(e,t){const s=kindWrappers.get(t)??new Map,i=s.get(e);if(i)return i;function KindEntry(s){if(!isKind(s.part,e))throw new Error(`renderer for ${e} received a ${s.part.kind} part`);return(0,_react.createElement)(t,{part:s.part,message:s.message,turn:s.turn,pickAttachments:s.pickAttachments})}return s.set(e,KindEntry),kindWrappers.set(t,s),KindEntry}const defaults=_index.defaultRenderers;function entryFor(e,t){return forKind(e,t??defaults[e])}function resolveRenderers(e){return{Text:entryFor("Text",e?.Text),Sources:entryFor("Sources",e?.Sources),QuickReplies:entryFor("QuickReplies",e?.QuickReplies),InputRequest:entryFor("InputRequest",e?.InputRequest),Action:entryFor("Action",e?.Action),Notice:entryFor("Notice",e?.Notice),Table:entryFor("Table",e?.Table),Chart:entryFor("Chart",e?.Chart),Figures:entryFor("Figures",e?.Figures),RecordCard:entryFor("RecordCard",e?.RecordCard),Image:entryFor("Image",e?.Image),File:entryFor("File",e?.File),Ticket:entryFor("Ticket",e?.Ticket),Handoff:entryFor("Handoff",e?.Handoff),VoiceClip:entryFor("VoiceClip",e?.VoiceClip)}}const renderPart=(e,t,s,i,a,r)=>{const n=e[t.kind];return(0,_react.createElement)(n,{key:r,part:t,message:s,turn:i,pickAttachments:a})},sameMessage=(e,t)=>e.signature===t.signature&&e.message.id===t.message.id&&e.message.rating===t.message.rating&&e.message.stored===t.message.stored&&e.groupPosition===t.groupPosition&&e.isLast===t.isLast&&e.handoffSettled===t.handoffSettled&&e.isLastVisitor===t.isLastVisitor&&e.thinking===t.thinking&&e.streaming===t.streaming&&e.pickAttachments===t.pickAttachments&&e.labels===t.labels&&e.all===t.all&&e.layoutParts===t.layoutParts&&e.chat.session===t.chat.session&&e.chat.features===t.chat.features&&e.chat.onNavigate===t.chat.onNavigate&&e.onNavigate===t.onNavigate&&e.onOpenAttachment===t.onOpenAttachment&&e.onOpenTarget===t.onOpenTarget&&e.openTicket===t.openTicket&&e.resolveLink===t.resolveLink&&e.focusComposer===t.focusComposer&&e.byline===t.byline&&e.avatar===t.avatar&&e.replyAvatars===t.replyAvatars&&e.avatarStart===t.avatarStart&&e.expressive===t.expressive&&e.reduced===t.reduced&&e.handoffHosts===t.handoffHosts;function ThreadMessageView({chat:e,message:t,labels:s,all:i,layoutParts:a,groupPosition:r,isLast:n,isLastVisitor:o,pickAttachments:l,onOpenAttachment:c,onOpenTarget:d,onNavigate:u,openTicket:m,handoffHosts:g,resolveLink:p,focusComposer:h,byline:y,avatar:_,replyAvatars:x,avatarStart:f,expressive:v,reduced:j,sourceRows:R,testID:T}){const b=(0,_mobileUi.useTheme)(),k=Object.assign((0,_chatCore.createTurnApi)(e.session,{messageId:t.id,labels:s,openAttachment:c,openTarget:d??_chatShared.defaultOpenTarget,onNavigate:u??e.onNavigate,openTicket:m,handoffHosts:g,openCitation:e=>{return t=String(e),void(0,_chatShared.focusForAccessibility)(R.current.get(t));var t}}),{resolveLink:p,focusComposer:h,registerSourceRow:(e,t)=>{t?R.current.set(e,t):R.current.delete(e)}});let A=0;const nextSlot=()=>(A+=1,A),N=(0,_jsxRuntime.jsx)(_ChatMessageActions.ChatMessageActions,{chat:e,message:t,labels:s,isLast:n,isLastVisitor:o,testID:`${T}-actions`});if(MINE.has(t.author.kind)){const e=t.parts.filter(e=>"File"===e.kind),s=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:b.space.xs},children:[e.map(e=>renderPart(i,e,t,k,l,`${t.id}-file-${nextSlot()}`)),N]});return(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"mine",text:joinedText(t.parts),labels:{you:""},groupPosition:r,footer:s,testID:T})}const w="Agent"===t.author.kind,C=t.author.displayName||s.agent,M=(a?a(t):t.parts).map(e=>Array.isArray(e)?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:b.space.xs},children:e.map(e=>renderPart(i,e,t,k,l,`${t.id}-part-${nextSlot()}`))},`${t.id}-group-${nextSlot()}`):renderPart(i,e,t,k,l,`${t.id}-item-${nextSlot()}`)),S=w&&y?(0,_jsxRuntime.jsx)(_AgentByline.AgentByline,{author:t.author,labels:s,showAvatar:x},`${t.id}-byline`):null,I=S?[S,...M]:M,P=(0,_chatCore.messagePlainText)(t.parts),V=(0,_jsxRuntime.jsx)(_mobileUi.MessageBubble,{side:"theirs",...w?{}:{author:t.author.displayName||(e.profile?.assistant.name??s.assistant)},text:w?`${s.agentSays(C)} ${P}`:P,streaming:t.streaming,groupPosition:r,footer:N,testID:T,children:I});if(!x||!_||"Assistant"!==t.author.kind)return V;const F=t.author.displayName||(e.profile?.assistant.name??s.assistant);return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"flex-end",gap:b.space.xs},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:f?void 0:{opacity:0},children:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:v&&t.streaming&&f,reduced:j,children:(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:F,...f?{source:{uri:_}}:{}})})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,minWidth:0},children:V})]})}const ThreadMessage=(0,_react.memo)(ThreadMessageView,sameMessage),TYPING_ORB_MARK=14,TYPING_ASSISTANT_MARK=8,TypingMark=({size:e})=>{const t=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:e,height:e,borderRadius:t.radius.pill,backgroundColor:t.colors.primary}})},TYPING_DOT=6,TypingDots=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},children:[0,1,2].map(t=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:6,height:6,borderRadius:3,backgroundColor:e.colors["text-muted"]}},t))})},TurnGap=()=>{const e=(0,_mobileUi.useTheme)();return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:e.space.lg}})},followNew=()=>!0;function ChatThread({chat:e,labels:t,renderers:s,layoutParts:i,loader:a="Steps",motion:r="On",avatar:n,replyAvatars:o=!0,expressive:l=!1,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,keyboardAware:_,keyboardOffset:x,empty:f,style:v,testID:j="chat-thread"}){const R=(0,_mobileUi.useTheme)(),T=(0,_mobileUi.useReducedMotion)(),b="Reduced"===r||T,k=(0,_react.useMemo)(()=>resolveRenderers(s),[s]),A=e.messages[0],N=e.greeting??"",w=(0,_react.useMemo)(()=>""!==N&&void 0!==A&&MINE.has(A.author.kind)?{...A,id:"greeting",author:{...A.author,kind:"Assistant",displayName:null,avatarUrl:null},parts:[{kind:"Text",text:N}],stored:!1,streaming:!1,restored:!1,rating:null}:null,[N,A]),C=(0,_react.useMemo)(()=>{const t=e.messages.filter(e=>!(e.streaming&&0===e.parts.length)).reverse();return w?[...t,w]:t},[e.messages,w]),M=e.messages[e.messages.length-1]?.id,S=(0,_react.useRef)(new Map),I=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(null!==I.current)for(const s of e.messages){if(MINE.has(s.author.kind)||s.streaming||s.restored||I.current.has(s.id))continue;if("Agent"===s.author.kind&&!s.stored)continue;I.current.add(s.id);const e=(0,_chatCore.messagePlainText)(s.parts);""!==e&&_reactNative.AccessibilityInfo.announceForAccessibility("Agent"===s.author.kind?`${t.agentSays(s.author.displayName||t.agent)} ${e}`:e)}else I.current=new Set(e.messages.map(e=>e.id))},[e.messages,t]);const P=(0,_react.useMemo)(()=>{for(let t=e.messages.length-1;t>=0;t-=1){const s=e.messages[t];if(s?.stored&&"Visitor"===s.author.kind)return s.id}},[e.messages]),V=(0,_react.useMemo)(()=>{const t=new Set;return e.messages.forEach((s,i)=>{if("Agent"!==s.author.kind)return;const a=e.messages[i-1];"Agent"===a?.author.kind&&(a.author.displayName||"")===(s.author.displayName||"")||t.add(s.id)}),t},[e.messages]),F=(0,_react.useMemo)(()=>{const t=new Set,s=e.messages.filter(e=>!(e.streaming&&0===e.parts.length));return w&&t.add(w.id),s.forEach((e,i)=>{"Assistant"===e.author.kind&&"Assistant"!==s[i-1]?.author.kind&&t.add(e.id)}),t},[e.messages,w]),L=(0,_react.useMemo)(()=>(0,_chatCore.handoffSettledIds)(e.messages),[e.messages]),$=e.turnError,D="daily_limit"===$?.code,E=null!==$&&/feature_off$/.test($.code),O=D&&$?.resetsDateTimeUtc?` ${t.dailyLimitRefresh((0,_chatCore.formatChatDateTime)($.resetsDateTimeUtc))}`:"",U=e.streaming||null===$&&!e.stopped?null:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs},testID:`${j}-error`,children:[null!==$?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityRole:D?void 0:"alert",accessibilityLiveRegion:D?"polite":void 0,children:`${$.message}${O}`}):(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:t.stopped}),!e.features.Retry||D||E?null:(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:t.retry,variant:"link",size:"sm",onPress:()=>{e.retry()},testID:`${j}-retry`})})]}),q=e.thinking&&null!==e.profile?(0,_jsxRuntime.jsx)(_ChatLoader.ChatLoader,{style:a,steps:e.steps,phrases:e.profile.experience.pacing.thinkingPhrases,intervalMs:e.profile.experience.pacing.phraseIntervalMs,announce:t.preparingAnswer(e.profile.assistant.name),motion:r}):null,H=!0===e.pending?.typing?(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(_ReplyRing.ReplyRing,{active:l,reduced:b,children:n?(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"xs",name:e.profile?.assistant.name??t.panelTitle,source:{uri:n}}):(0,_jsxRuntime.jsx)(TypingMark,{size:"Orb"===a?TYPING_ORB_MARK:TYPING_ASSISTANT_MARK})})}):null,K=null!==e.agentTyping&&"WithAgent"===e.conversationState?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.xs,alignSelf:"flex-start"},children:[(0,_jsxRuntime.jsx)(_TypingPill.TypingPill,{motion:r,mark:(0,_jsxRuntime.jsx)(TypingDots,{})}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:t.agentTyping(e.agentTyping.displayName||t.agent)})]}):null,B=H||q||U||K?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:R.space.sm},children:[H,q,K,U]}):void 0,G=(0,_jsxRuntime.jsx)(_mobileUi.MessageList,{messages:C,keyExtractor:e=>e.id,renderMessage:({item:s,groupPosition:a})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"listitem",children:[MINE.has(s.author.kind)?(0,_jsxRuntime.jsx)(_mobileUi.Text,{style:visuallyHidden,children:`${t.you}: `}):null,(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{animate:!s.restored,children:(0,_jsxRuntime.jsx)(ThreadMessage,{chat:e,message:s,signature:(0,_chatShared.messageSignature)(s),labels:t,all:k,layoutParts:i,groupPosition:a,isLast:s.id===M,isLastVisitor:s.id===P,handoffSettled:L.has(s.id),thinking:e.thinking,streaming:e.streaming,pickAttachments:c,onOpenAttachment:d,onOpenTarget:u,onNavigate:m,openTicket:g,handoffHosts:p,resolveLink:h,focusComposer:y,byline:V.has(s.id),avatar:n,replyAvatars:o,avatarStart:F.has(s.id),expressive:l,reduced:b,sourceRows:S,testID:`${j}-${s.id}`})})]}),getAuthorKey:e=>e.author.kind,getDate:e=>e.createdDateTimeUtc,followNew:followNew,typing:B,empty:f,ItemSeparatorComponent:TurnGap,...void 0===_?{}:{keyboardAware:_},...void 0===x?{}:{keyboardOffset:x},accessibilityLabel:t.thread,accessibilityRole:"list",style:v,testID:j});return"web"!==_reactNative.Platform.OS?G:(0,_jsxRuntime.jsx)(_reactNative.View,{role:"log","aria-live":"polite","aria-label":t.thread,style:{flex:1},children:G})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WEB_STRONG=void 0,exports.defaultOpenTarget=defaultOpenTarget,exports.focusForAccessibility=focusForAccessibility,exports.messageSignature=messageSignature,exports.openExternalUrl=openExternalUrl;var _mobileCore=require("@webority/mobile-core"),_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 r of e.parts)"Text"===r.kind&&(t+=r.text.length);return`${e.id}|${e.parts.length}|${t}`}const ABSOLUTE_WEB_URL=/^https?:\/\//i;function openExternalUrl(e){_reactNative.Linking.openURL(e).catch(e=>{throw _mobileCore.Logger.error("[chat] link did not open",e),e})}function defaultOpenTarget(e){ABSOLUTE_WEB_URL.test(e)&&openExternalUrl(e)}const WEB_STRONG=exports.WEB_STRONG="web"===_reactNative.Platform.OS?{role:"strong"}:{};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WEB_STRONG=void 0,exports.defaultOpenTarget=defaultOpenTarget,exports.focusForAccessibility=focusForAccessibility,exports.messageSignature=messageSignature,exports.openExternalUrl=openExternalUrl;var _mobileCore=require("@webority/mobile-core"),_reactNative=require("react-native");function focusForAccessibility(e){if(null==e)return;if("web"===_reactNative.Platform.OS)return void("object"==typeof e&&"focus"in e&&"function"==typeof e.focus&&e.focus());const t=(0,_reactNative.findNodeHandle)(e);null!=t&&_reactNative.AccessibilityInfo.setAccessibilityFocus(t)}function messageSignature(e){let t=0;for(const r of e.parts)"Text"===r.kind&&(t+=r.text.length);return`${e.id}|${e.parts.length}|${t}`}const ABSOLUTE_WEB_URL=/^https?:\/\//i;function openExternalUrl(e){_reactNative.Linking.openURL(e).catch(e=>{throw _mobileCore.Logger.error("[chat] link did not open",e),e})}function defaultOpenTarget(e){ABSOLUTE_WEB_URL.test(e)&&openExternalUrl(e)}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.loadExpoFileSystem=exports.loadExpoAudio=void 0;const isRecord=o=>"object"==typeof o&&null!==o,isExpoAudio=o=>isRecord(o)&&isRecord(o.AudioModule)&&"function"==typeof o.AudioModule.AudioRecorder&&isRecord(o.RecordingPresets)&&isRecord(o.RecordingPresets.HIGH_QUALITY)&&"function"==typeof o.setAudioModeAsync&&"function"==typeof o.createAudioPlayer,isExpoFileSystem=o=>isRecord(o)&&"function"==typeof o.File&&isRecord(o.Paths)&&"cache"in o.Paths,loadExpoAudio=()=>{const o=require("expo-audio");if(!isExpoAudio(o))throw new Error("expo-audio did not load.");return o};exports.loadExpoAudio=loadExpoAudio;const loadExpoFileSystem=()=>{const o=require("expo-file-system");if(!isExpoFileSystem(o))throw new Error("expo-file-system did not load.");return o};exports.loadExpoFileSystem=loadExpoFileSystem;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.iconNameOf=iconNameOf;var _icons=require("@webority/mobile-ui/icons");function iconNameOf(e){return e?_icons.ICON_NAMES.find(i=>i===e)??null:null}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLoader=ChatLoader;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_OrbLoader=require("./OrbLoader.js"),_PhrasesLoader=require("./PhrasesLoader.js"),_SkeletonLoader=require("./SkeletonLoader.js"),_StepsLoader=require("./StepsLoader.js"),_jsxRuntime=require("react/jsx-runtime");const ANNOUNCE_DELAY_MS=500;function ChatLoader({style:e="Steps",steps:t=[],phrases:r,intervalMs:s,motion:o="On",announce:a,testID:i="chat-loader"}){if(!_chatCore.LOADER_STYLES.includes(e))throw new Error(`ChatLoader style must be one of ${_chatCore.LOADER_STYLES.join(", ")}; got "${e}".`);const c=(0,_mobileUi.useReducedMotion)(),n="Reduced"===o||c,[u,d]=(0,_react.useState)({style:e,count:0});(0,_react.useEffect)(()=>{d({style:e,count:0})},[e]),(0,_react.useEffect)(()=>{if(n)return;const t=setInterval(()=>{d(t=>({style:e,count:(t.style===e?t.count:0)+1}))},s);return()=>clearInterval(t)},[e,s,n]);const l=(0,_react.useRef)(a),[_,L]=(0,_react.useState)("");(0,_react.useEffect)(()=>{const e=setTimeout(()=>L(l.current),ANNOUNCE_DELAY_MS);return()=>clearTimeout(e)},[]);const h=n||u.style!==e?0:u.count,S=(0,_chatCore.loaderView)(e,t,r,h);return(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"status",accessibilityLabel:S.label,accessibilityLiveRegion:"polite",testID:i,children:[loaderBody(e,S,n),(0,_jsxRuntime.jsx)(_mobileUi.Text,{accessibilityLiveRegion:"polite",style:styles.announce,children:_})]})}const loaderBody=(e,t,r)=>{switch(e){case"Steps":return(0,_jsxRuntime.jsx)(_StepsLoader.StepsLoader,{view:t,reduced:r});case"Phrases":return(0,_jsxRuntime.jsx)(_PhrasesLoader.PhrasesLoader,{view:t,reduced:r});case"Orb":return(0,_jsxRuntime.jsx)(_OrbLoader.OrbLoader,{view:t,reduced:r});case"Skeleton":return(0,_jsxRuntime.jsx)(_SkeletonLoader.SkeletonLoader,{view:t,reduced:r})}},styles=_reactNative.StyleSheet.create({announce:{position:"absolute",width:1,height:1,opacity:0,overflow:"hidden"}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChatLoader=ChatLoader;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_OrbLoader=require("./OrbLoader.js"),_PhrasesLoader=require("./PhrasesLoader.js"),_SkeletonLoader=require("./SkeletonLoader.js"),_StepsLoader=require("./StepsLoader.js"),_jsxRuntime=require("react/jsx-runtime");const ANNOUNCE_DELAY_MS=500;function ChatLoader({style:e="Steps",steps:t=[],phrases:r,intervalMs:s,motion:a="On",announce:o,testID:i="chat-loader"}){const c=(0,_mobileUi.useReducedMotion)(),n="Reduced"===a||c,[u,d]=(0,_react.useState)({style:e,count:0});(0,_react.useEffect)(()=>{d({style:e,count:0})},[e]),(0,_react.useEffect)(()=>{if(n)return;const t=setInterval(()=>{d(t=>({style:e,count:(t.style===e?t.count:0)+1}))},s);return()=>clearInterval(t)},[e,s,n]);const l=(0,_react.useRef)(o),[_,L]=(0,_react.useState)("");(0,_react.useEffect)(()=>{const e=setTimeout(()=>L(l.current),ANNOUNCE_DELAY_MS);return()=>clearTimeout(e)},[]);const h=n||u.style!==e?0:u.count,j=(0,_chatCore.loaderView)(e,t,r,h);return(0,_jsxRuntime.jsxs)(_reactNative.View,{role:"status",accessibilityLabel:j.label,accessibilityLiveRegion:"polite",testID:i,children:[loaderBody(e,j,n),(0,_jsxRuntime.jsx)(_mobileUi.Text,{accessibilityLiveRegion:"polite",style:styles.announce,children:_})]})}const loaderBody=(e,t,r)=>{switch(e){case"Steps":return(0,_jsxRuntime.jsx)(_StepsLoader.StepsLoader,{view:t,reduced:r});case"Phrases":return(0,_jsxRuntime.jsx)(_PhrasesLoader.PhrasesLoader,{view:t,reduced:r});case"Orb":return(0,_jsxRuntime.jsx)(_OrbLoader.OrbLoader,{view:t,reduced:r});case"Skeleton":return(0,_jsxRuntime.jsx)(_SkeletonLoader.SkeletonLoader,{view:t,reduced:r})}},styles=_reactNative.StyleSheet.create({announce:{position:"absolute",width:1,height:1,opacity:0,overflow:"hidden"}});
@@ -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"),_chatShared=require("../chatShared.js"),_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:()=>(0,_chatShared.openExternalUrl)(e.href),children:i},e.key):(0,_jsxRuntime.jsx)(_reactNative.Text,{children:i},e.key)}if("image"===e.type)return null;const i="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return(0,_jsxRuntime.jsx)(_reactNative.Text,{style:i,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${(0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat((0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),{labels:n,features: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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ActionPart=ActionPart;var _chatCore=require("@webority/chat-core"),_markdownCore=require("@webority/markdown-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const LEAD_CAPTURE="ChatLeadCapture",SAFE_LINK=/^https?:\/\//i,inlineNodes=(e,t)=>e.map(e=>{if("text"===e.type||"code"===e.type||"citation"===e.type)return e.text;if("link"===e.type){const i=inlineNodes(e.children,t);return SAFE_LINK.test(e.href)?(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"link",style:{color:t.colors.link,textDecorationLine:"underline"},onPress:()=>(0,_chatShared.openExternalUrl)(e.href),children:i},e.key):(0,_jsxRuntime.jsx)(_reactNative.Text,{children:i},e.key)}if("image"===e.type)return null;const i="strong"===e.type?{fontWeight:t.weight.bold}:"em"===e.type?{fontStyle:"italic"}:{textDecorationLine:"line-through"};return(0,_jsxRuntime.jsx)(_reactNative.Text,{style:i,children:inlineNodes(e.children,t)},e.key)}),splitLine=e=>{const t=e.indexOf(": ");return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}},statusLine=(e,t)=>{switch(e.state){case"Confirmed":return t.actionConfirmed;case"Done":return e.decidedDateTimeUtc?`${t.actionDone} ${(0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)}`:t.actionDone;case"Rejected":return t.actionRejected;case"Expired":return t.actionExpired;case"Failed":return t.actionFailed;case"Repeat":return e.decidedDateTimeUtc?t.actionRepeat((0,_chatCore.formatChatDate)(e.decidedDateTimeUtc)):t.actionDone;case"Pending":return""}};function ActionBody({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),{labels:n,features:a}=t,[r,o]=(0,_react.useState)(null),[l,s]=(0,_react.useState)(""),[c,d]=(0,_react.useState)(!1),run=async(e,t)=>{o(e),s("");try{await t()}catch(t){_mobileCore.Logger.error(`[chat] action ${e} failed`,t),s(t instanceof _chatCore.ChatApiError&&""!==t.message?t.message:n.actionFailed),o(null)}},u=(e.editFields??[]).map(e=>({label:e.label,value:e.id})),m=a.LeadRecap&&e.actionKind===LEAD_CAPTURE,x=m&&u.length>0,_=m&&e.confirmLabel||n.actionConfirm,h=m&&e.rejectLabel||n.actionDismiss,j=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:[""!==l?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:l}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:"confirm"===r?n.actionWorking:_,loading:"confirm"===r,disabled:j,onPress:()=>{run("confirm",()=>t.confirmAction(e.actionId))}}),(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:h,variant:"ghost",disabled:j,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:j||"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({part:e,turn:t}){return(0,_jsxRuntime.jsx)(ActionBody,{part:e,turn:t},e.actionId)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChartPart=ChartPart;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const TONES=["primary","info","success","warning","danger","neutral"],toneAt=e=>TONES[e%TONES.length]??"primary",MAX_SERIES=8,withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]),writeValue=(e,t)=>{const i=0!==e&&Math.abs(e)<.001?(0,_FigureText.runsToText)((0,_chatCore.formatFigure)(e)):(0,_mobileCore.formatNumber)(e,{maximumFractionDigits:2});return t?`${i} ${t}`:i};function ChartPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),[r,a]=(0,_react.useState)(!1),l="Donut"===e.chartType?e.series.slice(0,1):e.series.slice(0,MAX_SERIES);if(l.every(e=>0===e.points.length))return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.chartEmpty})]});const{unit:s}=e,o=e.title?(0,_chatCore.toFigureText)(e.title):t.labels.chart,n=l.length>1;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLabel:o,style:{gap:i.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0}):null,(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:r?t.labels.chartShowChart:t.labels.chartShowTable,variant:"link",size:"sm",onPress:()=>a(e=>!e)}),withPositions(l).map(({key:a,item:l})=>{const c=toneAt(a),u=(0,_chatCore.toFigureText)(l.name)||o,m=l.points;if(0===m.length)return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_chatCore.toFigureText)(l.name)}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.chartEmpty})]},a);const x=m.map(e=>e.value),_=x.reduce((e,t)=>Math.min(e,t)),h=x.reduce((e,t)=>Math.max(e,t)),b=m[0],j=m[m.length-1];let p;if(r)p=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"summary",style:{gap:i.space.xs},children:withPositions(m).map(({key:e,item:t})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:(0,_chatCore.toFigureText)(t.label)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:writeValue(t.value,s)})]},e))});else if("Bar"===e.chartType)p=(0,_jsxRuntime.jsx)(_mobileUi.BarChart,{data:m.map(e=>({label:(0,_chatCore.toFigureText)(e.label),value:e.value})),height:m.length>4?300:240,label:u,formatValue:e=>writeValue(e,s),formatTick:e=>s?`${(0,_mobileCore.formatCompactNumber)(e)} ${s}`:(0,_mobileCore.formatCompactNumber)(e),tone:c});else if("Line"===e.chartType)p=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Sparkline,{data:x,height:160,fill:!0,tone:c,label:u,formatLabel:e=>writeValue(e,s)}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between"},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:(0,_chatCore.toFigureText)(b.label)}),m.length>1?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:(0,_chatCore.toFigureText)(j.label)}):null]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:`${t.labels.chartLow(writeValue(_,s))} ${t.labels.chartHigh(writeValue(h,s))}`})]});else{const e=x.reduce((e,t)=>e+(Number.isFinite(t)&&t>0?t:0),0);p=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"list",style:{gap:i.space.sm},children:withPositions(m).map(({key:t,item:i})=>{const r=e>0&&Number.isFinite(i.value)&&i.value>0?i.value/e:0;return(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:r,height:8,tone:toneAt(t),label:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:i.label,variant:"bodySmall"}),valueLabel:`${writeValue(i.value,s)} (${(0,_mobileCore.formatPercent)(r,{maximumFractionDigits:0})})`},t)})})}return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_chatCore.toFigureText)(l.name)}):null,p]},a)})]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ChartPart=ChartPart;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const TONES=["primary","info","success","warning","danger","neutral"],toneAt=e=>TONES[e%TONES.length]??"primary",MAX_SERIES=8,withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]),writeValue=(e,t)=>{const i=0!==e&&Math.abs(e)<.001?(0,_FigureText.runsToText)((0,_chatCore.formatFigure)(e)):(0,_mobileCore.formatNumber)(e,{maximumFractionDigits:2});return t?`${i} ${t}`:i};function ChartPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),[r,a]=(0,_react.useState)(!1),l="Donut"===e.chartType?e.series.slice(0,1):e.series.slice(0,MAX_SERIES);if(l.every(e=>0===e.points.length))return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.chartEmpty})]});const{unit:s}=e,o=e.title?(0,_chatCore.toFigureText)(e.title):t.labels.chart,n=l.length>1;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLabel:o,style:{gap:i.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0}):null,(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:r?t.labels.chartShowChart:t.labels.chartShowTable,variant:"link",size:"sm",onPress:()=>a(e=>!e)}),withPositions(l).map(({key:a,item:l})=>{const c=toneAt(a),u=(0,_chatCore.toFigureText)(l.name)||o,m=l.points;if(0===m.length)return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_chatCore.toFigureText)(l.name)}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.chartEmpty})]},a);const x=m.map(e=>e.value),h=x.reduce((e,t)=>Math.min(e,t)),_=x.reduce((e,t)=>Math.max(e,t)),b=m[0];if(void 0===b)throw new Error("A chart with points has no first point.");const j=m[m.length-1];if(void 0===j)throw new Error("A chart with points has no last point.");let p;if(r)p=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"summary",style:{gap:i.space.xs},children:withPositions(m).map(({key:e,item:t})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:(0,_chatCore.toFigureText)(t.label)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:writeValue(t.value,s)})]},e))});else if("Bar"===e.chartType)p=(0,_jsxRuntime.jsx)(_mobileUi.BarChart,{data:m.map(e=>({label:(0,_chatCore.toFigureText)(e.label),value:e.value})),height:m.length>4?300:240,label:u,formatValue:e=>writeValue(e,s),formatTick:e=>s?`${(0,_mobileCore.formatCompactNumber)(e)} ${s}`:(0,_mobileCore.formatCompactNumber)(e),tone:c});else if("Line"===e.chartType)p=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Sparkline,{data:x,height:160,fill:!0,tone:c,label:u,formatLabel:e=>writeValue(e,s)}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between"},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:(0,_chatCore.toFigureText)(b.label)}),m.length>1?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"tertiary",children:(0,_chatCore.toFigureText)(j.label)}):null]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:`${t.labels.chartLow(writeValue(h,s))} ${t.labels.chartHigh(writeValue(_,s))}`})]});else{const e=x.reduce((e,t)=>e+(Number.isFinite(t)&&t>0?t:0),0);p=(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"list",style:{gap:i.space.sm},children:withPositions(m).map(({key:t,item:i})=>{const r=e>0&&Number.isFinite(i.value)&&i.value>0?i.value/e:0;return(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:r,height:8,tone:toneAt(t),label:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:i.label,variant:"bodySmall"}),valueLabel:`${writeValue(i.value,s)} (${(0,_mobileCore.formatPercent)(r,{maximumFractionDigits:0})})`},t)})})}return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:(0,_chatCore.toFigureText)(l.name)}):null,p]},a)})]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FigureRuns=FigureRuns,exports.FigureText=FigureText,exports.runsToText=runsToText;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const sizeStepOf=e=>"caption"===e?"xs":"bodySmall"===e||"label"===e?"sm":"title"===e?"lg":"base",inkFor=(e,t)=>"secondary"===t?e.colors["text-muted"]:"tertiary"===t?e.colors["text-subtle"]:"success"===t||"warning"===t||"danger"===t||"info"===t?e.colors[`${t}-text`]:e.colors["text-body"];function runsToText(e){return e.map(e=>e.text).join("")}const withOffsets=e=>e.reduce((e,t)=>{const r=e[e.length-1],i=r?r.offset+r.run.text.length:0;return e.push({offset:i,run:t}),e},[]);function runNode(e,t,r){if("text"===e.kind)return e.text;const i="sub"===e.kind?Math.round(.4*t):-Math.round(.45*t),n=Math.round(.75*t);return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{transform:[{translateY:i}]},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{fontSize:n,lineHeight:n,includeFontPadding:!1,color:r},children:e.text})})}function FigureRuns({runs:e,variant:t="bodySmall",color:r,strong:i=!1,numberOfLines:n,accessibilityLabel:s,testID:o,heading:u}){const a=(0,_mobileUi.useTheme)(),c=a.text[sizeStepOf(t)].size,l=inkFor(a,r);return(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:t,color:r,weight:i?"semibold":void 0,numberOfLines:n,testID:o,accessibilityRole:u?"header":void 0,accessibilityLabel:s??runsToText(e),children:withOffsets(e).map(({offset:e,run:t})=>(0,_jsxRuntime.jsx)(_react.Fragment,{children:runNode(t,c,l)},e))})}function FigureText({text:e,variant:t="bodySmall",enabled:r=!0,...i}){const n=(0,_react.useMemo)(()=>r?(0,_chatCore.toFigureRuns)(e):[{kind:"text",text:e}],[e,r]);return(0,_jsxRuntime.jsx)(FigureRuns,{runs:n,variant:t,...i})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FigureRuns=FigureRuns,exports.FigureText=FigureText,exports.runsToText=runsToText;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");const sizeStepOf=e=>"caption"===e?"xs":"bodySmall"===e||"label"===e?"sm":"title"===e?"lg":"base",inkFor=(e,t)=>"secondary"===t?e.colors["text-muted"]:"tertiary"===t?e.colors["text-subtle"]:"success"===t||"warning"===t||"danger"===t||"info"===t?e.colors[`${t}-text`]:e.colors["text-body"];function runsToText(e){return e.map(e=>e.text).join("")}const withOffsets=e=>e.reduce((e,t)=>{const r=e[e.length-1],i=r?r.offset+r.run.text.length:0;return e.push({offset:i,run:t}),e},[]);function runNode(e,t,r){if("text"===e.kind)return e.text;const i="sub"===e.kind?Math.round(.4*t):-Math.round(.45*t),n=Math.round(.75*t);return(0,_jsxRuntime.jsx)(_reactNative.View,{style:{transform:[{translateY:i}]},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:{fontSize:n,lineHeight:n,includeFontPadding:!1,color:r},children:e.text})})}function FigureRuns({runs:e,variant:t="bodySmall",color:r,strong:i=!1,numberOfLines:n,accessibilityLabel:s,testID:o,heading:u}){const a=(0,_mobileUi.useTheme)(),c=a.text[sizeStepOf(t)].size,l=inkFor(a,r);return(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:t,...void 0===r?{}:{color:r},...i?{weight:"semibold"}:{},...void 0===n?{}:{numberOfLines:n},...void 0===o?{}:{testID:o},...u?{accessibilityRole:"header"}:{},accessibilityLabel:s??runsToText(e),children:withOffsets(e).map(({offset:e,run:t})=>(0,_jsxRuntime.jsx)(_react.Fragment,{children:runNode(t,c,l)},e))})}function FigureText({text:e,variant:t="bodySmall",enabled:r=!0,...i}){const n=(0,_react.useMemo)(()=>r?(0,_chatCore.toFigureRuns)(e):[{kind:"text",text:e}],[e,r]);return(0,_jsxRuntime.jsx)(FigureRuns,{runs:n,variant:t,...i})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FilePart=FilePart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_NoticePart=require("./NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");function FilePart(e){const{part:t,message:i,turn:r}=e;if("File"!==t.kind){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:r})}const{openAttachment:s}=r;return(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:`${t.fileName} (${(0,_chatCore.formatFileSize)(t.length)})`,leftIcon:"document-text",variant:"soft",size:"sm",accessibilityLabel:r.labels.fileOpen(t.fileName),onPress:s?()=>s(t):void 0})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FilePart=FilePart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_jsxRuntime=require("react/jsx-runtime");function FilePart({part:e,turn:t}){const{openAttachment:i}=t;return(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:`${e.fileName} (${(0,_chatCore.formatFileSize)(e.length)})`,leftIcon:"document-text",variant:"soft",size:"sm",accessibilityLabel:t.labels.fileOpen(e.fileName),...i?{onPress:()=>i(e)}:{}})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HandoffPart=HandoffPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function HandoffPart({part:e,turn:i}){const t=(0,_mobileUi.useTheme)(),{labels:s}=i;if(!0===i.handoffSettled&&("Requested"===e.state||"Waiting"===e.state))return null;const a=i.isLast&&("Requested"===e.state||"Waiting"===e.state||"Joined"===e.state),n=e.agent?.displayName||s.handoffAgentFallback,r=e.agent?.avatarUrl;let o;switch(e.state){case"Requested":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Spinner,{size:"sm"}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffRequested})]});break;case"Waiting":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Spinner,{size:"sm"}),"number"==typeof e.queuePosition?null:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:s.handoffWaiting})]}),"number"==typeof e.queuePosition?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffQueued(e.queuePosition)}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffQueuedText})]});break;case"Joined":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"sm",name:n,source:r?{uri:r}:void 0}),(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{position:"absolute",right:0,bottom:0,width:8,height:8,borderRadius:t.radius.pill,backgroundColor:t.colors["success-text"]}})]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:s.handoffJoined(n)})]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffJoinedText(n)})]});break;case"Left":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffLeft(n)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffLeftText})]});break;case"Ended":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffEnded}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffEndedText})]})}return void 0===o?null:(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLiveRegion:a?"polite":void 0,children:o})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HandoffPart=HandoffPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function HandoffPart({part:e,turn:i}){const t=(0,_mobileUi.useTheme)(),{labels:s}=i;if(!0===i.handoffSettled&&("Requested"===e.state||"Waiting"===e.state))return null;const a=i.isLast&&("Requested"===e.state||"Waiting"===e.state||"Joined"===e.state),n=e.agent?.displayName||s.handoffAgentFallback,r=e.agent?.avatarUrl;let o;switch(e.state){case"Requested":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Spinner,{size:"sm"}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffRequested})]});break;case"Waiting":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Spinner,{size:"sm"}),"number"==typeof e.queuePosition?null:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:s.handoffWaiting})]}),"number"==typeof e.queuePosition?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffQueued(e.queuePosition)}):null,(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffQueuedText})]});break;case"Joined":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",gap:t.space.sm},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{position:"relative"},children:[(0,_jsxRuntime.jsx)(_mobileUi.Avatar,{size:"sm",name:n,...r?{source:{uri:r}}:{}}),(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{position:"absolute",right:0,bottom:0,width:8,height:8,borderRadius:t.radius.pill,backgroundColor:t.colors["success-text"]}})]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:s.handoffJoined(n)})]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffJoinedText(n)})]});break;case"Left":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffLeft(n)}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffLeftText})]});break;case"Ended":o=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:s.handoffEnded}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.handoffEndedText})]})}return void 0===o?null:(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLiveRegion:a?"polite":void 0,children:o})}
@@ -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(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
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_jsxRuntime=require("react/jsx-runtime");const fileNameOf=(e,t)=>{const i="object"==typeof e&&null!==e&&"name"in e?e.name:void 0;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),isStringList=e=>Array.isArray(e)&&e.every(e=>"string"==typeof e),selectedIds=e=>{if(""===e)return[];const t=JSON.parse(e);if(!isStringList(t))throw new Error("Selected ids are not a list of strings.");return t},KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` (${t.inputOptional})`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:s,features:n}=t,[a,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[b,_]=(0,_react.useState)({}),[f,h]=(0,_react.useState)({}),j=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=j.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,U=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(s.errorGeneric),m(!1)}},w=n.LeadShortcuts,T=e.fields[0];if(w&&1===e.fields.length&&void 0===T)throw new Error("A one-field form has no field.");const q=w&&1===e.fields.length&&void 0!==T&&!T.required,C=w&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",...e.title?{accessibilityLabel:e.title}:{},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(n=>{const l=a[n.key]??"",c=o[n.key];if("File"===n.type){const e=y[n.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${n.label}${optionalSuffix(n,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=n.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,{..."number"==typeof e.progress?{progress:e.progress}:{},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 n=r[0];if(!n)return;R.current+=1;const a=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(n,e.label),status:"Uploading",progress:null,token:a}});try{const i=await t.uploadInputFile(n,t=>{isLiveUpload(e.key,a)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,a)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,a)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(n)}})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},n.key)}if("MultiChoice"===n.type){const e=(n.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:`${n.label}${optionalSuffix(n,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[n.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(n.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:n.label,...void 0===c?{}:{error:c},disabled:p})})]},n.key)}if("Choice"===n.type||"TimeSlot"===n.type){const e="TimeSlot"===n.type?(n.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(n.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:`${n.label}${optionalSuffix(n,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[n.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,...""===l?{}:{value:l},onChange:e=>setValue(n.key,String(e)),accessibilityLabel:n.label,...void 0===c?{}:{error:c},disabled:p})})]},n.key)}if("Consent"===n.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(n.key,e?"true":"false"),label:n.consentText??n.label,...void 0===c?{}:{error:c},disabled:p},n.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{j.current[n.key]=e},label:n.label,..."string"==typeof n.placeholder?{placeholder:n.placeholder}:{},value:l,onChangeText:e=>setValue(n.key,e),..."number"==typeof n.maxLength?{maxLength:n.maxLength}:{},required:n.required,...void 0===c?{}:{error:c},...n.required?{}:{help:s.inputOptional},labelMode:"top",disabled:p,type:n.secret?"password":"LongText"===n.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[n.type]??"default",..."Email"===n.type?{autoCapitalize:"none"}:{},...void 0===AUTO_COMPLETE[n.type]?{}:{autoComplete:AUTO_COMPLETE[n.type]}},n.key);if(!("Otp"===n.verify&&("Email"===n.type||"Phone"===n.type)))return u;const m=f[n.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:(a[i.key]??"").trim()}),h(e=>({...e,[i.key]:"sent"}))}catch{h(e=>({...e,[i.key]:"failed"}))}})(n)},testID:`otp-send-${n.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:s.inputEnterCode,value:b[n.key]??"",onChangeText:e=>_(t=>({...t,[n.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]})]},n.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||U,onPress:()=>{(async()=>{if(U)return;const i={},r={};for(const t of e.fields){const e=a[t.key]??"";if("Consent"===t.type){const n="true"===e;t.required&&!n&&(i[t.key]=s.inputConsentRequired),r[t.key]=n?"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 n=selectedIds(e);t.required&&0===n.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(n)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const n=t.secret?e:e.trim();t.required&&""===n&&(i[t.key]=s.inputRequired),r[t.key]=n}}const n={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(b[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),n[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(n).length>0?n:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}m(!1)})()}}),U?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,q?(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({part:e,turn:t,pickAttachments:i}){return"Answered"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:e.answeredSummary||t.labels.inputAnswered}):"Skipped"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputSkipped}):"Expired"===e.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:e,turn:t,pickAttachments:i},e.requestId)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NoticePart=NoticePart;var _mobileUi=require("@webority/mobile-ui"),_jsxRuntime=require("react/jsx-runtime");function NoticePart({part:e}){const t="AssistantUnavailable"===e.code?"danger":"ActionLimitReached"===e.code||"ConversationTooLong"===e.code?"warning":"info";return(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:e.text,tone:t,accessibilityRole:"alert"})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NoticePart=NoticePart;var _mobileUi=require("@webority/mobile-ui"),_jsxRuntime=require("react/jsx-runtime");function NoticePart({part:e,turn:t}){const i="AssistantUnavailable"===e.code?"danger":"ActionLimitReached"===e.code||"ConversationTooLong"===e.code?"warning":"info",r="NeedsNewerApp"===e.code?t.labels.needsNewerApp:e.text;return(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:r,tone:i,accessibilityRole:"alert"})}
@@ -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,{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
+ "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"),_iconName=require("../iconName.js"),_chipLook=require("./chipLook.js"),_jsxRuntime=require("react/jsx-runtime");const QUIET_LOOK={variant:"outline"};function QuickRepliesPart({part:e,turn:i}){const n=(0,_mobileUi.useTheme)();if(!i.features.SuggestedReplies||!i.isLast||i.busy||0===e.replies.length)return null;const t=i.openTarget,a=i.onNavigate,r=void 0!==t&&t!==_chatShared.defaultOpenTarget,o="Composer"===e.placement,s=e.replies.filter(e=>"Send"===e.action||"Open"===e.action&&e.target&&t||"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,n)=>{const t=(0,_iconName.iconNameOf)(e.icon);return(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:n.variant,...void 0===n.tone?{}:{tone:n.tone},...t?{leftIcon:t}:{},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:n.space.xs,...o?{paddingHorizontal:n.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:n.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,n)=>{const o=n+u,s=l?QUIET_LOOK:(0,_chipLook.chipLook)(e.variant),c=(0,_iconName.iconNameOf)(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&&t)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:o,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:s.variant,...void 0===s.tone?{}:{tone:s.tone},...void 0===c?{}:{leftIcon:c},onPress:()=>t(d)})},e.id);if("Navigate"===e.action){const n=(e=>{if(!e)return null;if((0,_chatCore.isHandoffTarget)(e,i.handoffHosts))return e;const n=i.resolveLink?.(e);return"string"==typeof n&&""!==n?n:null})(d),l=null===n?void 0:(e=>e.startsWith("/")?t&&r?()=>t(e):a?()=>a(e):void 0:t?()=>t(e):void 0)(n);return null===n||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,...i.handoffPause||void 0===s.tone?{}:{tone:s.tone},...void 0===c?{}:{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.SourcesPart=SourcesPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_ChatEntrance=require("../ChatEntrance.js"),_jsxRuntime=require("react/jsx-runtime");const HTTP_LINK=/^https?:\/\//i;function SourcesPart({part:e,turn:r}){const t=(0,_mobileUi.useTheme)();if(!r.features.Sources||0===e.sources.length)return null;const i=r.openTarget;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:r.labels.sources}),(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"list",accessibilityLabel:r.labels.sources,style:{flexDirection:"row",flexWrap:"wrap",gap:t.space.xs},children:e.sources.map((e,t)=>{const s=e.url,a=null!==s&&HTTP_LINK.test(s)&&void 0!==i?()=>i(s):void 0;return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:t,animate:!1,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t=>r.registerSourceRow?.(String(e.marker),t),children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:`${e.marker} ${e.title}`,variant:"outline",size:"sm",accessibilityLabel:a?r.labels.openSource(e.title):void 0,onPress:a})})},e.marker)})})]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SourcesPart=SourcesPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_ChatEntrance=require("../ChatEntrance.js"),_jsxRuntime=require("react/jsx-runtime");const HTTP_LINK=/^https?:\/\//i;function SourcesPart({part:e,turn:r}){const t=(0,_mobileUi.useTheme)();if(!r.features.Sources||0===e.sources.length)return null;const i=r.openTarget;return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:r.labels.sources}),(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"list",accessibilityLabel:r.labels.sources,style:{flexDirection:"row",flexWrap:"wrap",gap:t.space.xs},children:e.sources.map((e,t)=>{const s=e.url,a=null!==s&&HTTP_LINK.test(s)&&void 0!==i?()=>i(s):void 0;return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:t,animate:!1,children:(0,_jsxRuntime.jsx)(_reactNative.View,{ref:t=>r.registerSourceRow?.(String(e.marker),t),children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:`${e.marker} ${e.title}`,variant:"outline",size:"sm",...void 0===a?{}:{accessibilityLabel:r.labels.openSource(e.title),onPress:a}})})},e.marker)})})]})}
@@ -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"),_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
+ "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+$/;function TextPart({part:e,message:t,turn:r}){const i="Visitor"===t.author.kind||"Customer"===t.author.kind;return(0,_jsxRuntime.jsx)(_reactNative.View,{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),...r.features.FigureText?{figureText:_chatCore.toFigureRuns}:{},...r.openCitation?{onOpenCitation:e=>r.openCitation?.(Number(e))}:{},children:e.text})})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VoiceClipPart=VoiceClipPart;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_expoAudio=require("../speech/expoAudio.js"),_phoneSpeech=require("../speech/phoneSpeech.js"),_speechText=require("../speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const expoFileSystem=()=>{try{return require("expo-file-system")}catch{throw new _phoneSpeech.PhoneSpeechError("Unavailable","Unavailable","Voice files are not available in this app.")}};function VoiceClipPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),r=(0,_react.useMemo)(()=>buildStyles(i),[i]),a=t.labels,[c,l]=(0,_react.useState)(!1),[n,s]=(0,_react.useState)(!1),[o,u]=(0,_react.useState)(!1),[p,h]=(0,_react.useState)(0),[m,_]=(0,_react.useState)(!1),x=(0,_react.useRef)(null),d=(0,_react.useRef)(null),b=(0,_react.useRef)(!0);(0,_react.useEffect)(()=>(b.current=!0,()=>{b.current=!1,x.current?.stop(),x.current=null,null!==d.current&&(0,_phoneSpeech.discardFile)(d.current)}),[]);const startPlayback=e=>{const t=(0,_expoAudio.playFile)(e,e=>{b.current&&(h(e.positionMs),u(e.playing))});x.current=t;const release=()=>!(!b.current||x.current!==t)&&(x.current=null,u(!1),!0);t.finished.then(()=>{release()&&h(0)},e=>{release()&&(s(!0),_mobileCore.Logger.error("[chat] voice clip playback failed",e))})},v=t.features.VoiceClips,y=null!==e.transcript&&""!==e.transcript?e.transcript:null,j=e.durationMs>0?Math.min(1,Math.max(0,p/e.durationMs)):0,w=(0,_react.useMemo)(()=>(0,_chatCore.voiceClipBars)(e.attachmentId,40).map((e,t)=>({id:`bar-${t}`,position:t,level:e})),[e.attachmentId]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"summary",accessibilityLabel:a.voiceClip,testID:"chat-voice-clip",style:r.root,children:[v?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:r.row,children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:o?"pause":"play",accessibilityLabel:o?a.voiceClipPause:a.voiceClipPlay,variant:"ghost",tone:"neutral",size:"sm",loading:c,disabled:c,onPress:()=>{const i=x.current;null===i?null===d.current?c||(async()=>{l(!0),s(!1);try{const i=new Uint8Array(await t.readAttachment(e.attachmentId)),{File:r,Paths:a}=expoFileSystem(),c=new r(a.cache,`wchat-clip-${e.attachmentId}${(0,_speechText.audioExtension)(i)}`);if(c.create({overwrite:!0}),c.write(i),!b.current)return void(0,_phoneSpeech.discardFile)(c.uri);d.current=c.uri,startPlayback(c.uri)}catch(e){if(!b.current)return;s(!0),_mobileCore.Logger.error("[chat] voice clip failed to load",e)}finally{b.current&&l(!1)}})():startPlayback(d.current):o?i.pause():i.resume()},testID:"chat-voice-clip-play"}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:r.wave,children:w.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{testID:"chat-voice-clip-bar",style:[r.bar,{height:Math.max(4,Math.round(28*e.level)),backgroundColor:e.position<Math.floor(40*j)?i.colors.primary:i.colors["text-subtle"]}]},e.id))}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.voiceClipTime((0,_speechText.formatClipTime)(p),(0,_speechText.formatClipTime)(e.durationMs))})]}):null,v&&null!==y?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:m?a.voiceClipHideTranscript:a.voiceClipShowTranscript,variant:"link",size:"sm",accessibilityState:{expanded:m},onPress:()=>_(e=>!e),testID:"chat-voice-clip-transcript-toggle"}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:y}):null]}):null,v||null===y?null:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:y}),n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:a.voiceClipFailed}):null]})}const buildStyles=e=>_reactNative.StyleSheet.create({root:{gap:e.space.xs},row:{flexDirection:"row",alignItems:"center",gap:e.space.xs},wave:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},bar:{width:3}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VoiceClipPart=VoiceClipPart;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_expoModules=require("../expoModules.js"),_expoAudio=require("../speech/expoAudio.js"),_phoneSpeech=require("../speech/phoneSpeech.js"),_speechText=require("../speech/speechText.js"),_jsxRuntime=require("react/jsx-runtime");const expoFileSystem=()=>{try{return(0,_expoModules.loadExpoFileSystem)()}catch{throw new _phoneSpeech.PhoneSpeechError("Unavailable","Unavailable","Voice files are not available in this app.")}};function VoiceClipPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),r=(0,_react.useMemo)(()=>buildStyles(i),[i]),a=t.labels,[c,l]=(0,_react.useState)(!1),[o,s]=(0,_react.useState)(!1),[n,u]=(0,_react.useState)(!1),[p,h]=(0,_react.useState)(0),[_,m]=(0,_react.useState)(!1),x=(0,_react.useRef)(null),d=(0,_react.useRef)(null),b=(0,_react.useRef)(!0);(0,_react.useEffect)(()=>(b.current=!0,()=>{b.current=!1,x.current?.stop(),x.current=null,null!==d.current&&(0,_phoneSpeech.discardFile)(d.current)}),[]);const startPlayback=e=>{const t=(0,_expoAudio.playFile)(e,e=>{b.current&&(h(e.positionMs),u(e.playing))});x.current=t;const release=()=>!(!b.current||x.current!==t)&&(x.current=null,u(!1),!0);t.finished.then(()=>{release()&&h(0)},e=>{release()&&(s(!0),_mobileCore.Logger.error("[chat] voice clip playback failed",e))})},v=t.features.VoiceClips,y=null!==e.transcript&&""!==e.transcript?e.transcript:null,j=e.durationMs>0?Math.min(1,Math.max(0,p/e.durationMs)):0,w=(0,_react.useMemo)(()=>(0,_chatCore.voiceClipBars)(e.attachmentId,40).map((e,t)=>({id:`bar-${t}`,position:t,level:e})),[e.attachmentId]);return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"summary",accessibilityLabel:a.voiceClip,testID:"chat-voice-clip",style:r.root,children:[v?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:r.row,children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:n?"pause":"play",accessibilityLabel:n?a.voiceClipPause:a.voiceClipPlay,variant:"ghost",tone:"neutral",size:"sm",loading:c,disabled:c,onPress:()=>{const i=x.current;null===i?null===d.current?c||(async()=>{l(!0),s(!1);try{const i=new Uint8Array(await t.readAttachment(e.attachmentId)),{File:r,Paths:a}=expoFileSystem(),c=new r(a.cache,`wchat-clip-${e.attachmentId}${(0,_speechText.audioExtension)(i)}`);if(c.create({overwrite:!0}),c.write(i),!b.current)return void(0,_phoneSpeech.discardFile)(c.uri);d.current=c.uri,startPlayback(c.uri)}catch(e){if(!b.current)return;s(!0),_mobileCore.Logger.error("[chat] voice clip failed to load",e)}finally{b.current&&l(!1)}})():startPlayback(d.current):n?i.pause():i.resume()},testID:"chat-voice-clip-play"}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:r.wave,children:w.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{testID:"chat-voice-clip-bar",style:[r.bar,{height:Math.max(4,Math.round(28*e.level)),backgroundColor:e.position<Math.floor(40*j)?i.colors.primary:i.colors["text-subtle"]}]},e.id))}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:a.voiceClipTime((0,_speechText.formatClipTime)(p),(0,_speechText.formatClipTime)(e.durationMs))})]}):null,v&&null!==y?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:_?a.voiceClipHideTranscript:a.voiceClipShowTranscript,variant:"link",size:"sm",accessibilityState:{expanded:_},onPress:()=>m(e=>!e),testID:"chat-voice-clip-transcript-toggle"}),_?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:y}):null]}):null,v||null===y?null:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:y}),o?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:a.voiceClipFailed}):null]})}const buildStyles=e=>_reactNative.StyleSheet.create({root:{gap:e.space.xs},row:{flexDirection:"row",alignItems:"center",gap:e.space.xs},wave:{flexDirection:"row",alignItems:"center",gap:e.space.xxs},bar:{width:3}});
@@ -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"),_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]+$/,SPEECH_RETRY={sideEffectFree:!0};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},SPEECH_RETRY);if(!r.ok)throw new SpeechRequestError(r.status);const o=await r.json();if(!Array.isArray(o.combinedPhrases))throw new _chatCore.ChatSpeechError("Unavailable","Speech is not available.");return o.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},SPEECH_RETRY);if(!s.ok)throw new SpeechRequestError(s.status);return new Uint8Array(await s.arrayBuffer())})}
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]+$/,SPEECH_RETRY={sideEffectFree:!0};class SpeechRequestError extends Error{constructor(e){super(`Speech request failed with status ${e}`),this.name="SpeechRequestError",this.status=e}}exports.SpeechRequestError=SpeechRequestError;const isUnknownArray=e=>Array.isArray(e),readTranscription=e=>{const t="object"==typeof e&&null!==e&&"combinedPhrases"in e?e.combinedPhrases:void 0;if(!isUnknownArray(t))throw new Error("Azure Speech returned no combinedPhrases.");return{combinedPhrases:t.map(e=>({text:"object"==typeof e&&null!==e&&"text"in e&&"string"==typeof e.text?e.text:""}))}},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 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(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:n,signal:e},SPEECH_RETRY);if(!r.ok)throw new SpeechRequestError(r.status);const o=await r.json();return readTranscription(o).combinedPhrases.map(e=>e.text).join(" ").trim()})}async function synthesizeSpeech(e){const{token:t,text:r,language:o,voice:i,signal:s,fetchImpl:n=fetch}=e;return assertRegion(t.region),withTimeout(s,async e=>{const s=await(0,_mobileCore.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:(0,_speechText.buildSsml)((0,_speechText.clampSpeakText)(r),o,i),signal:e},SPEECH_RETRY);if(!s.ok)throw new SpeechRequestError(s.status);return new Uint8Array(await s.arrayBuffer())})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.playFile=playFile,exports.startRecording=startRecording;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core");const expoAudio=()=>require("expo-audio"),expoFileSystem=()=>{try{return require("expo-file-system")}catch{throw new _chatCore.ChatSpeechError("Unavailable","Voice files are not available in this app.")}},RECORDING_OPTIONS={sampleRate:16e3,numberOfChannels:1,bitRate:48e3},setRecordingMode=e=>expoAudio().setAudioModeAsync({allowsRecording:e,playsInSilentMode:!0});async function startRecording(){const e=expoAudio();await setRecordingMode(!0);const t=new e.AudioModule.AudioRecorder({...e.RecordingPresets.HIGH_QUALITY,...RECORDING_OPTIONS});let o=0;try{await t.prepareToRecordAsync(),o=Date.now(),t.record()}catch(e){throw await setRecordingMode(!1),e}return{async stop(){try{await t.stop();const e=t.uri;if(null===e)throw new Error("The recorder finished without a file.");const i=t.getStatus().durationMillis;return{uri:e,durationMs:i>0?i:Date.now()-o}}finally{await setRecordingMode(!1)}},async cancel(){try{t.isRecording&&await t.stop();const e=t.uri;if(null!==e){const{File:t}=expoFileSystem();try{new t(e).delete()}catch(e){_mobileCore.Logger.warn("Removing a cancelled recording failed:",e)}}}finally{await setRecordingMode(!1)}}}}let active=null;function playFile(e,t){active?.stop();let o=null,i=null,r=!1,resolveFinished=()=>{},rejectFinished=()=>{};const a=new Promise((e,t)=>{resolveFinished=e,rejectFinished=t}),release=()=>{i?.remove(),i=null,null!==o&&(o.pause(),o.remove(),o=null),active===n&&(active=null)},n={finished:a,pause:()=>o?.pause(),resume:()=>o?.play(),stop:()=>{r||(r=!0,release(),resolveFinished())}};active=n;const l=expoAudio();return l.setAudioModeAsync({playsInSilentMode:!0,allowsRecording:!1}).then(()=>{if(r)return;const a=l.createAudioPlayer({uri:e});o=a,i=a.addListener("playbackStatusUpdate",e=>{t?.({positionMs:1e3*e.currentTime,durationMs:e.duration>0?1e3*e.duration:null,playing:e.playing}),e.didJustFinish&&(r=!0,release(),resolveFinished())}),a.play()}).catch(e=>{r||(r=!0,release(),rejectFinished(e))}),n}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.playFile=playFile,exports.startRecording=startRecording;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_expoModules=require("../expoModules.js");const expoFileSystem=()=>{try{return(0,_expoModules.loadExpoFileSystem)()}catch(e){throw _mobileCore.Logger.warn("[chat] expo-file-system could not be loaded",e),new _chatCore.ChatSpeechError("Unavailable","Voice files are not available in this app.")}},RECORDING_OPTIONS={sampleRate:16e3,numberOfChannels:1,bitRate:48e3},setRecordingMode=e=>(0,_expoModules.loadExpoAudio)().setAudioModeAsync({allowsRecording:e,playsInSilentMode:!0});async function startRecording(){const e=(0,_expoModules.loadExpoAudio)();await setRecordingMode(!0);const o=new e.AudioModule.AudioRecorder({...e.RecordingPresets.HIGH_QUALITY,...RECORDING_OPTIONS});let t=0;try{await o.prepareToRecordAsync(),t=Date.now(),o.record()}catch(e){throw await setRecordingMode(!1),e}return{async stop(){try{await o.stop();const e=o.uri;if(null===e)throw new Error("The recorder finished without a file.");const i=o.getStatus().durationMillis;return{uri:e,durationMs:i>0?i:Date.now()-t}}finally{await setRecordingMode(!1)}},async cancel(){try{o.isRecording&&await o.stop();const e=o.uri;if(null!==e){const{File:o}=expoFileSystem();try{new o(e).delete()}catch(e){_mobileCore.Logger.warn("Removing a cancelled recording failed:",e)}}}finally{await setRecordingMode(!1)}}}}let active=null;function playFile(e,o){active?.stop();let t=null,i=null,r=!1,resolveFinished=()=>{},rejectFinished=()=>{};const a=new Promise((e,o)=>{resolveFinished=e,rejectFinished=o}),release=()=>{i?.remove(),i=null,null!==t&&(t.pause(),t.remove(),t=null),active===n&&(active=null)},n={finished:a,pause:()=>t?.pause(),resume:()=>t?.play(),stop:()=>{r||(r=!0,release(),resolveFinished())}};active=n;const l=(0,_expoModules.loadExpoAudio)();return l.setAudioModeAsync({playsInSilentMode:!0,allowsRecording:!1}).then(()=>{if(r)return;const a=l.createAudioPlayer({uri:e});t=a,i=a.addListener("playbackStatusUpdate",e=>{o?.({positionMs:1e3*e.currentTime,durationMs:e.duration>0?1e3*e.duration:null,playing:e.playing}),e.didJustFinish&&(r=!0,release(),resolveFinished())}),a.play()}).catch(e=>{r||(r=!0,release(),rejectFinished(e))}),n}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PhoneSpeechError=void 0,exports.createPhoneSpeech=createPhoneSpeech,exports.discardFile=discardFile;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_permissions=require("@webority/mobile-core/permissions"),_azureSpeech=require("./azureSpeech.js"),_expoAudio=require("./expoAudio.js"),_speechText=require("./speechText.js");class PhoneSpeechError extends _chatCore.ChatSpeechError{constructor(e,r,t){super(e,t),this.name="PhoneSpeechError",this.phoneCode=r}}exports.PhoneSpeechError=PhoneSpeechError;const expoFileSystem=()=>{try{return require("expo-file-system")}catch{throw new PhoneSpeechError("Unavailable","Unavailable","Voice files are not available in this app.")}};function discardFile(e){try{const{File:r}=expoFileSystem();new r(e).delete()}catch(e){_mobileCore.Logger.warn("Removing a temporary audio file failed:",e)}}const failed=e=>e instanceof _chatCore.ChatSpeechError?e:(_mobileCore.Logger.error("[chat] speech failed",e),new PhoneSpeechError("Failed","Failed")),waitForDictation=e=>new Promise(r=>{if(e?.aborted)return void r();const done=()=>{clearTimeout(t),e?.removeEventListener("abort",done),r()},t=setTimeout(done,_speechText.MAX_DICTATION_MS);e?.addEventListener("abort",done)});function createPhoneSpeech(e){const r=e.language??_speechText.DEFAULT_SPEECH_LANGUAGE,t=e.voice??_speechText.DEFAULT_SPEECH_VOICE,o=(0,_chatCore.createSpeechTokenSource)(e.getToken);let a=null,i=null,n=Promise.resolve();const token=async()=>{try{return await o.get()}catch(e){throw failed(e)}},dictate=async e=>{a?.abort(),i?.abort();const t=n,o=new AbortController,forward=()=>o.abort();e.signal?.aborted&&o.abort(),e.signal?.addEventListener("abort",forward),i=o;const c=t.then(()=>(async(e,t)=>{const o=await _permissions.Permissions.ensure("microphone").catch(()=>{throw new PhoneSpeechError("Blocked","MicDenied","The microphone permission could not be checked.")});if("blocked"===o)throw new PhoneSpeechError("Blocked","MicBlocked");if("unavailable"===o)throw new PhoneSpeechError("NoMicrophone","MicUnavailable");if("granted"!==o)throw new PhoneSpeechError("Blocked","MicDenied");let a,i;try{a=await(0,_expoAudio.startRecording)()}catch(e){throw failed(e)}e.onStarted?.(),await waitForDictation(t);try{i=await a.stop()}catch(r){throw e.onEnd?.(),failed(r)}if(e.shouldDiscard?.())return discardFile(i.uri),void e.onEnd?.();if(i.durationMs<_speechText.MIN_DICTATION_MS)return discardFile(i.uri),void e.onEnd?.();try{const t=await(0,_azureSpeech.transcribeClip)({token:await token(),uri:i.uri,language:e.language??r});""!==t&&e.onText?.(t,!0),e.onEnd?.()}catch(r){throw e.onEnd?.(),failed(r)}finally{discardFile(i.uri)}})(e,o.signal));n=c.then(()=>{},()=>{});try{await c}finally{e.signal?.removeEventListener("abort",forward),i===o&&(i=null)}};return{dictation:!0,readAloud:!0,streamsText:!1,startDictation:e=>dictate(e),speak:(e,o)=>(async(e,o)=>{a?.abort();const i=new AbortController;a=i;const forward=()=>i.abort();o.signal?.aborted&&i.abort(),o.signal?.addEventListener("abort",forward);const n=i.signal;let c=null,s=null;const onAbort=()=>{s?.stop()};try{const a=(0,_speechText.clampSpeakText)(e);if(""===a)return;const i=await(0,_azureSpeech.synthesizeSpeech)({token:await token(),text:a,language:o.language??r,voice:t,signal:n});if(n.aborted)return;const{File:l,Paths:h}=expoFileSystem();if(c=new l(h.cache,`wchat-read-${Date.now()}.mp3`),c.create({overwrite:!0}),c.write(i),n.aborted)return;s=(0,_expoAudio.playFile)(c.uri),n.addEventListener("abort",onAbort),n.aborted&&s.stop(),await s.finished}catch(e){if(n.aborted)return;throw failed(e)}finally{n.removeEventListener("abort",onAbort),o.signal?.removeEventListener("abort",forward),a===i&&(a=null),null!==c&&discardFile(c.uri)}})(e,o)}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PhoneSpeechError=void 0,exports.createPhoneSpeech=createPhoneSpeech,exports.discardFile=discardFile;var _chatCore=require("@webority/chat-core"),_mobileCore=require("@webority/mobile-core"),_permissions=require("@webority/mobile-core/permissions"),_expoModules=require("../expoModules.js"),_azureSpeech=require("./azureSpeech.js"),_expoAudio=require("./expoAudio.js"),_speechText=require("./speechText.js");class PhoneSpeechError extends _chatCore.ChatSpeechError{constructor(e,r,o){super(e,o),this.name="PhoneSpeechError",this.phoneCode=r}}exports.PhoneSpeechError=PhoneSpeechError;const expoFileSystem=()=>{try{return(0,_expoModules.loadExpoFileSystem)()}catch{throw new PhoneSpeechError("Unavailable","Unavailable","Voice files are not available in this app.")}};function discardFile(e){try{const{File:r}=expoFileSystem();new r(e).delete()}catch(e){_mobileCore.Logger.warn("Removing a temporary audio file failed:",e)}}const failed=e=>e instanceof _chatCore.ChatSpeechError?e:(_mobileCore.Logger.error("[chat] speech failed",e),new PhoneSpeechError("Failed","Failed")),waitForDictation=e=>new Promise(r=>{if(e?.aborted)return void r();const done=()=>{clearTimeout(o),e?.removeEventListener("abort",done),r()},o=setTimeout(done,_speechText.MAX_DICTATION_MS);e?.addEventListener("abort",done)});function createPhoneSpeech(e){const r=e.language??_speechText.DEFAULT_SPEECH_LANGUAGE,o=e.voice??_speechText.DEFAULT_SPEECH_VOICE,t=(0,_chatCore.createSpeechTokenSource)(e.getToken);let a=null,i=null,n=Promise.resolve();const token=async()=>{try{return await t.get()}catch(e){throw failed(e)}},dictate=async e=>{a?.abort(),i?.abort();const o=n,t=new AbortController,forward=()=>t.abort();e.signal?.aborted&&t.abort(),e.signal?.addEventListener("abort",forward),i=t;const c=o.then(()=>(async(e,o)=>{const t=await _permissions.Permissions.ensure("microphone").catch(()=>{throw new PhoneSpeechError("Blocked","MicDenied","The microphone permission could not be checked.")});if("blocked"===t)throw new PhoneSpeechError("Blocked","MicBlocked");if("unavailable"===t)throw new PhoneSpeechError("NoMicrophone","MicUnavailable");if("granted"!==t)throw new PhoneSpeechError("Blocked","MicDenied");let a,i;try{a=await(0,_expoAudio.startRecording)()}catch(e){throw failed(e)}e.onStarted?.(),await waitForDictation(o);try{i=await a.stop()}catch(r){throw e.onEnd?.(),failed(r)}if(e.shouldDiscard?.())return discardFile(i.uri),void e.onEnd?.();if(i.durationMs<_speechText.MIN_DICTATION_MS)return discardFile(i.uri),void e.onEnd?.();try{const o=await(0,_azureSpeech.transcribeClip)({token:await token(),uri:i.uri,language:e.language??r});""!==o&&e.onText?.(o,!0),e.onEnd?.()}catch(r){throw e.onEnd?.(),failed(r)}finally{discardFile(i.uri)}})(e,t.signal));n=c.then(()=>{},()=>{});try{await c}finally{e.signal?.removeEventListener("abort",forward),i===t&&(i=null)}};return{dictation:!0,readAloud:!0,streamsText:!1,startDictation:e=>dictate(e),speak:(e,t)=>(async(e,t)=>{a?.abort();const i=new AbortController;a=i;const forward=()=>i.abort();t.signal?.aborted&&i.abort(),t.signal?.addEventListener("abort",forward);const n=i.signal;let c=null,s=null;const onAbort=()=>{s?.stop()};try{const a=(0,_speechText.clampSpeakText)(e);if(""===a)return;const i=await(0,_azureSpeech.synthesizeSpeech)({token:await token(),text:a,language:t.language??r,voice:o,signal:n});if(n.aborted)return;const{File:l,Paths:h}=expoFileSystem();if(c=new l(h.cache,`wchat-read-${Date.now()}.mp3`),c.create({overwrite:!0}),c.write(i),n.aborted)return;s=(0,_expoAudio.playFile)(c.uri),n.addEventListener("abort",onAbort),n.aborted&&s.stop(),await s.finished}catch(e){if(n.aborted)return;throw failed(e)}finally{n.removeEventListener("abort",onAbort),t.signal?.removeEventListener("abort",forward),a===i&&(a=null),null!==c&&discardFile(c.uri)}})(e,t)}}