@webority/mobile-chat 0.133.0 → 0.135.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 (137) hide show
  1. package/lib/commonjs/AgentByline.js +1 -1
  2. package/lib/commonjs/ChatAppearanceScope.js +1 -0
  3. package/lib/commonjs/ChatComposer.js +1 -1
  4. package/lib/commonjs/ChatConversationActions.js +1 -1
  5. package/lib/commonjs/ChatDictationButton.js +1 -1
  6. package/lib/commonjs/ChatEmbed.js +1 -1
  7. package/lib/commonjs/ChatFooter.js +1 -1
  8. package/lib/commonjs/ChatFrame.js +1 -1
  9. package/lib/commonjs/ChatHistory.js +1 -1
  10. package/lib/commonjs/ChatLauncher.js +1 -0
  11. package/lib/commonjs/ChatLiveBar.js +1 -1
  12. package/lib/commonjs/ChatMessageActions.js +1 -1
  13. package/lib/commonjs/ChatNudge.js +1 -1
  14. package/lib/commonjs/ChatOpenTickets.js +1 -1
  15. package/lib/commonjs/ChatPanel.js +1 -0
  16. package/lib/commonjs/ChatPastChats.js +1 -0
  17. package/lib/commonjs/ChatScreen.js +1 -1
  18. package/lib/commonjs/ChatSheet.js +1 -1
  19. package/lib/commonjs/ChatStarters.js +1 -1
  20. package/lib/commonjs/ChatThread.js +1 -1
  21. package/lib/commonjs/ReadAloudButton.js +1 -1
  22. package/lib/commonjs/chatShared.js +1 -1
  23. package/lib/commonjs/features.map.json +3 -3
  24. package/lib/commonjs/index.js +1 -1
  25. package/lib/commonjs/loaders/ChatLoader.js +1 -1
  26. package/lib/commonjs/renderers/ActionPart.js +1 -1
  27. package/lib/commonjs/renderers/ChartPart.js +1 -1
  28. package/lib/commonjs/renderers/FigureText.js +1 -1
  29. package/lib/commonjs/renderers/FiguresPart.js +1 -1
  30. package/lib/commonjs/renderers/FilePart.js +1 -1
  31. package/lib/commonjs/renderers/HandoffPart.js +1 -1
  32. package/lib/commonjs/renderers/ImagePart.js +1 -1
  33. package/lib/commonjs/renderers/InputRequestPart.js +1 -1
  34. package/lib/commonjs/renderers/NoticePart.js +1 -1
  35. package/lib/commonjs/renderers/QuickRepliesPart.js +1 -1
  36. package/lib/commonjs/renderers/RecordCardPart.js +1 -1
  37. package/lib/commonjs/renderers/SourcesPart.js +1 -1
  38. package/lib/commonjs/renderers/TablePart.js +1 -1
  39. package/lib/commonjs/renderers/TicketPart.js +1 -1
  40. package/lib/commonjs/renderers/VoiceClipPart.js +1 -1
  41. package/lib/commonjs/speech/phoneSpeech.js +1 -1
  42. package/lib/commonjs/speech/speechText.js +1 -1
  43. package/lib/commonjs/useChat.js +1 -1
  44. package/lib/commonjs/useChatHaptics.js +1 -1
  45. package/lib/commonjs/useChatSound.js +1 -0
  46. package/lib/module/AgentByline.js +1 -1
  47. package/lib/module/ChatAppearanceScope.js +1 -0
  48. package/lib/module/ChatComposer.js +1 -1
  49. package/lib/module/ChatConversationActions.js +1 -1
  50. package/lib/module/ChatDictationButton.js +1 -1
  51. package/lib/module/ChatEmbed.js +1 -1
  52. package/lib/module/ChatFooter.js +1 -1
  53. package/lib/module/ChatFrame.js +1 -1
  54. package/lib/module/ChatHistory.js +1 -1
  55. package/lib/module/ChatLauncher.js +1 -0
  56. package/lib/module/ChatLiveBar.js +1 -1
  57. package/lib/module/ChatMessageActions.js +1 -1
  58. package/lib/module/ChatNudge.js +1 -1
  59. package/lib/module/ChatOpenTickets.js +1 -1
  60. package/lib/module/ChatPanel.js +1 -0
  61. package/lib/module/ChatPastChats.js +1 -0
  62. package/lib/module/ChatScreen.js +1 -1
  63. package/lib/module/ChatSheet.js +1 -1
  64. package/lib/module/ChatStarters.js +1 -1
  65. package/lib/module/ChatThread.js +1 -1
  66. package/lib/module/ReadAloudButton.js +1 -1
  67. package/lib/module/chatShared.js +1 -1
  68. package/lib/module/features.map.json +3 -3
  69. package/lib/module/index.js +1 -1
  70. package/lib/module/loaders/ChatLoader.js +1 -1
  71. package/lib/module/renderers/ActionPart.js +1 -1
  72. package/lib/module/renderers/ChartPart.js +1 -1
  73. package/lib/module/renderers/FigureText.js +1 -1
  74. package/lib/module/renderers/FiguresPart.js +1 -1
  75. package/lib/module/renderers/FilePart.js +1 -1
  76. package/lib/module/renderers/HandoffPart.js +1 -1
  77. package/lib/module/renderers/ImagePart.js +1 -1
  78. package/lib/module/renderers/InputRequestPart.js +1 -1
  79. package/lib/module/renderers/NoticePart.js +1 -1
  80. package/lib/module/renderers/QuickRepliesPart.js +1 -1
  81. package/lib/module/renderers/RecordCardPart.js +1 -1
  82. package/lib/module/renderers/SourcesPart.js +1 -1
  83. package/lib/module/renderers/TablePart.js +1 -1
  84. package/lib/module/renderers/TicketPart.js +1 -1
  85. package/lib/module/renderers/VoiceClipPart.js +1 -1
  86. package/lib/module/speech/phoneSpeech.js +1 -1
  87. package/lib/module/speech/speechText.js +1 -1
  88. package/lib/module/useChat.js +1 -1
  89. package/lib/module/useChatHaptics.js +1 -1
  90. package/lib/module/useChatSound.js +1 -0
  91. package/lib/typescript/commonjs/ChatAppearanceScope.d.ts +11 -0
  92. package/lib/typescript/commonjs/ChatComposer.d.ts +5 -2
  93. package/lib/typescript/commonjs/ChatConversationActions.d.ts +1 -1
  94. package/lib/typescript/commonjs/ChatDictationButton.d.ts +3 -1
  95. package/lib/typescript/commonjs/ChatEmbed.d.ts +1 -1
  96. package/lib/typescript/commonjs/ChatFrame.d.ts +15 -4
  97. package/lib/typescript/commonjs/ChatLauncher.d.ts +22 -0
  98. package/lib/typescript/commonjs/ChatPanel.d.ts +39 -0
  99. package/lib/typescript/commonjs/ChatPastChats.d.ts +21 -0
  100. package/lib/typescript/commonjs/ChatScreen.d.ts +1 -1
  101. package/lib/typescript/commonjs/ChatSheet.d.ts +1 -6
  102. package/lib/typescript/commonjs/ChatThread.d.ts +3 -1
  103. package/lib/typescript/commonjs/chatShared.d.ts +2 -0
  104. package/lib/typescript/commonjs/index.d.ts +2 -1
  105. package/lib/typescript/commonjs/renderers/ChartPart.d.ts +1 -1
  106. package/lib/typescript/commonjs/renderers/FigureText.d.ts +4 -2
  107. package/lib/typescript/commonjs/renderers/HandoffPart.d.ts +1 -1
  108. package/lib/typescript/commonjs/renderers/ImagePart.d.ts +2 -1
  109. package/lib/typescript/commonjs/renderers/VoiceClipPart.d.ts +1 -1
  110. package/lib/typescript/commonjs/speech/speechText.d.ts +3 -3
  111. package/lib/typescript/commonjs/types.d.ts +28 -2
  112. package/lib/typescript/commonjs/useChat.d.ts +2 -0
  113. package/lib/typescript/commonjs/useChatSound.d.ts +35 -0
  114. package/lib/typescript/module/ChatAppearanceScope.d.ts +11 -0
  115. package/lib/typescript/module/ChatComposer.d.ts +5 -2
  116. package/lib/typescript/module/ChatConversationActions.d.ts +1 -1
  117. package/lib/typescript/module/ChatDictationButton.d.ts +3 -1
  118. package/lib/typescript/module/ChatEmbed.d.ts +1 -1
  119. package/lib/typescript/module/ChatFrame.d.ts +15 -4
  120. package/lib/typescript/module/ChatLauncher.d.ts +22 -0
  121. package/lib/typescript/module/ChatPanel.d.ts +39 -0
  122. package/lib/typescript/module/ChatPastChats.d.ts +21 -0
  123. package/lib/typescript/module/ChatScreen.d.ts +1 -1
  124. package/lib/typescript/module/ChatSheet.d.ts +1 -6
  125. package/lib/typescript/module/ChatThread.d.ts +3 -1
  126. package/lib/typescript/module/chatShared.d.ts +2 -0
  127. package/lib/typescript/module/index.d.ts +2 -1
  128. package/lib/typescript/module/renderers/ChartPart.d.ts +1 -1
  129. package/lib/typescript/module/renderers/FigureText.d.ts +4 -2
  130. package/lib/typescript/module/renderers/HandoffPart.d.ts +1 -1
  131. package/lib/typescript/module/renderers/ImagePart.d.ts +2 -1
  132. package/lib/typescript/module/renderers/VoiceClipPart.d.ts +1 -1
  133. package/lib/typescript/module/speech/speechText.d.ts +3 -3
  134. package/lib/typescript/module/types.d.ts +28 -2
  135. package/lib/typescript/module/useChat.d.ts +2 -0
  136. package/lib/typescript/module/useChatSound.d.ts +35 -0
  137. package/package.json +10 -9
@@ -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"),_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,t)=>!FIELD_TYPES.has(e.type)||"File"===e.type&&!t,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})`;function OpenRequest({part:e,turn:t,pickAttachments:i}){const a=(0,_mobileUi.useTheme)(),{labels:s,features:l}=t,[n,r]=(0,_react.useState)({}),[o,u]=(0,_react.useState)({}),[c,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[x,y]=(0,_react.useState)({}),setValue=(e,t)=>r(i=>({...i,[e]:t})),patchUpload=(e,t)=>y(i=>{const a=i[e];return a?{...i,[e]:{...a,...t}}:i}),b=Object.values(x).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(s.errorGeneric),m(!1)}},_=l.LeadShortcuts,j=_&&1===e.fields.length&&!e.fields[0].required,h=_&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:a.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:e.title}):null,_&&e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.typeAnswer}):null,e.fields.map(e=>{const l=n[e.key]??"",r=o[e.key];if("File"===e.type){const l=x[e.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:a.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${e.label}${optionalSuffix(e,s)}`}),l?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:a.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:l.fileName,variant:"soft",onRemove:"Uploading"===l.status?void 0:()=>{return t=e.key,y(e=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))),void setValue(t,"");var t},labels:{remove:s.inputRemoveFile}}),"Uploading"===l.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:l.progress??void 0,label:s.attachmentUploading,height:4}):null,"Failed"===l.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",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,onPress:()=>{(async e=>{if(!i)return;let a;try{a=await i()}catch{return void d(s.errorGeneric)}const l=a[0];if(l){y(t=>({...t,[e.key]:{fileName:fileNameOf(l,e.label),status:"Uploading",progress:null}}));try{const i=await t.uploadInputFile(l,t=>patchUpload(e.key,{progress:t}));setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null})}catch{setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null})}}})(e)}})}),r?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:r}):null]},e.key)}if("MultiChoice"===e.type){const t=(e.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:a.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${e.label}${optionalSuffix(e,s)}`}),(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:t,value:selectedIds(l),onChange:i=>setValue(e.key,JSON.stringify(t.filter(e=>i.includes(e.value)).map(e=>e.value))),accessibilityLabel:e.label,error:r,disabled:p})]},e.key)}if("Choice"===e.type||"TimeSlot"===e.type){const t="TimeSlot"===e.type?(e.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(e.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:a.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${e.label}${optionalSuffix(e,s)}`}),(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:t,value:""===l?void 0:l,onChange:t=>setValue(e.key,String(t)),accessibilityLabel:e.label,error:r,disabled:p})]},e.key)}return"Consent"===e.type?(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:t=>setValue(e.key,t?"true":"false"),label:`${e.consentText??e.label}${optionalSuffix(e,s)}`,error:r,disabled:p},e.key):(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:e.label,placeholder:e.placeholder??void 0,value:l,onChangeText:t=>setValue(e.key,t),maxLength:e.maxLength??void 0,required:e.required,error:r,help:e.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:"LongText"===e.type?"textarea":e.secret?"password":"input",keyboardType:KEYBOARD_TYPES[e.type]??"default",autoCapitalize:"Email"===e.type?"none":void 0,autoComplete:AUTO_COMPLETE[e.type]},e.key)}),""!==c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:c}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:a.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||b,onPress:()=>{(async()=>{if(b)return;const i={},a={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const l="true"===e;t.required&&!l&&(i[t.key]=s.inputConsentRequired),a[t.key]=l?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),a[t.key]=e;else if("MultiChoice"===t.type){const l=selectedIds(e);t.required&&0===l.length&&(i[t.key]=s.inputRequired),a[t.key]=JSON.stringify(l)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),a[t.key]=e;else{const l=e.trim();t.required&&""===l&&(i[t.key]=s.inputRequired),a[t.key]=l}}if(u(i),!(Object.keys(i).length>0)){m(!0),d("");try{const i=await t.answerInput(e.requestId,a);if(i.ok)return;u(i.errors),d(i.message??"")}catch{d(s.errorGeneric)}m(!1)}})()}}),j?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,h?(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:a,pickAttachments:s}=e,l=void 0!==s;if("InputRequest"!==t.kind||t.fields.some(e=>isUndrawnField(e,l))){const e={kind:"Notice",code:"NeedsNewerApp",text:a.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:a})}return"Answered"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary??a.labels.inputAnswered}):"Skipped"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:a.labels.inputSkipped}):"Expired"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:a.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:t,turn:a,pickAttachments:s},t.requestId)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InputRequestPart=InputRequestPart;var _mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_chatShared=require("../chatShared.js"),_NoticePart=require("./NoticePart.js"),_jsxRuntime=require("react/jsx-runtime");const FIELD_TYPES=new Set(["Email","Phone","Name","Company","Text","LongText","Choice","MultiChoice","TimeSlot","File","Consent"]),isUndrawnField=e=>!FIELD_TYPES.has(e.type),fileNameOf=(e,t)=>{const i=e.name;return"string"==typeof i&&""!==i?i:t},slotFormat=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"numeric",minute:"2-digit"}),selectedIds=e=>""===e?[]:JSON.parse(e),KEYBOARD_TYPES={Email:"email-address",Phone:"phone-pad"},AUTO_COMPLETE={Email:"email",Phone:"tel",Name:"name",Company:"organization"},optionalSuffix=(e,t)=>e.required?"":` (${t.inputOptional})`,firstErrorKey=(e,t)=>e.find(e=>void 0!==t[e.key])?.key;function OpenRequest({part:e,turn:t,pickAttachments:i}){const r=(0,_mobileUi.useTheme)(),{labels:s,features:a}=t,[n,l]=(0,_react.useState)({}),[o,c]=(0,_react.useState)({}),[u,d]=(0,_react.useState)(""),[p,m]=(0,_react.useState)(!1),[y,x]=(0,_react.useState)({}),[_,b]=(0,_react.useState)({}),[f,j]=(0,_react.useState)({}),h=(0,_react.useRef)({}),v=(0,_react.useRef)({}),k=(0,_react.useRef)(y),R=(0,_react.useRef)(0),g=(0,_react.useRef)(!1),S=(0,_react.useCallback)(e=>{const t=h.current[e];if(t)return void t.focus();const i=v.current[e];i&&(0,_chatShared.focusForAccessibility)(i)},[]);(0,_react.useEffect)(()=>{if(p||!g.current)return;g.current=!1;const t=firstErrorKey(e.fields,o);void 0!==t&&S(t)},[p,o,e.fields,S]);const setValue=(e,t)=>l(i=>({...i,[e]:t})),commitUploads=e=>{k.current=e,x(e)},patchUpload=(e,t)=>{const i=k.current[e];i&&commitUploads({...k.current,[e]:{...i,...t}})},isLiveUpload=(e,t)=>k.current[e]?.token===t,T=Object.values(y).some(e=>"Ready"!==e.status),leave=async e=>{m(!0),d("");try{await e()}catch{d(s.errorGeneric),m(!1)}},U=a.LeadShortcuts,w=U&&1===e.fields.length&&!e.fields[0].required,C=U&&e.cancellable;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLabel:e.title||void 0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.sm},children:[e.title?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",accessibilityRole:"header",children:e.title}):null,e.allowTyped?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.typeAnswer}):null,e.fields.map(a=>{const l=n[a.key]??"",c=o[a.key];if("File"===a.type){const e=y[a.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),e?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xxs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.fileName,variant:"soft",onRemove:()=>{return e=a.key,commitUploads(Object.fromEntries(Object.entries(k.current).filter(([t])=>t!==e))),void setValue(e,"");var e},labels:{remove:s.inputRemoveFile}}),"Uploading"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:e.progress??void 0,label:s.attachmentUploading,height:4}):null,"Failed"===e.status?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:s.attachmentFailed}):null]}):(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.inputChooseFile,variant:"soft",size:"sm",leftIcon:"paperclip",disabled:p||void 0===i,onPress:()=>{(async e=>{if(!i)return;let r;try{r=await i()}catch{return void d(s.errorGeneric)}const a=r[0];if(!a)return;R.current+=1;const n=R.current;commitUploads({...k.current,[e.key]:{fileName:fileNameOf(a,e.label),status:"Uploading",progress:null,token:n}});try{const i=await t.uploadInputFile(a,t=>{isLiveUpload(e.key,n)&&patchUpload(e.key,{progress:t})});isLiveUpload(e.key,n)&&(setValue(e.key,i),patchUpload(e.key,{status:"Ready",progress:null}))}catch{isLiveUpload(e.key,n)&&(setValue(e.key,""),patchUpload(e.key,{status:"Failed",progress:null}))}})(a)}})}),c?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"assertive",children:c}):null]},a.key)}if("MultiChoice"===a.type){const e=(a.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{selectionMode:"multiple",options:e,value:selectedIds(l),onChange:t=>setValue(a.key,JSON.stringify(e.filter(e=>t.includes(e.value)).map(e=>e.value))),accessibilityLabel:a.label,error:c,disabled:p})})]},a.key)}if("Choice"===a.type||"TimeSlot"===a.type){const e="TimeSlot"===a.type?(a.slots??[]).map(e=>({label:slotFormat.format(new Date(e.startDateTimeUtc)),value:e.id})):(a.options??[]).map(e=>({label:e.label,value:e.id}));return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:`${a.label}${optionalSuffix(a,s)}`}),(0,_jsxRuntime.jsx)(_reactNative.View,{ref:e=>{v.current[a.key]=e},children:(0,_jsxRuntime.jsx)(_mobileUi.ChoiceGroup,{options:e,value:""===l?void 0:l,onChange:e=>setValue(a.key,String(e)),accessibilityLabel:a.label,error:c,disabled:p})})]},a.key)}if("Consent"===a.type)return(0,_jsxRuntime.jsx)(_mobileUi.Checkbox,{checked:"true"===l,onChange:e=>setValue(a.key,e?"true":"false"),label:a.consentText??a.label,error:c,disabled:p},a.key);const u=(0,_jsxRuntime.jsx)(_mobileUi.Input,{ref:e=>{h.current[a.key]=e},label:a.label,placeholder:a.placeholder??void 0,value:l,onChangeText:e=>setValue(a.key,e),maxLength:a.maxLength??void 0,required:a.required,error:c,help:a.required?void 0:s.inputOptional,labelMode:"top",disabled:p,type:a.secret?"password":"LongText"===a.type?"textarea":"input",keyboardType:KEYBOARD_TYPES[a.type]??"default",autoCapitalize:"Email"===a.type?"none":void 0,autoComplete:AUTO_COMPLETE[a.type]},a.key);if(!("Otp"===a.verify&&("Email"===a.type||"Phone"===a.type)))return u;const m=f[a.key];return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[u,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.inputSendCode,variant:"soft",size:"sm",disabled:p,onPress:()=>{(async i=>{if("Otp"===i.verify)try{await t.sendOtp(e.requestId,{fieldKey:i.key,value:(n[i.key]??"").trim()}),j(e=>({...e,[i.key]:"sent"}))}catch{j(e=>({...e,[i.key]:"failed"}))}})(a)},testID:`otp-send-${a.key}`}),(0,_jsxRuntime.jsx)(_mobileUi.Input,{label:s.inputEnterCode,value:_[a.key]??"",onChangeText:e=>b(t=>({...t,[a.key]:e})),keyboardType:"number-pad",autoComplete:"one-time-code",disabled:p}),m?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"failed"===m?"danger":"secondary",accessibilityLiveRegion:"polite",children:"failed"===m?s.inputCodeFailed:s.inputCodeSent}):null]})]},a.key)}),""!==u?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"danger",accessibilityLiveRegion:"polite",children:u}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:p?s.inputSubmitting:e.submitLabel,loading:p,disabled:p||T,onPress:()=>{(async()=>{if(T)return;const i={},r={};for(const t of e.fields){const e=n[t.key]??"";if("Consent"===t.type){const a="true"===e;t.required&&!a&&(i[t.key]=s.inputConsentRequired),r[t.key]=a?"true":"false"}else if("Choice"===t.type||"TimeSlot"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else if("MultiChoice"===t.type){const a=selectedIds(e);t.required&&0===a.length&&(i[t.key]=s.inputRequired),r[t.key]=JSON.stringify(a)}else if("File"===t.type)t.required&&""===e&&(i[t.key]=s.inputRequired),r[t.key]=e;else{const a=t.secret?e:e.trim();t.required&&""===a&&(i[t.key]=s.inputRequired),r[t.key]=a}}const a={};for(const t of e.fields){if("Otp"!==t.verify)continue;const e=(_[t.key]??"").trim();""===e&&(i[t.key]=s.inputRequired),a[t.key]=e}if(c(i),Object.keys(i).length>0){const t=firstErrorKey(e.fields,i);return void(void 0!==t&&S(t))}m(!0),d("");try{const i=await t.answerInput(e.requestId,r,Object.keys(a).length>0?a:null);if(i.ok)return;c(i.errors),g.current=!0,d(i.message??"")}catch{d(s.errorGeneric)}m(!1)})()}}),T?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:s.attachmentUploading}):null,w?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.skip,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.skipInput(e.requestId))}}):null,C?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.cancel,variant:"ghost",disabled:p,onPress:()=>{leave(()=>t.cancelLead())}}):null]})]})})}function InputRequestPart(e){const{part:t,message:i,turn:r,pickAttachments:s}=e;if("InputRequest"!==t.kind||t.fields.some(isUndrawnField)){const e={kind:"Notice",code:"NeedsNewerApp",text:r.labels.needsNewerApp};return(0,_jsxRuntime.jsx)(_NoticePart.NoticePart,{part:e,message:i,turn:r})}return"Answered"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:t.answeredSummary||r.labels.inputAnswered}):"Skipped"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputSkipped}):"Expired"===t.state?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"secondary",children:r.labels.inputExpired}):(0,_jsxRuntime.jsx)(OpenRequest,{part:t,turn:r,pickAttachments:s},t.requestId)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NoticePart=NoticePart;var _mobileUi=require("@webority/mobile-ui"),_jsxRuntime=require("react/jsx-runtime");function NoticePart({part:e}){const t="ActionLimitReached"===e.code||"AssistantUnavailable"===e.code?"warning":"info";return(0,_jsxRuntime.jsx)(_mobileUi.Banner,{message:e.text,tone:t,accessibilityRole:"summary"})}
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 +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"),_jsxRuntime=require("react/jsx-runtime");function lookOf(e){switch(e){case"Primary":return{variant:"soft",tone:"primary"};case"Cta":return{variant:"solid",tone:"primary"};default:return{variant:"outline"}}}function QuickRepliesPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)();if(!t.features.SuggestedReplies||!t.isLast||t.busy||t.handoffPause||0===e.replies.length)return null;const a=t.openTarget,n=void 0!==a&&a!==_chatShared.defaultOpenTarget;return(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityRole:"list",accessibilityLabel:t.labels.quickReplies,style:{flexDirection:"row",flexWrap:"wrap",gap:i.space.xs},children:e.replies.map((e,i)=>{const r=lookOf(e.variant),s=e.icon?e.icon:void 0;if("Send"===e.action)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:r.variant,tone:r.tone,leftIcon:s,onPress:()=>t.chooseQuickReply(e)})},e.id);const o=e.target;if("Open"===e.action&&o&&a)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:r.variant,tone:r.tone,leftIcon:s,onPress:()=>a(o)})},e.id);if("Navigate"===e.action&&t.features.LinkHandoff&&o&&a){const l=(0,_chatCore.isHandoffTarget)(o,t.handoffHosts)&&(!o.startsWith("/")||n);return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:i,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:r.variant,tone:r.tone,leftIcon:s,onPress:l?()=>t.beginHandoff(e,()=>a(o)):void 0})},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"),_jsxRuntime=require("react/jsx-runtime");const QUIET_LOOK={variant:"outline"};function lookOf(e){switch(e){case"Primary":case"Cta":return{variant:"solid",tone:"primary"};default:return QUIET_LOOK}}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,s="Composer"===e.placement,o=e.replies.filter(e=>"Send"===e.action||"Open"===e.action&&e.target&&n||"Navigate"===e.action&&i.features.LinkHandoff);if(0===o.length)return null;const l=s?void 0:o.find(e=>e.id===_chatCore.CHAT_HANDOFF_REQUEST_ID&&"Send"===e.action),c=l?o.filter(e=>e!==l):o,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,{accessibilityRole:"summary",accessibilityLabel:i.labels.quickReplies,accessibilityLiveRegion:i.handoffPause?"polite":void 0,style:{flexDirection:"row",flexWrap:"wrap",gap:t.space.xs,...s?{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,lookOf("Primary"))]})},l.id):null,c.map((e,t)=>{const s=t+u,o=l?QUIET_LOOK:lookOf(e.variant),c=e.icon?e.icon:void 0;if("Send"===e.action)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:s,children:sendChip(e,o)},e.id);const d=e.target;if("Open"===e.action&&d&&n)return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:s,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:e.label,variant:o.variant,tone:o.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:s,children:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"primary",children:e.label})},e.id):(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:s,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:i.handoffPause?i.labels.handoffMoment:e.label,variant:i.handoffPause?QUIET_LOOK.variant:o.variant,tone:i.handoffPause?void 0:o.tone,leftIcon:c,disabled:i.handoffPause,onPress:()=>i.beginHandoff(e,l)})},e.id)}return null})]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RecordCardPart=RecordCardPart;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 withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]);function RecordCardPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),r=void 0!==t.openRecord&&null!==e.target;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityRole:r?"button":"summary",accessibilityLabel:r?t.labels.recordOpenFor(e.title):void 0,onPress:r?()=>t.openRecord?.(e):void 0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0,numberOfLines:2}),e.subtitle?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.subtitle,variant:"bodySmall",color:"secondary"}):null,withPositions(e.fields).map(({key:e,item:t})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[e>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:i.colors["border-subtle"]}}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexShrink:1},children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:t.label,variant:"caption",color:"secondary"})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,alignItems:"flex-end"},children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:(0,_chatCore.formatChatValue)(t.value,t.type,null),variant:"bodySmall",color:"primary"})})]})]},e))]})})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RecordCardPart=RecordCardPart;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 withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]),NUMERIC=new Set(["Integer","Decimal","MoneyMinor","Percent"]);function RecordCardPart({part:e,turn:t}){const r=(0,_mobileUi.useTheme)(),i=void 0!==t.openRecord&&null!==e.target;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityRole:"summary",children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0,numberOfLines:2,enabled:t.features.FigureText,heading:!0}),e.subtitle?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.subtitle,variant:"bodySmall",color:"secondary",enabled:t.features.FigureText}):null,withPositions(e.fields).map(({key:e,item:i})=>(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:r.space.xs},children:[e>0?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:r.colors["border-subtle"]}}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",justifyContent:"space-between",gap:r.space.sm},children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexShrink:1},children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:i.label,variant:"caption",color:"secondary",enabled:t.features.FigureText})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flex:1,alignItems:NUMERIC.has(i.type)?"flex-end":"flex-start"},children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:(0,_chatCore.formatChatValue)(i.value,i.type,null),variant:"bodySmall",color:"primary",enabled:t.features.FigureText})})]})]},e)),i?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:t.labels.recordOpen,variant:"link",size:"sm",accessibilityLabel:t.labels.recordOpenFor((0,_chatCore.toFigureText)(e.title)),onPress:()=>t.openRecord?.(e),testID:`record-open-${e.recordId}`}):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:t}){const r=(0,_mobileUi.useTheme)();if(!t.features.Sources||0===e.sources.length)return null;const s=t.openTarget;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityRole:"list",accessibilityLabel:t.labels.sources,style:{gap:r.space.xs},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:t.labels.sources}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row",flexWrap:"wrap",gap:r.space.xs},children:e.sources.map((e,r)=>{const i=e.url;return(0,_jsxRuntime.jsx)(_ChatEntrance.ChatEntrance,{index:r,children:(0,_jsxRuntime.jsx)(_mobileUi.Chip,{label:`${e.marker} ${e.title}`,variant:"outline",size:"sm",accessibilityLabel:t.labels.openSource(e.title),onPress:null!==i&&HTTP_LINK.test(i)&&s?()=>s(i):void 0})},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",accessibilityLabel:a?r.labels.openSource(e.title):void 0,onPress:a})})},e.marker)})})]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TablePart=TablePart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const PREVIEW_ROWS=10,COLUMN_WIDTH={Text:140,Integer:88,Decimal:96,MoneyMinor:112,Percent:80,Date:112,DateTimeUtc:152},NUMERIC=new Set(["Integer","Decimal","MoneyMinor","Percent"]),withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]);function TablePart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),[r,l]=(0,_react.useState)(!1);if(0===e.columns.length||0===e.rows.length)return null;const s=r?e.rows:e.rows.slice(0,PREVIEW_ROWS),a={height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:i.colors["border-subtle"]},n={paddingVertical:i.space.xs,paddingHorizontal:i.space.sm},cellValue=(t,i,r)=>{const l=t[i];return null==l?null:(0,_chatCore.formatChatValue)(l,r.type,e.currency)};return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLabel:e.title?(0,_chatCore.toFigureText)(e.title):t.labels.table,style:{gap:i.space.xs},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0}):null,(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",children:(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!0,nestedScrollEnabled:!0,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:e.columns.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:[n,{width:COLUMN_WIDTH[e.type],alignItems:NUMERIC.has(e.type)?"flex-end":"flex-start"}],children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.label,variant:"label",color:"secondary",strong:!0,numberOfLines:2})},e.key))}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:a}),withPositions(s).map(({key:t,item:i})=>{const r=e.columns.map((e,t)=>`${(0,_chatCore.toFigureText)(e.label)}: ${cellValue(i,t,e)??"-"}`).join(", ");return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessible:!0,accessibilityLabel:r,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row"},children:e.columns.map((e,t)=>{const r=cellValue(i,t,e);return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[n,{width:COLUMN_WIDTH[e.type],alignItems:NUMERIC.has(e.type)?"flex-end":"flex-start"}],children:null===r?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"tertiary",children:"-"}):(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:r,variant:"bodySmall",color:"primary",numberOfLines:3})},e.key)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:a})]},t)})]})})}),!r&&e.rows.length>PREVIEW_ROWS?(0,_jsxRuntime.jsx)(_mobileUi.Button,{variant:"link",size:"sm",label:t.labels.tableShowAll(e.rows.length),onPress:()=>l(!0)}):null]})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TablePart=TablePart;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native"),_FigureText=require("./FigureText.js"),_jsxRuntime=require("react/jsx-runtime");const PREVIEW_ROWS=25,COLUMN_WIDTH={Text:140,Integer:88,Decimal:96,MoneyMinor:112,Percent:80,Date:112,DateTimeUtc:152},NUMERIC=new Set(["Integer","Decimal","MoneyMinor","Percent"]),withPositions=e=>e.reduce((e,t)=>(e.push({key:e.length,item:t}),e),[]);function TablePart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),[r,n]=(0,_react.useState)(!1),[s,a]=(0,_react.useState)(0),[l,o]=(0,_react.useState)(0),[c,u]=(0,_react.useState)(0);if(0===e.columns.length||0===e.rows.length)return null;const plain=e=>t.features.FigureText?(0,_chatCore.toFigureText)(e):e,x=l>c+s+1,m=r?e.rows:e.rows.slice(0,PREVIEW_ROWS),_={height:_reactNative.StyleSheet.hairlineWidth,backgroundColor:i.colors["border-subtle"]},h={paddingVertical:i.space.xs,paddingHorizontal:i.space.sm},cellValue=(t,i,r)=>{const n=t[i];return null==n?null:(0,_chatCore.formatChatValue)(n,r.type,e.currency)};return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLabel:e.title?plain(e.title):t.labels.table,style:{gap:i.space.xs},children:[e.title?(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.title,variant:"label",color:"primary",strong:!0,enabled:t.features.FigureText}):null,(0,_jsxRuntime.jsxs)(_mobileUi.Card,{variant:"outline",padding:"sm",onLayout:e=>u(e.nativeEvent.layout.width),children:[(0,_jsxRuntime.jsx)(_reactNative.ScrollView,{horizontal:!0,showsHorizontalScrollIndicator:!0,nestedScrollEnabled:!0,onScroll:e=>a(e.nativeEvent.contentOffset.x),onContentSizeChange:e=>o(e),scrollEventThrottle:16,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:{flexDirection:"row"},children:e.columns.map(e=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:[h,{width:COLUMN_WIDTH[e.type],alignItems:NUMERIC.has(e.type)?"flex-end":"flex-start"}],children:(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:e.label,variant:"label",color:"secondary",strong:!0,numberOfLines:2,enabled:t.features.FigureText})},e.key))}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_}),withPositions(m).map(({key:i,item:r})=>{const n=e.columns.map((e,t)=>`${plain(e.label)}: ${cellValue(r,t,e)??"-"}`).join(", ");return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessible:!0,accessibilityLabel:n,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row"},children:e.columns.map((e,i)=>{const n=cellValue(r,i,e);return(0,_jsxRuntime.jsx)(_reactNative.View,{style:[h,{width:COLUMN_WIDTH[e.type],alignItems:NUMERIC.has(e.type)?"flex-end":"flex-start"}],children:null===n?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",color:"tertiary",children:"-"}):(0,_jsxRuntime.jsx)(_FigureText.FigureText,{text:n,variant:"bodySmall",color:"primary",numberOfLines:3,enabled:t.features.FigureText})},e.key)})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:_})]},i)})]})}),x?(0,_jsxRuntime.jsx)(_reactNative.View,{pointerEvents:"none",style:{position:"absolute",right:0,top:0,bottom:0,justifyContent:"center"},children:(0,_jsxRuntime.jsx)(_mobileUi.AppIcon,{name:"chevron-right",size:"sm",color:"tertiary"})}):null]}),!r&&e.rows.length>PREVIEW_ROWS?(0,_jsxRuntime.jsx)(_mobileUi.Button,{variant:"link",size:"sm",label:t.labels.tableShowAll(e.rows.length),onPress:()=>n(!0)}):null]})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TicketPart=TicketPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function TicketPart({part:e,turn:i}){const t=(0,_mobileUi.useTheme)(),{labels:r,openTicket:s}=i,n=r.ticketAria(e.number),a=s?()=>s({ticketId:e.ticketId,number:e.number}):void 0;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",interactive:void 0!==a,onPress:a,accessibilityLabel:`${n}, ${e.status}`,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:t.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:t.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:n}),(0,_jsxRuntime.jsx)(_mobileUi.Chip,{size:"sm",variant:"soft",label:e.status})]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",numberOfLines:2,children:e.subject}),a?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:r.ticketView}):null]})})}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TicketPart=TicketPart;var _mobileUi=require("@webority/mobile-ui"),_reactNative=require("react-native"),_jsxRuntime=require("react/jsx-runtime");function TicketPart({part:e,turn:t}){const i=(0,_mobileUi.useTheme)(),{labels:s,openTicket:r}=t,a=s.ticketAria(e.number),n=s.ticketStatus(e.status),l=r?()=>r({ticketId:e.ticketId,number:e.number}):void 0;return(0,_jsxRuntime.jsx)(_mobileUi.Card,{variant:"outline",padding:"sm",accessibilityLabel:n?`${a}, ${n}`:a,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{gap:i.space.xs},children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:i.space.sm},children:[(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"label",children:a}),n?(0,_jsxRuntime.jsx)(_mobileUi.Chip,{size:"sm",variant:"soft",label:n}):null]}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"bodySmall",children:e.subject}),l?(0,_jsxRuntime.jsx)(_mobileUi.Button,{label:s.ticketView,variant:"link",size:"sm",onPress:l,testID:`ticket-view-${e.ticketId}`}):null]})})}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VoiceClipPart=VoiceClipPart;var _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 r=(0,_mobileUi.useTheme)(),i=(0,_react.useMemo)(()=>buildStyles(r),[r]),c=t.labels,[a,n]=(0,_react.useState)(!1),[l,s]=(0,_react.useState)(!1),[o,u]=(0,_react.useState)(!1),[p,h]=(0,_react.useState)(0),_=(0,_react.useRef)(null),m=(0,_react.useRef)(null),x=(0,_react.useRef)(!0);(0,_react.useEffect)(()=>(x.current=!0,()=>{x.current=!1,_.current?.stop(),_.current=null,null!==m.current&&(0,_phoneSpeech.discardFile)(m.current)}),[]);const startPlayback=e=>{const t=(0,_expoAudio.playFile)(e,e=>{x.current&&(h(e.positionMs),u(e.playing))});_.current=t;const release=()=>!(!x.current||_.current!==t)&&(_.current=null,u(!1),!0);t.finished.then(()=>{release()&&h(0)},e=>{release()&&(s(!0),_mobileCore.Logger.error("[chat] voice clip playback failed",e))})},d=t.features.VoiceClips&&!l,b=null!==e.transcript&&""!==e.transcript.trim()?e.transcript:null,y=e.durationMs>0?Math.min(1,Math.max(0,p/e.durationMs)):0;return(0,_jsxRuntime.jsxs)(_reactNative.View,{accessibilityLabel:c.voiceClip,testID:"chat-voice-clip",style:i.root,children:[d?(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:i.row,children:[(0,_jsxRuntime.jsx)(_mobileUi.IconButton,{icon:o?"pause":"play",accessibilityLabel:o?c.voiceClipPause:c.voiceClipPlay,variant:"ghost",tone:"neutral",size:"sm",loading:a,onPress:()=>{const r=_.current;null===r?null===m.current?a||(async()=>{n(!0),s(!1);try{const r=new Uint8Array(await t.readAttachment(e.attachmentId)),{File:i,Paths:c}=expoFileSystem(),a=new i(c.cache,`wchat-clip-${e.attachmentId}${(0,_speechText.audioExtension)(r)}`);if(a.create({overwrite:!0}),a.write(r),!x.current)return void(0,_phoneSpeech.discardFile)(a.uri);m.current=a.uri,startPlayback(a.uri)}catch(e){if(!x.current)return;s(!0),_mobileCore.Logger.error("[chat] voice clip failed to load",e)}finally{x.current&&n(!1)}})():startPlayback(m.current):o?r.pause():r.resume()},testID:"chat-voice-clip-play"}),(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:"secondary",children:c.voiceClipTime((0,_speechText.formatClipTime)(p),(0,_speechText.formatClipTime)(e.durationMs))})]}),p>0?(0,_jsxRuntime.jsx)(_mobileUi.ProgressBar,{progress:y,height:4}):null]}):null,null!==b?(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"body",children:b}):null,d||null!==b?null:(0,_jsxRuntime.jsx)(_mobileUi.Text,{variant:"caption",color:l?"danger":"secondary",accessibilityLiveRegion:"polite",children:c.voiceClipFailed})]})}const buildStyles=e=>_reactNative.StyleSheet.create({root:{gap:e.space.xs},row:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});
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 +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=>{i?.abort();const t=n,o=new AbortController,forward=()=>o.abort();e.signal?.aborted&&o.abort(),e.signal?.addEventListener("abort",forward),i=o;const a=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(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=a.then(()=>{},()=>{});try{await a}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"),_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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MIN_DICTATION_MS=exports.MAX_SPEAK_CHARS=exports.MAX_DICTATION_MS=exports.DEFAULT_SPEECH_VOICE=exports.DEFAULT_SPEECH_LANGUAGE=void 0,exports.audioExtension=audioExtension,exports.buildSsml=buildSsml,exports.clampSpeakText=clampSpeakText,exports.escapeSsml=escapeSsml,exports.formatClipTime=formatClipTime,exports.joinDictation=joinDictation;const DEFAULT_SPEECH_LANGUAGE=exports.DEFAULT_SPEECH_LANGUAGE="en-IN",DEFAULT_SPEECH_VOICE=exports.DEFAULT_SPEECH_VOICE="en-IN-NeerjaNeural",MAX_SPEAK_CHARS=exports.MAX_SPEAK_CHARS=4e3,MAX_DICTATION_MS=exports.MAX_DICTATION_MS=6e4,MIN_DICTATION_MS=exports.MIN_DICTATION_MS=600,SENTENCE_END_FLOOR=2e3,ascii=e=>Array.from(e,e=>e.charCodeAt(0)),OGG=ascii("OggS"),RIFF=ascii("RIFF"),EBML=[26,69,223,163],ID3=ascii("ID3"),MPEG_FRAME_HEADERS=[[255,251],[255,243],[255,242]],startsWith=(e,t,s)=>s.every((s,r)=>e[t+r]===s);function audioExtension(e){return startsWith(e,0,OGG)?".ogg":startsWith(e,0,RIFF)?".wav":startsWith(e,0,EBML)?".webm":startsWith(e,0,ID3)||MPEG_FRAME_HEADERS.some(t=>startsWith(e,0,t))?".mp3":".m4a"}function escapeSsml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function buildSsml(e,t,s){return`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="${escapeSsml(t)}"><voice name="${escapeSsml(s)}">${escapeSsml(e)}</voice></speak>`}function clampSpeakText(e){const t=e.trim();if(t.length<=MAX_SPEAK_CHARS)return t;const s=t.slice(0,MAX_SPEAK_CHARS),r=Math.max(s.lastIndexOf("."),s.lastIndexOf("?"),s.lastIndexOf("!"));return r>SENTENCE_END_FLOOR?s.slice(0,r+1):s}function formatClipTime(e){if(!Number.isFinite(e)||e<0)return"0:00";const t=Math.floor(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function joinDictation(e,t,s){const r=t.trim();if(""===r)return e;return`${e}${e.length>0&&!/\s$/.test(e)?" ":""}${r}`.slice(0,s)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MIN_DICTATION_MS=exports.MAX_SPEAK_CHARS=exports.MAX_DICTATION_MS=exports.DEFAULT_SPEECH_VOICE=exports.DEFAULT_SPEECH_LANGUAGE=void 0,exports.audioExtension=audioExtension,exports.buildSsml=buildSsml,exports.clampSpeakText=clampSpeakText,exports.escapeSsml=escapeSsml,exports.formatClipTime=formatClipTime,exports.joinDictation=joinDictation;const DEFAULT_SPEECH_LANGUAGE=exports.DEFAULT_SPEECH_LANGUAGE="en-IN",DEFAULT_SPEECH_VOICE=exports.DEFAULT_SPEECH_VOICE="en-IN-NeerjaNeural",MAX_SPEAK_CHARS=exports.MAX_SPEAK_CHARS=6e3,MAX_DICTATION_MS=exports.MAX_DICTATION_MS=3e5,MIN_DICTATION_MS=exports.MIN_DICTATION_MS=600,ascii=e=>Array.from(e,e=>e.charCodeAt(0)),OGG=ascii("OggS"),RIFF=ascii("RIFF"),EBML=[26,69,223,163],ID3=ascii("ID3"),MPEG_FRAME_HEADERS=[[255,251],[255,243],[255,242]],startsWith=(e,t,s)=>s.every((s,r)=>e[t+r]===s);function audioExtension(e){return startsWith(e,0,OGG)?".ogg":startsWith(e,0,RIFF)?".wav":startsWith(e,0,EBML)?".webm":startsWith(e,0,ID3)||MPEG_FRAME_HEADERS.some(t=>startsWith(e,0,t))?".mp3":".m4a"}function escapeSsml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function buildSsml(e,t,s){return`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="${escapeSsml(t)}"><voice name="${escapeSsml(s)}">${escapeSsml(e)}</voice></speak>`}function clampSpeakText(e){const t=e.trim();if(t.length<=MAX_SPEAK_CHARS)return t;const s=t.slice(0,MAX_SPEAK_CHARS),r=s.lastIndexOf(". ");return-1===r?s.trim():s.slice(0,r+1)}function formatClipTime(e){if(!Number.isFinite(e)||e<0)return"0:00";const t=Math.round(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function joinDictation(e,t,s){const r=t.trim();if(""===r)return e;return`${e}${e.length>0&&!/\s$/.test(e)?" ":""}${r}`.slice(0,s)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChat=useChat;var _chatCore=require("@webority/chat-core"),_react=require("react"),_reactNative=require("react-native");const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze((0,_chatCore.emptyFeatures)()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});function useChat(e){const{client:t,screen:r,layout:n,narrow:a,conversationId:s,pageContext:c,behaviour:o,prefs:u,getCaptchaToken:i,onEvent:l,onError:f,onNavigate:p}=e,v=JSON.stringify(a??{}),_=(0,_react.useRef)(p);_.current=p;const d=(0,_react.useCallback)(e=>_.current?.(e),[]),m=(0,_react.useRef)(s);m.current=s;const g=(0,_react.useRef)(c);g.current=c;const S=(0,_react.useRef)(o);S.current=o;const h=(0,_react.useRef)(i);h.current=i;const E=(0,_react.useRef)(l);E.current=l;const C=(0,_react.useRef)(f);C.current=f;const y=(0,_react.useRef)(u);y.current=u;const[b,I]=(0,_react.useState)(null);(0,_react.useEffect)(()=>{const e=(0,_chatCore.createChatSession)(t,{screen:r,layout:n,narrow:JSON.parse(v),conversationId:m.current??void 0,pageContext:()=>g.current,behaviour:()=>S.current?.()??null,prefs:y.current,getCaptchaToken:e=>h.current?.(e)??Promise.resolve(null),onEvent:(e,t)=>E.current?.(e,t),onError:e=>C.current?.(e),schedule:requestFrame});return I({client:t,screen:r,layout:n,narrowKey:v,session:e}),()=>e.dispose()},[t,r,n,v]);const N=null!==b&&b.client===t&&b.screen===r&&b.layout===n&&b.narrowKey===v?b.session:IDLE_SESSION,O=(0,_react.useSyncExternalStore)(N.subscribe,N.getState),R=(0,_react.useMemo)(()=>({load:()=>N.load(),submit:e=>N.submit(e),chooseQuickReply:e=>N.chooseQuickReply(e),answerInput:(e,t)=>N.answerInput(e,t),confirmAction:e=>N.confirmAction(e),rejectAction:(e,t)=>N.rejectAction(e,t),stop:()=>N.stop(),retry:()=>N.retry(),regenerate:()=>N.regenerate(),startEdit:e=>N.startEdit(e),cancelEdit:()=>N.cancelEdit(),attach:e=>N.attach(e),removeAttachment:e=>N.removeAttachment(e),openConversation:e=>N.openConversation(e),resumeLast:()=>N.resumeLast(),newConversation:()=>N.newConversation(),rate:(e,t,r)=>N.rate(e,t,r),reset:()=>N.reset(),requestHandoff:e=>N.requestHandoff(e),notifyTyping:()=>N.notifyTyping(),resumeLive:()=>N.resumeLive()}),[N]),A=(0,_react.useRef)(s);(0,_react.useEffect)(()=>{N!==IDLE_SESSION&&s&&s!==A.current&&(A.current=s,N.openConversation(s))},[s,N]);const T=(0,_react.useRef)("active"===_reactNative.AppState.currentState),L=(0,_react.useRef)(!0),k=(0,_react.useCallback)(()=>N.setLiveActive(T.current&&L.current),[N]),w=(0,_react.useCallback)(e=>{L.current=e,k()},[k]);(0,_react.useEffect)(()=>{k();const e=_reactNative.AppState.addEventListener("change",e=>{"active"===e?(T.current=!0,N.endHandoffPause()):T.current=!1,k()});return()=>e.remove()},[k,N]);const P=(0,_react.useCallback)((e,t)=>{E.current?.(e,t)},[]);return{...O,...R,session:N,client:t,emit:P,setChatVisible:w,onNavigate:p?d:void 0}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChat=useChat;var _chatCore=require("@webority/chat-core"),_mobileUi=require("@webority/mobile-ui"),_react=require("react"),_reactNative=require("react-native");const requestFrame=e=>{const t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},NO_SUBSCRIPTION=()=>()=>{},IDLE_STATE=Object.freeze({profile:null,profileError:null,features:Object.freeze((0,_chatCore.emptyFeatures)()),conversationId:null,conversationState:"Open",title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:"Off",handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),IDLE_SESSION=new Proxy({},{get:(e,t)=>{if("symbol"!=typeof t&&"client"!==t&&"toJSON"!==t&&!t.startsWith("$$")){if("getState"===t)return()=>IDLE_STATE;if("subscribe"===t)return NO_SUBSCRIPTION;if("then"!==t)return()=>Promise.resolve()}}});function useChat(e){const{client:t,screen:r,layout:n,narrow:a,conversationId:c,pageContext:o,behaviour:s,prefs:u,getCaptchaToken:i,onEvent:l,onError:f,onNavigate:_}=e,p=JSON.stringify(a??{}),d=(0,_react.useRef)(_);d.current=_;const v=(0,_react.useCallback)(e=>d.current?.(e),[]),m=(0,_react.useRef)(c);m.current=c;const h=(0,_react.useRef)(o);h.current=o;const E=(0,_react.useRef)(s);E.current=s;const g=(0,_react.useRef)(i);g.current=i;const S=(0,_react.useRef)(l);S.current=l;const y=(0,_react.useRef)(f);y.current=f;const C=(0,_react.useRef)(u);C.current=u;const b=(0,_mobileUi.useReducedMotion)(),I=(0,_react.useRef)(b);I.current=b;const[R,A]=(0,_react.useState)(null),[N,L]=(0,_react.useState)(null);(0,_react.useEffect)(()=>{const e=(0,_chatCore.createChatSession)(t,{screen:r,layout:n,pathname:()=>r||"/",narrow:JSON.parse(p),conversationId:m.current??void 0,pageContext:()=>h.current,behaviour:()=>E.current?.()??null,prefs:C.current,getCaptchaToken:e=>g.current?.(e)??Promise.reject(new Error("No captcha handler.")),onEvent:(e,t)=>S.current?.(e,t),onError:e=>y.current?.(e),schedule:requestFrame,reducedMotion:()=>I.current});return A({client:t,screen:r,layout:n,narrowKey:p,session:e}),()=>e.dispose()},[t,r,n,p]);const O=null!==R&&R.client===t&&R.screen===r&&R.layout===n&&R.narrowKey===p?R.session:IDLE_SESSION,T=(0,_react.useSyncExternalStore)(O.subscribe,O.getState),w=(0,_react.useMemo)(()=>({load:()=>O.load(),submit:e=>O.submit(e),chooseQuickReply:e=>O.chooseQuickReply(e),answerInput:(e,t)=>O.answerInput(e,t),confirmAction:e=>O.confirmAction(e),rejectAction:(e,t)=>O.rejectAction(e,t),stop:()=>O.stop(),retry:()=>O.retry(),regenerate:()=>O.regenerate(),startEdit:e=>O.startEdit(e),cancelEdit:()=>O.cancelEdit(),attach:e=>O.attach(e),removeAttachment:e=>O.removeAttachment(e),openConversation:e=>O.openConversation(e),resumeLast:()=>O.resumeLast(),newConversation:()=>O.newConversation(),rate:(e,t,r)=>O.rate(e,t,r),reset:()=>O.reset(),requestHandoff:async e=>{L(null);try{await O.requestHandoff(e)}catch(e){const t=e instanceof Error&&""!==e.message?e.message:_chatCore.DEFAULT_CHAT_LABELS.errorGeneric;throw L(t),e}},notifyTyping:()=>O.notifyTyping(),resumeLive:()=>O.resumeLive()}),[O]),k=(0,_react.useRef)(c);(0,_react.useEffect)(()=>{O!==IDLE_SESSION&&c&&c!==k.current&&(k.current=c,O.openConversation(c))},[c,O]);const q=(0,_react.useRef)("active"===_reactNative.AppState.currentState),P=(0,_react.useRef)(!0),j=(0,_react.useCallback)(()=>O.setLiveActive(q.current&&P.current),[O]),x=(0,_react.useCallback)(e=>{P.current=e,j()},[j]);(0,_react.useEffect)(()=>{j();const e=_reactNative.AppState.addEventListener("change",e=>{"active"===e?(q.current=!0,O.endHandoffPause()):q.current=!1,j()});return()=>e.remove()},[j,O]);const D=(0,_react.useCallback)((e,t)=>{S.current?.(e,t)},[]);return{...T,...w,session:O,client:t,emit:D,setChatVisible:x,handoffError:N,onNavigate:_?v:void 0}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChatHaptics=useChatHaptics;var _react=require("react"),_reactNative=require("react-native");const isReply=e=>"Assistant"===e.author.kind||"Agent"===e.author.kind&&e.stored;function useChatHaptics(e){const t=(0,_react.useRef)(null),r=e.features.Sounds&&!0===e.profile?.experience.sound.vibrate&&!e.muted,s=e.profile?.experience.sound.vibrateMs??0;(0,_react.useEffect)(()=>{if(null!==t.current)for(const a of e.messages){if(!isReply(a)||a.streaming||t.current.has(a.id))continue;if(t.current.add(a.id),a.restored)continue;const e=a.parts.length>0&&a.parts.every(e=>"Notice"===e.kind),i="Agent"!==a.author.kind||"active"===_reactNative.AppState.currentState;r&&!e&&i&&_reactNative.Vibration.vibrate(s)}else t.current=new Set(e.messages.map(e=>e.id))},[e.messages,r,s])}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useChatHaptics=useChatHaptics;var _react=require("react"),_reactNative=require("react-native");const isReply=e=>"Assistant"===e.author.kind||"Script"===e.author.kind||"Agent"===e.author.kind;function useChatHaptics(e){const t=(0,_react.useRef)(null),r=e.features.Sounds&&!0===e.profile?.experience.sound.vibrate&&!e.muted,s=e.profile?.experience.sound.vibrateMs??0;(0,_react.useEffect)(()=>{if(null!==t.current)for(const i of e.messages){if(!isReply(i)||i.streaming||t.current.has(i.id))continue;if(t.current.add(i.id),i.restored)continue;const e=i.parts.some(e=>"Notice"===e.kind);r&&!e&&_reactNative.Vibration.vibrate(s)}else t.current=new Set(e.messages.map(e=>e.id))},[e.messages,r,s])}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CUES=void 0,exports.playCue=playCue,exports.useChatSound=useChatSound;var _mobileCore=require("@webority/mobile-core"),_react=require("react");const CUES=exports.CUES={open:{from:420,to:920,seconds:.16,peak:.16},reply:{from:680,to:540,seconds:.11,peak:.06},sent:{from:540,to:760,seconds:.09,peak:.05}},SAMPLE_RATE=22050,ATTACK_SECONDS=.01,written=new Map;function cueBytes(e){const t=Math.round(22050*e.seconds),n=2*t,s=new Uint8Array(44+n),o=new DataView(s.buffer),text=(e,t)=>{for(let n=0;n<t.length;n+=1)o.setUint8(e+n,t.charCodeAt(n))};text(0,"RIFF"),o.setUint32(4,36+n,!0),text(8,"WAVE"),text(12,"fmt "),o.setUint32(16,16,!0),o.setUint16(20,1,!0),o.setUint16(22,1,!0),o.setUint32(24,22050,!0),o.setUint32(28,44100,!0),o.setUint16(32,2,!0),o.setUint16(34,16,!0),text(36,"data"),o.setUint32(40,n,!0);const r=Math.min(.01,e.seconds/2);let a=0;for(let n=0;n<t;n+=1){const t=n/22050,s=e.from+(e.to-e.from)*t/e.seconds;a+=2*Math.PI*s/22050;const i=t<r?t/r:(e.seconds-t)/(e.seconds-r);o.setInt16(44+2*n,Math.round(32767*e.peak*i*Math.sin(a)),!0)}return s}function playCue(e,t=1){(async()=>{let n=written.get(e);if(void 0===n){const{File:t,Paths:s}=require("expo-file-system"),o=new t(s.cache,`wchat-cue-${e}.wav`);o.create({overwrite:!0}),o.write(cueBytes(CUES[e])),n=o.uri,written.set(e,n)}const{createAudioPlayer:s}=require("expo-audio"),o=s({uri:n});o.volume=t,o.addListener("playbackStatusUpdate",e=>{e.didJustFinish&&o.remove()}),o.play()})().catch(e=>{_mobileCore.Logger.warn("[chat] sound cue failed",e)})}function takeUnseen(e,t,n){if(t){e.wasLoading=!0;for(const t of n)e.seen.add(t.id);return[]}if(e.wasLoading||!e.seeded){e.wasLoading=!1,e.seeded=!0;for(const t of n)e.seen.add(t.id);return[]}const s=[];for(const t of n)e.seen.has(t.id)||(e.seen.add(t.id),s.push(t));return s}function useChatSound(e){const t=e.features.Sounds?e.profile?.experience.sound??null:null,n=(0,_react.useRef)(e);n.current=e;const s=(0,_react.useRef)(e.open),o=(0,_react.useRef)({seen:new Set,seeded:!1,wasLoading:!1}),{open:r,loading:a,messages:i}=e;(0,_react.useEffect)(()=>{const e=s.current;s.current=r;const u=takeUnseen(o.current,a,i);if(null!==t&&!n.current.muted&&t.volume>0){r&&!e&&t.open&&playCue("open",t.volume);for(const e of u){if(e.restored||e.parts.some(e=>"Notice"===e.kind))continue;const n=e.author.kind;"Visitor"===n?!e.stored&&t.sent&&playCue("sent",t.volume):"Assistant"!==n&&"Script"!==n&&"Agent"!==n||!t.reply||playCue("reply",t.volume)}}},[r,a,i,t])}
@@ -1 +1 @@
1
- "use strict";import{Avatar,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function AgentByline({author:e,labels:s}){const t=useTheme(),i=e.displayName||s.agent,r=e.avatarUrl?{uri:e.avatarUrl}:void 0;return _jsxs(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row",alignItems:"center",gap:t.space.xs},children:[_jsx(Avatar,{size:"xs",name:i,source:r}),_jsx(Text,{variant:"caption",color:"secondary",children:i})]})}
1
+ "use strict";import{Avatar,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function AgentByline({author:e,labels:t}){const r=useTheme(),i=e.displayName||t.agent,a=e.avatarUrl?{uri:e.avatarUrl}:void 0;return _jsxs(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",style:{flexDirection:"row",alignItems:"center",gap:r.space.xs},children:[_jsx(Avatar,{size:"xs",name:i,source:a}),_jsx(Text,{variant:"caption",color:"secondary",children:i}),_jsx(Text,{variant:"caption",color:"tertiary",children:t.agent})]})}
@@ -0,0 +1 @@
1
+ "use strict";import{ThemeProvider,useTheme,useThemeMode}from"@webority/mobile-ui";import{useMemo}from"react";import{Fragment as _Fragment,jsx as _jsx}from"react/jsx-runtime";const DISPLAY_FONT="var(--wui-font-display)",radiusPx=e=>{if(null==e)return null;const r=Number.parseFloat(e);return Number.isFinite(r)?r:null},brandFor=(e,r,n)=>{if(null===e&&null===r&&null===n)return;const t={};return null!==e&&(t.colors={light:{primary:e},dark:{primary:e}}),null!==r&&(t.radius={md:r,lg:r,xl:r}),null!==n&&(t.font={ui:n}),t};export function ChatAppearanceScope({appearance:e,children:r}){const n=useTheme(),{preference:t}=useThemeMode(),i=e?.["--wui-chat-accent"]??null,u=radiusPx(e?.["--wui-chat-radius"]),l=e?.["--wui-chat-font"]===DISPLAY_FONT?n.font.display:null,a=useMemo(()=>brandFor(i,u,l),[i,u,l]);return void 0===a?_jsx(_Fragment,{children:r}):_jsx(ThemeProvider,{initialPreference:t,brand:a,settings:n.settings,children:r},t)}
@@ -1 +1 @@
1
- "use strict";import{Permissions}from"@webority/mobile-core/permissions";import{Banner,Chip,Composer,IconButton,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatDictationButton}from"./ChatDictationButton.js";import{ChatFooter}from"./ChatFooter.js";import{joinDictation}from"./speech/speechText.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const ALLOWANCE_SHOWN_AT=10,DEFAULT_MAX_LENGTH=4e3;export function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:o,safeArea:i,testID:n="chat-composer"}){const r=useTheme(),l=useMemo(()=>buildStyles(r),[r]),[c,m]=useState(""),[p,h]=useState(null),d=e.editing;useEffect(()=>{m(d?d.text:"")},[d]);const g=e.attachments,u=g.some(e=>"Uploading"===e.status),f=g.some(e=>"Ready"===e.status),x=e.messagesLeftToday,b=e.profile?.limits.maxMessageLength??4e3,y=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,v=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),j=y&&!e.handoffPause?_jsx(IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${n}-attach`}):void 0,_=d?_jsx(Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${n}-editing`}):null,S=g.length>0?_jsx(View,{style:l.tray,testID:`${n}-attachments`,children:_jsx(View,{style:l.row,children:g.map(s=>_jsxs(View,{style:l.item,children:[_jsx(Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{remove:t.removeAttachment},removeTestID:`${n}-remove-${s.key}`,testID:`${n}-chip-${s.key}`}),"Uploading"===s.status?_jsx(ProgressBar,{progress:s.progress??void 0,label:t.attachmentUploading,height:4,containerStyle:l.progress}):null,"Failed"===s.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:t.attachmentFailed}):null]},s.key))})}):null,w=null!==x&&x<=10?_jsx(Text,{variant:"caption",color:0===x?"danger":"secondary",accessibilityLiveRegion:"polite",testID:`${n}-allowance`,children:t.allowance(x)}):null,A=p?_jsx(Banner,{message:p.message,tone:"danger",dismissible:!0,onClose:()=>h(null),actions:p.openSettings?[{label:t.dictateOpenSettings,onPress:()=>{Permissions.openSettings()}}]:void 0,testID:`${n}-voice-notice`}):null,D=_||S||w||A?_jsxs(_Fragment,{children:[_,S,w,A]}):void 0,C=!u&&(!!f||void 0),T=c.length>0,L=!0===e.profile?.experience.motion;return _jsx(Composer,{onSend:t=>{e.submit(t)},value:c,onChangeText:t=>{m(t),v&&t.length>0&&e.notifyTyping()},loading:e.streaming,ring:L&&(T||e.streaming),sendReveal:L?"onText":"always",onStop:e.features.Stop?()=>e.stop():void 0,stopLabel:t.stop,disabled:0===x||e.handoffPause,maxLength:b,canSend:C,placeholder:e.handoffPause?t.handoffMoment:t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:j,trailing:_jsx(ChatDictationButton,{chat:e,labels:t,disabled:0===x||e.handoffPause,onText:e=>m(t=>joinDictation(t,e,b)),onNotice:h}),above:D,below:_jsx(ChatFooter,{chat:e,labels:t}),keyboardAware:o,keyboardOffset:a,safeArea:i,testID:n})}const buildStyles=e=>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";import{defaultChatLook}from"@webority/chat-core";import{Permissions}from"@webority/mobile-core/permissions";import{Banner,Chip,Composer,IconButton,ProgressBar,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatDictationButton}from"./ChatDictationButton.js";import{ChatFooter}from"./ChatFooter.js";import{joinDictation}from"./speech/speechText.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"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};export function ChatComposer({chat:e,labels:t,pickAttachments:s,keyboardOffset:a,keyboardAware:o,safeArea:n,testID:i="chat-composer",focusRef:r,look:l=defaultChatLook}){const c=useTheme(),u=useMemo(()=>buildStyles(c),[c]),[m,p]=useState(""),[h,d]=useState(null),f=e.editing,g=useRef(null),x=useRef(null);useEffect(()=>{if(r)return r.current=()=>x.current?.focus(),()=>{r.current=null}},[r]),useEffect(()=>{f&&g.current?.(),p(f?f.text:"")},[f]);const b=e.attachments,y=b.some(e=>"Uploading"===e.status),v=b.some(e=>"Ready"===e.status),j=e.messagesLeftToday,_=e.profile?.limits.maxMessageLength??4e3,S=void 0!==s&&e.features.Attachments&&(e.profile?.limits.maxAttachments??0)>0,w=e.features.HumanHandoff&&("WaitingForAgent"===e.conversationState||"WithAgent"===e.conversationState),A=S&&!e.handoffPause?_jsx(IconButton,{icon:"paperclip",accessibilityLabel:t.attach,variant:"ghost",tone:"neutral",onPress:()=>{s&&s().then(t=>e.attach(t))},testID:`${i}-attach`}):void 0,C=f?_jsx(Banner,{message:t.editing,accessibilityRole:"summary",actions:[{label:t.cancel,onPress:()=>e.cancelEdit()}],testID:`${i}-editing`}):null,T=b.length>0?_jsx(View,{style:u.tray,testID:`${i}-attachments`,children:_jsx(View,{style:u.row,children:b.map(s=>_jsxs(View,{style:u.item,children:[_jsx(Chip,{label:s.fileName,variant:"soft",onRemove:()=>{e.removeAttachment(s.key)},labels:{remove:t.removeAttachment},removeTestID:`${i}-remove-${s.key}`,testID:`${i}-chip-${s.key}`}),"Uploading"===s.status?_jsx(ProgressBar,{progress:s.progress??void 0,label:t.attachmentUploading,height:4,containerStyle:u.progress}):null,"Failed"===s.status?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.error??t.attachmentFailed}):null]},s.key))})}):null,D=null!==j&&j<=10?_jsx(Text,{variant:"caption",color:0===j?"danger":"secondary",accessibilityLiveRegion:"polite",testID:`${i}-allowance`,children:t.allowance(j)}):null,L=h?_jsx(Banner,{message:h.message,tone:h.tone,dismissible:!0,onClose:()=>d(null),actions:h.openSettings?[{label:t.dictateOpenSettings,onPress:()=>{Permissions.openSettings()}}]:void 0,testID:`${i}-voice-notice`}):null,R=m.length>0,k=m.length>.9*_?_jsx(Text,{variant:"caption",color:"secondary",testID:`${i}-counter`,children:t.counter(m.length,_)}):null,I=C||T||D||k||L?_jsxs(_Fragment,{children:[C,T,D,k,L]}):void 0,P=!y&&(!!v||void 0);return _jsx(Composer,{ref:x,onSend:t=>{g.current?.(),e.submit(t)},value:m,onChangeText:t=>{g.current?.(),p(t),w&&t.length>0&&e.notifyTyping()},loading:e.streaming&&e.features.Stop,ring:l.input.ring&&(R||e.streaming),sendReveal:"Always"===l.input.sendReveal?"always":"onText",onStop:e.features.Stop?()=>e.stop():void 0,stopLabel:t.stop,disabled:0===j||e.handoffPause,maxLength:_,canSend:P,placeholder:e.handoffPause?t.handoffMoment:openQuestion(e.messages)??t.placeholder,accessibilityLabel:t.composer,labels:{send:t.send},leading:A,trailing:_jsx(ChatDictationButton,{chat:e,labels:t,disabled:0===j||e.handoffPause,onText:e=>p(t=>joinDictation(t,e,_)),onNotice:d,stopRef:g}),above:I,below:_jsx(ChatFooter,{chat:e,labels:t}),keyboardAware:o,keyboardOffset:a,safeArea:n,testID:i})}const buildStyles=e=>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";import{IconButton,Text}from"@webority/mobile-ui";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export function ChatConversationActions({chat:s,labels:t,testID:e}){const n=useTranscriptActions(s,t);return n.canShare&&s.messages.some(s=>!s.streaming)?_jsxs(_Fragment,{children:[_jsx(IconButton,{icon:"share",variant:"ghost",size:"sm",accessibilityLabel:t.shareConversation,disabled:s.streaming||s.thinking,onPress:()=>{n.shareConversation()},testID:e}),null!==n.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:n.notice}):null]}):null}
1
+ "use strict";import{messagePlainText}from"@webority/chat-core";import{IconButton,Text}from"@webority/mobile-ui";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const REPLY_AUTHORS=new Set(["Assistant","Agent","Script"]);export function ChatConversationActions({chat:s,labels:t,testID:e}){const n=useTranscriptActions(s,t),i=s.messages.some(s=>s.stored&&REPLY_AUTHORS.has(s.author.kind)&&""!==messagePlainText(s.parts));return s.streaming||s.thinking||s.loading||null===s.conversationId||!i||!n.canShare?null:_jsxs(_Fragment,{children:[_jsx(IconButton,{icon:"share",variant:"ghost",size:"sm",accessibilityLabel:t.shareConversation,onPress:()=>{n.shareConversation()},testID:e}),null!==n.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:n.notice}):null]})}
@@ -1 +1 @@
1
- "use strict";import{Logger}from"@webority/mobile-core";import{announce,IconButton}from"@webority/mobile-ui";import{useEffect,useRef,useState}from"react";import{PhoneSpeechError}from"./speech/phoneSpeech.js";import{useChatSpeech}from"./useChatSpeech.js";import{jsx as _jsx}from"react/jsx-runtime";export function ChatDictationButton({chat:e,labels:t,disabled:n=!1,onText:i,onNotice:r,testID:o="chat-dictation"}){const c=useChatSpeech(e),[a,s]=useState("idle"),u=useRef(null),l=useRef(!0);if(useEffect(()=>(l.current=!0,()=>{l.current=!1,u.current?.abort()}),[]),!e.features.Dictation||null===c)return null;const d="transcribing"===a,g="listening"===a,p=g?t.dictateStop:d?t.dictateTranscribing:t.dictate;return _jsx(IconButton,{icon:g?"stop":"microphone",accessibilityLabel:p,variant:"ghost",tone:"neutral",active:g,loading:d,disabled:n||d,onPress:()=>{if("listening"===a)return s("transcribing"),void u.current?.abort();if("idle"!==a)return;r(null);const e=new AbortController;u.current=e,s("listening"),announce(t.dictateListening);let n=!1;(async()=>{try{await c.startDictation({signal:e.signal,onText:e=>{l.current&&(n=!0,i(e))},onEnd:()=>{l.current&&s("transcribing")}}),l.current&&!n&&r({message:t.dictationNotHeard,openSettings:!1})}catch(e){if(!l.current)return;e instanceof PhoneSpeechError?r(dictationFailure(e,t)):(Logger.error("[chat] dictation failed",e),r({message:t.dictationFailed,openSettings:!1}))}finally{l.current&&(u.current=null,s("idle"))}})()},testID:o})}const dictationFailure=(e,t)=>{switch(e.phoneCode){case"MicBlocked":return{message:t.dictationBlocked,openSettings:!0};case"MicDenied":return{message:t.dictationBlocked,openSettings:!1};case"MicUnavailable":return{message:t.dictationNoMicrophone,openSettings:!1};default:return{message:t.dictationFailed,openSettings:!1}}};
1
+ "use strict";import{Logger}from"@webority/mobile-core";import{announce,IconButton}from"@webority/mobile-ui";import{useEffect,useRef,useState}from"react";import{PhoneSpeechError}from"./speech/phoneSpeech.js";import{useChatSpeech}from"./useChatSpeech.js";import{jsx as _jsx}from"react/jsx-runtime";export function ChatDictationButton({chat:e,labels:t,disabled:n=!1,onText:r,onNotice:i,testID:o="chat-dictation",stopRef:a}){const c=useChatSpeech(e),[s,u]=useState("idle"),l=useRef(null),d=useRef(!0),g=useRef(!1);if(useEffect(()=>{if(a)return a.current=()=>{null!==l.current&&(u("transcribing"),l.current.abort())},()=>{a.current=null}},[a]),useEffect(()=>(d.current=!0,()=>{d.current=!1,g.current=!0,l.current?.abort()}),[]),!e.features.Dictation||null===c)return null;const f="transcribing"===s,p="listening"===s,h=p?t.dictateStop:f?t.dictateTranscribing:t.dictate;return _jsx(IconButton,{icon:p?"stop":"microphone",accessibilityLabel:h,variant:"ghost",tone:"neutral",active:p,loading:f,disabled:n||f,onPress:()=>{if("listening"===s)return u("transcribing"),void l.current?.abort();if("idle"!==s)return;i(null),g.current=!1;const e=new AbortController;l.current=e,u("listening"),announce(t.dictateListening);let n=!1;(async()=>{try{await c.startDictation({signal:e.signal,onText:e=>{d.current&&(n=!0,r(e))},onEnd:()=>{d.current&&u("transcribing")},shouldDiscard:()=>g.current}),d.current&&!n&&i({message:t.dictationNotHeard,openSettings:!1,tone:"info"})}catch(e){if(!d.current)return;e instanceof PhoneSpeechError?i(dictationFailure(e,t)):(Logger.error("[chat] dictation failed",e),i({message:t.dictationFailed,openSettings:!1,tone:"info"}))}finally{d.current&&(l.current=null,u("idle"))}})()},testID:o})}const dictationFailure=(e,t)=>{switch(e.phoneCode){case"MicBlocked":return{message:t.dictationBlocked,openSettings:!0,tone:"danger"};case"MicDenied":return{message:t.dictationBlocked,openSettings:!1,tone:"danger"};case"MicUnavailable":return{message:t.dictationNoMicrophone,openSettings:!1,tone:"danger"};case"Unavailable":return{message:t.dictationUnavailable,openSettings:!1,tone:"info"};default:return{message:t.dictationFailed,openSettings:!1,tone:"info"}}};
@@ -1 +1 @@
1
- "use strict";import{mergeLabels}from"@webority/chat-core";import{radiusOf,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatFrame}from"./ChatFrame.js";import{jsx as _jsx}from"react/jsx-runtime";export function ChatEmbed({chat:e,labels:t,renderers:r,layoutParts:o,loader:a="Steps",motion:s="On",pickAttachments:i,onOpenAttachment:n,onOpenTarget:m,onNavigate:l,openTicket:d,handoffHosts:h,keyboardOffset:c,title:f,headerActions:b,height:u=520,testID:p="chat-embed"}){const g=useTheme();return null===e.profile||e.features.VisitorChat?_jsx(View,{style:{height:u,overflow:"hidden",borderRadius:radiusOf(g,"lg"),borderWidth:1,borderColor:g.colors["border-subtle"],backgroundColor:g.colors.bg},testID:p,children:_jsx(ChatFrame,{chat:e,labels:mergeLabels(t),renderers:r,layoutParts:o,loader:a,motion:s,pickAttachments:i,onOpenAttachment:n,onOpenTarget:m,onNavigate:l,openTicket:d,handoffHosts:h,keyboardOffset:c,layout:"embedded",title:f,headerActions:b,testID:`${p}-frame`})}):null}
1
+ "use strict";import{mergeLabels}from"@webority/chat-core";import{radiusOf,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{jsx as _jsx}from"react/jsx-runtime";const EmbedBox=({height:e,testID:t,children:r})=>{const o=useTheme();return _jsx(View,{style:{height:e,overflow:"hidden",borderRadius:radiusOf(o,"lg"),borderWidth:1,borderColor:o.colors["border-subtle"],backgroundColor:o.colors.bg},testID:t,children:r})};export function ChatEmbed({chat:e,labels:t,renderers:r,layoutParts:o,loader:a="Steps",look:s,appearance:n,pickAttachments:i,onOpenAttachment:l,onOpenTarget:c,onNavigate:h,openTicket:d,handoffHosts:m,resolveLink:p,keyboardOffset:b,title:f,headerActions:u,onClose:g,height:C=520,testID:k="chat-embed"}){return null===e.profile||e.features.VisitorChat?_jsx(ChatAppearanceScope,{appearance:n,children:_jsx(EmbedBox,{height:C,testID:k,children:_jsx(ChatFrame,{chat:e,labels:mergeLabels(t),renderers:r,layoutParts:o,loader:a,look:s,pickAttachments:i,onOpenAttachment:l,onOpenTarget:c,onNavigate:h,openTicket:d,handoffHosts:m,resolveLink:p,keyboardOffset:b,layout:"embedded",title:f,headerActions:u,onClose:g,testID:`${k}-frame`})})}):null}
@@ -1 +1 @@
1
- "use strict";import{showsCaptchaNote}from"@webority/chat-core";import{Text,useTheme}from"@webority/mobile-ui";import{Linking,View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>{Linking.openURL(e).catch(()=>{})};export function ChatFooter({chat:e,labels:i}){const o=useTheme(),t=e.profile;if(!t)return null;const n=t.footer.disclaimer??i.disclaimer,r=t.footer.privacyUrl,a=t.footer.assuranceText,c=showsCaptchaNote(t);return Boolean(n)||Boolean(r)||Boolean(a)||c?_jsxs(View,{style:{gap:o.space.xxs,alignItems:"center"},children:[n?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:n}):null,r?_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(r),children:i.footerPrivacy}):null,a?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:a}):null,c?_jsxs(Text,{variant:"caption",color:"tertiary",align:"center",children:[i.captchaNote," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:i.captchaPrivacy})," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:i.captchaTerms})]}):null]}):null}
1
+ "use strict";import{showsCaptchaNote}from"@webority/chat-core";import{Text,useTheme}from"@webority/mobile-ui";import{Linking,View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const GOOGLE_PRIVACY="https://policies.google.com/privacy",GOOGLE_TERMS="https://policies.google.com/terms",openLink=e=>{Linking.openURL(e).catch(()=>{})};export function ChatFooter({chat:e,labels:t}){const i=useTheme(),o=e.profile;if(!o)return null;const r=o.footer.disclaimer||t.disclaimer,n=o.footer.privacyUrl,a=o.footer.assuranceText,c=o.footer.privacyText,l=showsCaptchaNote(o);return Boolean(r)||Boolean(c)||Boolean(n)||Boolean(a)||l?_jsxs(View,{style:{gap:i.space.xxs,alignItems:"center"},children:[r?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:r}):null,c?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:c}):null,n?_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(n),children:t.footerPrivacy}):null,a?_jsx(Text,{variant:"caption",color:"tertiary",align:"center",children:a}):null,l?_jsxs(Text,{variant:"caption",color:"tertiary",align:"center",children:[t.captchaNote," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_PRIVACY),children:t.captchaPrivacy})," ",_jsx(Text,{variant:"caption",color:"link",accessibilityRole:"link",onPress:()=>openLink(GOOGLE_TERMS),children:t.captchaTerms})]}):null]}):null}
@@ -1 +1 @@
1
- "use strict";import{Banner,Button,Spinner,Text,useTheme}from"@webority/mobile-ui";import{useState}from"react";import{View}from"react-native";import{ChatComposer}from"./ChatComposer.js";import{ChatConversationActions}from"./ChatConversationActions.js";import{ChatHistory}from"./ChatHistory.js";import{ChatLiveBar}from"./ChatLiveBar.js";import{ChatStarters}from"./ChatStarters.js";import{ChatThread}from"./ChatThread.js";import{useChatHaptics}from"./useChatHaptics.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function ChatFrame({chat:e,labels:t,renderers:s,layoutParts:a,loader:r="Steps",motion:o="On",pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:m,handoffHosts:h,keyboardOffset:d,layout:p,title:u,headerActions:f,testID:C="chat-frame"}){const x=useTheme(),[j,b]=useState(!1);useChatHaptics(e);const y="sheet"!==p,g=null!==e.profile;if(g&&!e.features.VisitorChat)return null;const _=e.messages.length>0,v=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,I=_jsxs(View,{style:{flexDirection:"row",alignItems:"center",gap:x.space.sm,paddingHorizontal:x.space.md,paddingVertical:x.space.sm,borderBottomWidth:1,borderBottomColor:x.colors["border-subtle"]},children:[_jsxs(View,{style:{flex:1,minWidth:0},children:[_jsx(Text,{variant:"title",accessibilityRole:"header",numberOfLines:1,children:u??e.profile?.assistant.name??t.panelTitle}),_jsx(Text,{variant:"caption",color:"secondary",children:t.headerStatus})]}),f,j?null:_jsx(ChatConversationActions,{chat:e,labels:t,testID:`${C}-conversation-actions`}),v?_jsx(Button,{label:e.muted?t.unmuteSounds:t.muteSounds,variant:"link",size:"sm",accessibilityState:{checked:e.muted},onPress:()=>e.session.setMuted(!e.muted),testID:`${C}-mute`}):null,e.features.History?_jsx(Button,{label:j?t.backToChat:t.history,variant:"link",size:"sm",onPress:()=>b(e=>!e),testID:`${C}-history`}):null,j?null:_jsx(Button,{label:t.newChat,size:"sm",variant:"soft",leftIcon:"add",disabled:!_&&!e.loading,onPress:()=>e.newConversation(),testID:`${C}-new`})]});let k;return k=j?_jsx(ChatHistory,{chat:e,labels:t,onOpen:()=>b(!1),testID:`${C}-history-list`}):e.profileError?_jsx(Banner,{tone:"danger",message:e.profileError.message,accessibilityRole:"alert",testID:`${C}-profile-error`}):!g||e.loading?_jsx(View,{style:{flex:1,alignItems:"center",justifyContent:"center"},children:_jsx(Spinner,{message:t.loadingConversation,testID:`${C}-loading`})}):e.loadError?_jsx(Banner,{tone:"danger",message:e.loadError.message,accessibilityRole:"alert",testID:`${C}-load-error`}):_?_jsx(ChatThread,{chat:e,labels:t,renderers:s,layoutParts:a,loader:r,motion:o,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:m,handoffHosts:h,keyboardAware:y,keyboardOffset:d,style:{flex:1},testID:`${C}-thread`}):_jsx(ChatStarters,{chat:e,labels:t,openTicket:m,testID:`${C}-starters`}),_jsxs(View,{style:{flex:1},testID:C,children:[I,j?null:_jsx(ChatLiveBar,{chat:e,labels:t,testID:`${C}-live`}),_jsx(View,{style:{flex:1},children:k}),j?null:_jsx(ChatComposer,{chat:e,labels:t,pickAttachments:n,keyboardOffset:d,keyboardAware:y,testID:`${C}-composer`})]})}
1
+ "use strict";import{mergeLook}from"@webority/chat-core";import{Banner,IconButton,Spinner,Text,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useMemo,useRef,useState}from"react";import{View}from"react-native";import{ChatComposer}from"./ChatComposer.js";import{ChatConversationActions}from"./ChatConversationActions.js";import{ChatHistory}from"./ChatHistory.js";import{ChatLiveBar}from"./ChatLiveBar.js";import{ChatPanelGrow,ChatReveal,panelRun}from"./ChatPanel.js";import{ChatStarters}from"./ChatStarters.js";import{ChatThread}from"./ChatThread.js";import{useChatHaptics}from"./useChatHaptics.js";import{useChatSound}from"./useChatSound.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function ChatFrame({chat:e,labels:t,renderers:s,layoutParts:o,loader:r="Steps",look:a,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:h,handoffHosts:m,resolveLink:u,keyboardOffset:d,layout:p,title:f,headerActions:C,onClose:x,enterKey:j=0,testID:y="chat-frame"}){const b=useTheme(),g=useMemo(()=>mergeLook(a),[a]),v=useReducedMotion(),_="Reduced"===g.motion||v,I="embedded"===p?"None":g.panel.motion,k="sheet"===p?"sheet":"screen",w=useMemo(()=>panelRun({motion:I,reduced:_,mode:k,run:j}),[I,_,k,j]),[D,R]=useState(!1),S=D&&!0===e.features.History;useChatHaptics(e),useChatSound(e);const T="sheet"!==p,B=null!==e.profile,$=useRef(null);if(B&&!e.features.VisitorChat)return null;const L=e.messages.length>0,A=e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind),H="screen"===p||A,O=!0===e.profile?.experience.sound.muteControl&&e.features.Sounds,P=_jsxs(View,{style:{flexDirection:"row",alignItems:"center",gap:b.space.sm,paddingHorizontal:b.space.md,paddingVertical:b.space.sm,borderBottomWidth:1,borderBottomColor:b.colors["border-subtle"]},children:[_jsxs(View,{style:{flex:1,minWidth:0},children:[_jsx(Text,{variant:"title",accessibilityRole:"header",numberOfLines:1,children:f??e.profile?.assistant.name??t.panelTitle}),_jsx(Text,{variant:"caption",color:"secondary",children:t.headerStatus})]}),C,S?null:_jsx(ChatConversationActions,{chat:e,labels:t,testID:`${y}-conversation-actions`}),e.features.History?_jsx(IconButton,{icon:S?"arrow-left":"history",variant:"ghost",tone:"neutral",accessibilityLabel:S?t.backToChat:t.history,onPress:()=>R(e=>!e),testID:`${y}-history`}):null,O?_jsx(IconButton,{icon:e.muted?"volume-mute":"volume-high",variant:"ghost",tone:"neutral",accessibilityLabel:e.muted?t.unmuteSounds:t.muteSounds,onPress:()=>e.session.setMuted(!e.muted),testID:`${y}-mute`}):null,S||!H?null:_jsx(IconButton,{icon:"plus",variant:"ghost",tone:"neutral",accessibilityLabel:t.newChat,disabled:e.streaming||e.thinking,onPress:()=>e.newConversation(),testID:`${y}-new`}),x?_jsx(IconButton,{icon:"x",variant:"ghost",tone:"neutral",accessibilityLabel:t.close,onPress:x,testID:`${y}-close`}):null]});let V;return V=S?_jsx(ChatHistory,{chat:e,labels:t,onOpen:()=>R(!1),testID:`${y}-history-list`}):e.profileError?_jsx(Banner,{tone:"danger",message:e.profileError.message,accessibilityRole:"alert",testID:`${y}-profile-error`}):!B||e.loading?_jsx(View,{style:{flex:1,alignItems:"center",justifyContent:"center"},children:_jsx(Spinner,{message:t.loadingConversation,testID:`${y}-loading`})}):e.loadError?_jsx(Banner,{tone:"danger",message:e.loadError.message,accessibilityRole:"alert",testID:`${y}-load-error`}):L?_jsx(ChatThread,{chat:e,labels:t,renderers:s,layoutParts:o,loader:r,motion:g.motion,pickAttachments:n,onOpenAttachment:i,onOpenTarget:l,onNavigate:c,openTicket:h,handoffHosts:m,resolveLink:u,focusComposer:()=>$.current?.(),keyboardAware:T,keyboardOffset:d,style:{flex:1},testID:`${y}-thread`}):_jsx(ChatStarters,{chat:e,labels:t,openTicket:h,testID:`${y}-starters`}),_jsx(ChatPanelGrow,{grow:w.grow,children:_jsxs(View,{style:{flex:1},testID:y,children:[_jsx(ChatReveal,{plan:w.reveal.header,children:P}),S?null:_jsx(ChatLiveBar,{chat:e,labels:t,testID:`${y}-live`}),_jsx(ChatReveal,{plan:w.reveal.body,flex:!0,children:_jsx(View,{style:{flex:1},children:V})}),S?null:_jsx(ChatReveal,{plan:w.reveal.composer,children:_jsx(ChatComposer,{chat:e,labels:t,look:g,pickAttachments:n,keyboardOffset:d,keyboardAware:T,focusRef:$,testID:`${y}-composer`})})]})})}
@@ -1 +1 @@
1
- "use strict";import{createConversationList}from"@webority/chat-core";import{formatDate}from"@webority/mobile-core";import{Banner,Button,Card,Dialog,EmptyState,IconButton,Input,Skeleton,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useState,useSyncExternalStore}from"react";import{ScrollView,View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const TITLE_MAX_LENGTH=120,EMPTY_LIST_STATE=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),NO_SUBSCRIPTION=()=>()=>{};export function ChatHistory({chat:e,labels:t,onOpen:n,testID:l="chat-history"}){const s=useTheme(),[i,a]=useState(null),r=null!==i&&i.client===e.client?i.list:null,o=useCallback(e=>r?r.subscribe(e):NO_SUBSCRIPTION(),[r]),c=useCallback(()=>r?r.getState():EMPTY_LIST_STATE,[r]),u=useSyncExternalStore(o,c),[d,m]=useState(null),[b,p]=useState(""),[h,x]=useState(""),[g,y]=useState(null),[I,S]=useState(""),[f,_]=useState(!1);useEffect(()=>{const t=createConversationList({client:e.client});return a({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client]);const saveRename=async()=>{if(!d||!r)return;const e=b.trim();if(""!==e){_(!0),x("");try{await r.rename(d.publicId,e),m(null)}catch{x(t.renameFailed)}finally{_(!1)}}},T=!u.loading&&null===u.error&&0===u.items.length;return _jsxs(ScrollView,{contentContainerStyle:{padding:s.space.md,gap:s.space.sm,flexGrow:1},accessibilityLabel:t.history,testID:l,children:[u.error?_jsx(Banner,{tone:"danger",message:u.error.message||t.loadFailed,actions:[{label:t.retry,onPress:()=>{r?.load()}}],testID:`${l}-error`}):null,T?_jsx(EmptyState,{size:"sm",title:t.historyEmptyTitle,description:t.historyEmptyText,testID:`${l}-empty`}):null,u.items.map(i=>{const a=i.title||t.untitled;return _jsx(Card,{variant:"outline",padding:"sm",onPress:()=>(t=>{e.openConversation(t.publicId),n()})(i),accessibilityLabel:a,testID:`${l}-item-${i.publicId}`,children:_jsxs(View,{style:{flexDirection:"row",alignItems:"center",gap:s.space.sm},children:[_jsxs(View,{style:{flex:1,minWidth:0},children:[_jsx(Text,{variant:"label",numberOfLines:1,children:a}),_jsx(Text,{variant:"caption",color:"secondary",children:formatDate(i.lastActivityDateTimeUtc)})]}),e.features.Rename?_jsx(IconButton,{icon:"edit",variant:"ghost",accessibilityLabel:t.rename,onPress:()=>{x(""),p(i.title??""),m(i)},testID:`${l}-rename-${i.publicId}`}):null,e.features.Delete?_jsx(IconButton,{icon:"trash",tone:"danger",variant:"ghost",accessibilityLabel:t.deleteChat,onPress:()=>{S(""),y(i)},testID:`${l}-delete-${i.publicId}`}):null]})},i.publicId)}),u.loading&&0===u.items.length?_jsxs(View,{style:{gap:s.space.sm},accessibilityElementsHidden:!0,children:[_jsx(Skeleton,{height:56}),_jsx(Skeleton,{height:56}),_jsx(Skeleton,{height:56})]}):null,!u.loading&&u.hasMore?_jsx(Button,{label:t.loadMore,variant:"outline",onPress:()=>{r?.loadMore()},testID:`${l}-more`}):null,_jsxs(Dialog,{open:null!==d,onClose:()=>{f||m(null)},title:t.rename,dismissOnAction:!1,actions:[{label:t.cancel,tone:"neutral",disabled:f,onPress:()=>m(null)},{label:t.renameSave,disabled:""===b.trim()||f,loading:f,onPress:()=>{saveRename()}}],testID:`${l}-rename`,children:[_jsx(Input,{label:t.conversationTitle,value:b,onChangeText:p,maxLength:120,returnKeyType:"done",onSubmitEditing:()=>{saveRename()},testID:`${l}-rename-input`}),""!==h?_jsx(Text,{variant:"caption",color:"danger",testID:`${l}-rename-error`,children:h}):null]}),_jsx(Dialog,{open:null!==g,onClose:()=>{f||y(null)},tone:"warning",title:t.deleteConfirmTitle,message:I||t.deleteConfirmMessage,dismissOnAction:!1,actions:[{label:t.cancel,tone:"neutral",disabled:f,onPress:()=>y(null)},{label:t.deleteConfirm,tone:"danger",loading:f,onPress:()=>{(async()=>{if(g&&r){_(!0),S("");try{await r.remove(g.publicId),g.publicId===e.conversationId&&e.newConversation(),y(null)}catch{S(t.deleteFailed)}finally{_(!1)}}})()}}],testID:`${l}-confirm`})]})}
1
+ "use strict";import{createConversationList}from"@webority/chat-core";import{Banner,Button,EmptyState,Skeleton,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useState,useSyncExternalStore}from"react";import{ScrollView,View}from"react-native";import{ConversationRow}from"./ChatPastChats.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const EMPTY_LIST_STATE=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),NO_SUBSCRIPTION=()=>()=>{};export function ChatHistory({chat:e,labels:t,onOpen:s,testID:l="chat-history"}){const n=useTheme(),[o,i]=useState(null),r=null!==o&&o.client===e.client?o.list:null,a=useCallback(e=>r?r.subscribe(e):NO_SUBSCRIPTION(),[r]),c=useCallback(()=>r?r.getState():EMPTY_LIST_STATE,[r]),u=useSyncExternalStore(a,c);useEffect(()=>{const t=createConversationList({client:e.client});return i({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client]);const open=t=>{e.openConversation(t.publicId),s()},m=!u.loading&&null===u.error&&0===u.items.length;return _jsxs(ScrollView,{contentContainerStyle:{padding:n.space.md,gap:n.space.sm,flexGrow:1},accessibilityLabel:t.history,testID:l,children:[u.error?_jsx(Banner,{tone:"danger",message:t.loadFailed,actions:[{label:t.retry,onPress:()=>{r?.load()}}],testID:`${l}-error`}):null,m?_jsx(EmptyState,{size:"sm",title:t.historyEmptyTitle,description:t.historyEmptyText,testID:`${l}-empty`}):null,u.items.map(s=>_jsx(ConversationRow,{conversation:s,list:r,chat:e,labels:t,testID:l,onOpen:open,untitledTitle:t.untitled},s.publicId)),u.loading&&0===u.items.length?_jsxs(View,{style:{gap:n.space.sm},accessibilityElementsHidden:!0,children:[_jsx(Skeleton,{height:56}),_jsx(Skeleton,{height:56}),_jsx(Skeleton,{height:56})]}):null,!u.loading&&u.hasMore?_jsx(Button,{label:t.loadMore,variant:"outline",onPress:()=>{r?.loadMore()},testID:`${l}-more`}):null]})}
@@ -0,0 +1 @@
1
+ "use strict";import{FloatingActionButton,useTheme}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{Animated,Easing,StyleSheet}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{jsx as _jsx}from"react/jsx-runtime";const RISE_MS=900,RISE_DELAY_MS=400,ENTRANCE_MS=800,ENTRANCE_DELAY_MS=1e3,FLOAT_HALF_MS=1600,FLOAT_PX=4,RISE_FROM_PX=116;function entranceStyle(e,t){const range=(e,a)=>t.interpolate({inputRange:e,outputRange:a,extrapolate:"clamp"});switch(e){case"Rise":return{opacity:range([0,.4,1],[0,1,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[116,0]})}]};case"SlideUp":return{opacity:range([0,1],[0,1]),transform:[{translateY:t.interpolate({inputRange:[0,1],outputRange:[100,0]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[.8,1]})}]};case"BounceIn":return{transform:[{scale:range([0,.5,.7,1],[.3,1.05,.9,1])}]};case"FadeInPulse":return{opacity:range([0,.5,1],[0,1,1]),transform:[{scale:range([0,.5,1],[1,1.1,1])}]};case"SpinScale":return{transform:[{rotate:t.interpolate({inputRange:[0,1],outputRange:["-180deg","0deg"]})},{scale:t.interpolate({inputRange:[0,1],outputRange:[0,1]})}]};case"WiggleIn":return{transform:[{translateY:range([0,.4,1],[100,0,0])},{rotate:range([0,.4,.6,.8,1],["-10deg","5deg","-3deg","1deg","0deg"])}]};case"ElasticIn":return{transform:[{scale:range([0,.55,.75,1],[0,1.1,.95,1])}]};default:return{transform:[]}}}const OVERSHOOT=new Set(["Rise","SlideUp","SpinScale"]);export function ChatLauncher({look:e,label:t,side:a,offsetX:n,offsetY:s,enter:r,reduced:i,buttonRef:o,onPress:u,testID:l}){const c=useTheme(),p=useSafeAreaInsets(),m=e.launcher.entrance,[g]=useState(()=>r&&!i&&"None"!==m),f=!i&&"FloatAndPulse"===e.launcher.idle,[d]=useState(()=>new Animated.Value(g?0:1)),[S]=useState(()=>new Animated.Value(0));useEffect(()=>{if(!g)return void d.setValue(1);const e="Rise"===m,t=Animated.timing(d,{toValue:1,duration:e?900:800,delay:e?400:1e3,easing:OVERSHOOT.has(m)?Easing.bezier(.34,e?1.4:1.56,.64,1):Easing.linear,useNativeDriver:!0});return t.start(),()=>t.stop()},[g,m,d]),useEffect(()=>{if(!f)return void S.setValue(0);const e=Animated.loop(Animated.sequence([Animated.timing(S,{toValue:1,duration:1600,easing:Easing.inOut(Easing.ease),useNativeDriver:!0}),Animated.timing(S,{toValue:0,duration:1600,easing:Easing.inOut(Easing.ease),useNativeDriver:!0})]));return e.start(),()=>e.stop()},[f,S]);const R="Pill"===e.launcher.style&&!e.launcher.compact,E=c.space[c.components["floating-action-button"]["edge-offset"]]+n,A={position:"absolute",bottom:s+p.bottom,..."start"===a?{left:E}:{right:E}},h=entranceStyle(m,d);return _jsx(Animated.View,{pointerEvents:"box-none",style:StyleSheet.absoluteFill,children:_jsx(Animated.View,{style:[A,{opacity:h.opacity??1,transform:[...h.transform,{translateY:S.interpolate({inputRange:[0,1],outputRange:[0,-4]})}]}],children:_jsx(FloatingActionButton,{ref:o,icon:"messages",label:R?t:void 0,collapsed:!R,accessibilityLabel:t,onPress:u,testID:l})})})}
@@ -1 +1 @@
1
- "use strict";import{Banner,Button,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const newestAgentName=(e,t)=>{for(let n=e.messages.length-1;n>=0;n-=1){const s=e.messages[n];if("Agent"===s?.author.kind)return s.author.displayName||t}return t};export function ChatLiveBar({chat:e,labels:t,testID:n="chat-live-bar"}){const s=useTheme();if(!e.features.HumanHandoff||null===e.conversationId)return null;const a=e.conversationState;if("Closed"===a)return null;if("Open"===a)return _jsx(View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:s.space.md,paddingVertical:s.space.xs},testID:n,children:_jsx(Button,{label:t.talkToPerson,variant:"soft",size:"sm",leftIcon:"user",loading:e.handoffPending,disabled:e.streaming||e.thinking,onPress:()=>{e.requestHandoff()},testID:`${n}-talk`})});const i="Lost"===e.live,o="WaitingForAgent"===a?t.handoffWaiting:t.handoffJoined(newestAgentName(e,t.agent));return _jsxs(View,{accessibilityLiveRegion:"polite",style:{gap:s.space.xs,paddingHorizontal:s.space.md,paddingVertical:s.space.xs},testID:n,children:[_jsx(Text,{variant:"caption",color:"secondary",children:o}),i?_jsx(Banner,{tone:"warning",message:t.liveLost,actions:[{label:t.retry,onPress:()=>e.resumeLive()}],testID:`${n}-lost`}):null]})}
1
+ "use strict";import{Banner,Button,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const newestAgentName=(e,t)=>{for(let s=e.messages.length-1;s>=0;s-=1){const n=e.messages[s];if("Agent"===n?.author.kind)return n.author.displayName||t}return t};export function ChatLiveBar({chat:e,labels:t,testID:s="chat-live-bar"}){const n=useTheme();if(!e.features.HumanHandoff||null===e.conversationId)return null;const i=e.conversationState;if("Closed"===i)return null;if("Open"===i){return e.features.HumanHandoff&&e.messages.some(e=>"Visitor"===e.author.kind||"Customer"===e.author.kind)&&!e.streaming&&!e.thinking?_jsxs(View,{accessibilityLiveRegion:"polite",style:{paddingHorizontal:n.space.md,paddingVertical:n.space.xs},testID:s,children:[_jsx(Button,{label:t.talkToPerson,variant:"soft",size:"sm",leftIcon:"user",loading:e.handoffPending,onPress:()=>{e.requestHandoff()},testID:`${s}-talk`}),null!==e.handoffError?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:t.errorGeneric}):null]}):null}const a="Lost"===e.live,r="WaitingForAgent"===i?t.statusWaitingForAgent:t.statusWithAgent(newestAgentName(e,t.agent));return _jsxs(View,{accessibilityLiveRegion:"polite",style:{gap:n.space.xs,paddingHorizontal:n.space.md,paddingVertical:n.space.xs},testID:s,children:[_jsx(Text,{variant:"caption",color:"secondary",children:r}),a?_jsx(Banner,{tone:"warning",message:t.liveLost,actions:[{label:t.retry,onPress:()=>e.resumeLive()}],testID:`${s}-lost`}):null]})}
@@ -1 +1 @@
1
- "use strict";import{buildTranscript,messagePlainText}from"@webority/chat-core";import{copyText}from"@webority/mobile-core/clipboard";import{Button,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{ReadAloudButton}from"./ReadAloudButton.js";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);export function ChatMessageActions({chat:e,message:t,labels:s,isLast:a,isLastVisitor:i,testID:r}){const n=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),d=useRef(null),m=useTranscriptActions(e,s),p=useMemo(()=>TEXT_AUTHORS.has(t.author.kind)&&buildTranscript([t],{labels:s,title:null,figureText:!1}).entries.length>0,[t,s]);if(useEffect(()=>()=>{null!==d.current&&clearTimeout(d.current)},[]),t.streaming)return null;const g=t.parts.filter(e=>"Text"===e.kind).map(e=>e.text).join("\n\n"),f=TEXT_AUTHORS.has(t.author.kind)&&""!==g,h=t.stored&&RATED_AUTHORS.has(t.author.kind),T=("Assistant"===t.author.kind||"Agent"===t.author.kind)&&""!==messagePlainText(t.parts).trim(),x=a&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),b=i&&t.stored&&e.features.Edit,save=async s=>{u("idle");try{await e.rate(t.id,s),u("saved")}catch{u("failed")}};return f&&e.features.Copy||p&&e.features.Share&&m.canShare||T||x||b||h&&e.features.Rating?_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:n.space.xs},testID:r,children:[f&&e.features.Copy?_jsx(Button,{label:o?s.copied:s.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await copyText(g)&&(l(!0),null!==d.current&&clearTimeout(d.current),d.current=setTimeout(()=>l(!1),2e3))})()},testID:`${r}-copy`}):null,p&&e.features.Share&&m.canShare?_jsx(Button,{label:s.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{m.shareReply(t)},testID:`${r}-share`}):null,T?_jsx(ReadAloudButton,{chat:e,message:t,labels:s}):null,x?_jsx(Button,{label:s.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${r}-regenerate`}):null,b?_jsx(Button,{label:s.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${r}-edit`}):null,h&&e.features.Rating?_jsxs(_Fragment,{children:[_jsx(Button,{label:s.rateUp,size:"sm",leftIcon:"like",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{selected:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${r}-rate-up`}),_jsx(Button,{label:s.rateDown,size:"sm",leftIcon:"dislike",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{selected:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${r}-rate-down`}),"failed"===c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.ratingFailed}):null,"saved"===c?_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:s.rated}):null]}):null,null!==m.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:m.notice}):null]}):null}
1
+ "use strict";import{buildTranscript,messagePlainText}from"@webority/chat-core";import{copyText}from"@webority/mobile-core/clipboard";import{Button,IconButton,Text,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{View}from"react-native";import{ReadAloudButton}from"./ReadAloudButton.js";import useTranscriptActions from"./useTranscriptActions.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const TEXT_AUTHORS=new Set(["Assistant","Agent","Script"]),RATED_AUTHORS=new Set(["Assistant","Agent"]);export function ChatMessageActions({chat:e,message:t,labels:s,isLast:i,isLastVisitor:a,testID:n}){const r=useTheme(),[o,l]=useState(!1),[c,u]=useState("idle"),m=useRef(null),d=useTranscriptActions(e,s),g=useMemo(()=>TEXT_AUTHORS.has(t.author.kind)&&buildTranscript([t],{labels:s,title:null,figureText:!1}).entries.length>0,[t,s]);if(useEffect(()=>()=>{null!==m.current&&clearTimeout(m.current)},[]),t.streaming)return null;const p=messagePlainText(t.parts),h=TEXT_AUTHORS.has(t.author.kind)&&""!==p,x=t.stored&&RATED_AUTHORS.has(t.author.kind),f=("Assistant"===t.author.kind||"Agent"===t.author.kind||"Script"===t.author.kind)&&""!==messagePlainText(t.parts).trim(),T=i&&"Assistant"===t.author.kind&&!e.streaming&&!e.thinking&&e.features.Regenerate&&e.messages.some(e=>e.stored&&"Visitor"===e.author.kind),b=a&&t.stored&&e.features.Edit&&!e.streaming&&!e.thinking,save=async s=>{try{await e.rate(t.id,s),u("saved")}catch{u("failed")}};return h&&e.features.Copy||g&&e.features.Share&&d.canShare||f||T||b||x&&e.features.Rating?_jsxs(View,{style:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",gap:r.space.xs},testID:n,children:[h&&e.features.Copy?_jsx(Button,{label:o?s.copied:s.copy,variant:"link",size:"sm",onPress:()=>{(async()=>{await copyText(p)&&(l(!0),null!==m.current&&clearTimeout(m.current),m.current=setTimeout(()=>l(!1),2e3))})()},testID:`${n}-copy`}):null,g&&e.features.Share&&d.canShare?_jsx(Button,{label:s.share,variant:"link",size:"sm",leftIcon:"share",disabled:e.streaming||e.thinking,onPress:()=>{d.shareReply(t)},testID:`${n}-share`}):null,f?_jsx(ReadAloudButton,{chat:e,message:t,labels:s}):null,T?_jsx(Button,{label:s.regenerate,variant:"link",size:"sm",onPress:()=>{e.regenerate()},testID:`${n}-regenerate`}):null,b?_jsx(Button,{label:s.edit,variant:"link",size:"sm",onPress:()=>e.startEdit(t.id),testID:`${n}-edit`}):null,x&&e.features.Rating?_jsxs(_Fragment,{children:[_jsxs(View,{accessibilityRole:"summary",accessibilityLabel:s.rating,style:{flexDirection:"row",alignItems:"center",gap:r.space.xs},children:[_jsx(IconButton,{icon:"like",accessibilityLabel:s.rateUp,tone:"neutral",size:"sm",variant:"Up"===t.rating?"soft":"ghost",accessibilityState:{checked:"Up"===t.rating},onPress:()=>{save("Up")},testID:`${n}-rate-up`}),_jsx(IconButton,{icon:"dislike",accessibilityLabel:s.rateDown,tone:"neutral",size:"sm",variant:"Down"===t.rating?"soft":"ghost",accessibilityState:{checked:"Down"===t.rating},onPress:()=>{save("Down")},testID:`${n}-rate-down`})]}),"failed"===c?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:s.ratingFailed}):null,"saved"===c?_jsx(Text,{variant:"caption",color:"secondary",accessibilityLiveRegion:"polite",children:s.rated}):null]}):null,null!==d.notice?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",children:d.notice}):null]}):null}
@@ -1 +1 @@
1
- "use strict";import{resolveNudge}from"@webority/chat-core";import{Banner}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{View}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";const LAUNCHER_CLEARANCE=72,EDGE_INSET=16;export function ChatNudge({chat:e,labels:t,enabled:o,onActivate:r,bottomOffset:s,position:i,testID:n="chat-nudge"}){const a=e.profile,u=e.features,l=a?resolveNudge(a,u):null,[c,m]=useState(!1),[f,b]=useState(!1);if(useEffect(()=>{if(!o||!l||c)return void b(!1);const e=setTimeout(()=>b(!0),1e3*l.delaySeconds);return()=>clearTimeout(e)},[o,l,c]),!l||!f||c)return null;return _jsx(View,{style:{position:"absolute",bottom:s+72,..."start"===i?{left:16}:{right:16},maxWidth:320},pointerEvents:"box-none",children:_jsx(Banner,{tone:"info",message:l.text,dismissible:!0,onClose:()=>m(!0),actions:[{label:t.launcher,onPress:r}],testID:n})})}
1
+ "use strict";import{resolveNudge}from"@webority/chat-core";import{Banner}from"@webority/mobile-ui";import{useEffect,useState}from"react";import{View}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";const LAUNCHER_CLEARANCE=72,EDGE_INSET=16;export function ChatNudge({chat:e,labels:t,enabled:s,onActivate:o,bottomOffset:r,position:i,testID:n="chat-nudge"}){const a=e.profile,u=e.features,l=a?resolveNudge(a,u):null,[m,c]=useState(!1),[f,d]=useState(!1),[b,p]=useState(!1);if(useEffect(()=>{if(!s||!l||m)return void d(!1);if(b)return;const e=setTimeout(()=>{d(!0),p(!0)},1e3*l.delaySeconds);return()=>clearTimeout(e)},[s,l,m,b]),!l||!f||m)return null;return _jsx(View,{style:{position:"absolute",bottom:r+72,..."start"===i?{left:16}:{right:16},maxWidth:320},pointerEvents:"box-none",children:_jsx(Banner,{tone:"info",message:l.text,dismissible:!0,onClose:()=>c(!0),labels:{dismiss:t.nudgeDismiss},actions:[{label:t.launcher,onPress:o}],testID:n})})}
@@ -1 +1 @@
1
- "use strict";import{Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SHOWN_AT_MOST=3;export function ChatOpenTickets({chat:e,labels:t,onOpenTicket:s,testID:i="chat-open-tickets"}){const n=useTheme();return e.features.OpenTickets&&0!==e.openTickets.length?_jsxs(View,{accessibilityRole:"list",accessibilityLabel:t.openTickets,style:{gap:n.space.xs},testID:i,children:[_jsx(Text,{variant:"caption",color:"secondary",children:t.openTickets}),e.openTickets.slice(0,3).map(e=>{const n=s?()=>s({ticketId:e.ticketId,number:e.number}):void 0;return _jsxs(Card,{variant:"outline",padding:"sm",interactive:void 0!==n,onPress:n,testID:`${i}-${e.ticketId}`,children:[_jsx(Text,{variant:"label",children:t.ticketAria(e.number)}),_jsx(Text,{variant:"bodySmall",numberOfLines:1,children:e.subject}),_jsx(Chip,{size:"sm",variant:"soft",label:e.status})]},e.ticketId)})]}):null}
1
+ "use strict";import{Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SHOWN_AT_MOST=3;export function ChatOpenTickets({chat:e,labels:t,onOpenTicket:s,testID:i="chat-open-tickets"}){const n=useTheme();return e.features.OpenTickets&&0!==e.openTickets.length?_jsx(View,{accessibilityLabel:t.openTickets,style:{gap:n.space.xs},testID:i,children:e.openTickets.slice(0,3).map(e=>{const n=s?()=>s({ticketId:e.ticketId,number:e.number}):void 0;return _jsxs(Card,{variant:"outline",padding:"sm",interactive:void 0!==n,onPress:n,testID:`${i}-${e.ticketId}`,children:[_jsx(Text,{variant:"label",children:t.ticketAria(e.number)}),_jsx(Text,{variant:"bodySmall",numberOfLines:1,children:e.subject}),_jsx(Chip,{size:"sm",variant:"soft",label:t.ticketStatus(e.status)||e.status})]},e.ticketId)})}):null}
@@ -0,0 +1 @@
1
+ "use strict";import{useEffect,useState}from"react";import{Animated}from"react-native";import{jsx as _jsx}from"react/jsx-runtime";const SPRING_DELAY={header:110,body:160,composer:240},revealFor=(e,t,n,r)=>n?null:"Spring"===e?{run:r,delay:SPRING_DELAY[t],duration:260,distance:10}:"Gentle"===e?{run:r,delay:0,duration:250,distance:12}:null;export const panelRun=e=>{const{motion:t,reduced:n,mode:r,run:a}=e;return{grow:"Spring"!==t||n||"screen"!==r?null:{run:a},reveal:{header:revealFor(t,"header",n,a),body:revealFor(t,"body",n,a),composer:revealFor(t,"composer",n,a)}}};const SPRING={stiffness:200,damping:22.4,mass:1,useNativeDriver:!0};export function ChatReveal({plan:e,flex:t=!1,children:n}){const[r]=useState(()=>new Animated.Value(null===e?1:0));useEffect(()=>{if(null===e)return void r.setValue(1);r.setValue(0);const t=Animated.timing(r,{toValue:1,duration:e.duration,delay:e.delay,useNativeDriver:!0});return t.start(),()=>t.stop()},[e,r]);const a=e?.distance??0;return _jsx(Animated.View,{style:{flex:t?1:void 0,opacity:r,transform:[{translateY:r.interpolate({inputRange:[0,1],outputRange:[a,0]})}]},children:n})}export function ChatPanelGrow({grow:e,children:t}){const[n]=useState(()=>new Animated.Value(null===e?1:0)),[r,a]=useState({width:0,height:0});useEffect(()=>{if(null===e)return void n.setValue(1);n.setValue(0);const t=Animated.spring(n,{toValue:1,...SPRING});return t.start(),()=>t.stop()},[e,n]);const o=[{translateY:n.interpolate({inputRange:[0,1],outputRange:[r.height,0]})}];return _jsx(Animated.View,{onLayout:e=>{const{width:t,height:n}=e.nativeEvent.layout;a(e=>e.width===t&&e.height===n?e:{width:t,height:n})},style:{flex:1,transform:o},children:t})}
@@ -0,0 +1 @@
1
+ "use strict";import{createConversationList,formatChatDate}from"@webority/chat-core";import{Button,Card,IconButton,Input,Text,useTheme}from"@webority/mobile-ui";import{useCallback,useEffect,useState,useSyncExternalStore}from"react";import{View}from"react-native";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const PAGE_SIZE=20,EMPTY_LIST_STATE=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),NO_SUBSCRIPTION=()=>()=>{};export function ChatPastChats({chat:e,labels:t,testID:n="chat-past-chats"}){const s=useTheme(),a=!0===e.features.History,[i,l]=useState(null),r=a&&null!==i&&i.client===e.client?i.list:null,o=useCallback(e=>r?r.subscribe(e):NO_SUBSCRIPTION(),[r]),c=useCallback(()=>r?r.getState():EMPTY_LIST_STATE,[r]),d=useSyncExternalStore(o,c);if(useEffect(()=>{if(!a)return;const t=createConversationList({client:e.client});return l({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client,a]),!a||0===d.items.length)return null;const open=t=>{e.openConversation(t.publicId)};return _jsx(View,{style:{gap:s.space.sm},testID:n,children:d.items.slice(0,20).map(s=>_jsx(ConversationRow,{conversation:s,list:r,chat:e,labels:t,testID:n,onOpen:open},s.publicId))})}export function ConversationRow({conversation:e,list:t,chat:n,labels:s,testID:a,onOpen:i,untitledTitle:l}){const r=useTheme(),[o,c]=useState("idle"),[d,u]=useState(""),[m,x]=useState(""),[h,p]=useState(!1),b=e.publicId,f=e.title||l||s.earlierChat,g=formatChatDate(e.lastActivityDateTimeUtc),cancel=()=>{x(""),c("idle")},saveRename=async()=>{const e=d.trim();if(!h&&t&&""!==e){p(!0),x("");try{await t.rename(b,e),c("idle")}catch{x(s.renameFailed)}finally{p(!1)}}};return _jsxs(Card,{variant:"outline",padding:"sm",onPress:"idle"===o?()=>i(e):void 0,accessibilityLabel:`${f}, ${g}`,testID:`${a}-item-${b}`,children:["idle"===o?_jsxs(View,{style:{flexDirection:"row",alignItems:"center",gap:r.space.sm},children:[_jsxs(View,{style:{flex:1,minWidth:0},children:[_jsx(Text,{variant:"label",numberOfLines:1,children:f}),_jsx(Text,{variant:"caption",color:"secondary",children:g})]}),n.features.Rename?_jsx(IconButton,{icon:"edit",variant:"ghost",accessibilityLabel:s.rename,onPress:()=>{x(""),u(e.title??""),c("renaming")},testID:`${a}-rename-${b}`}):null,n.features.Delete?_jsx(IconButton,{icon:"trash",tone:"danger",variant:"ghost",accessibilityLabel:s.deleteChat,onPress:()=>{x(""),c("deleting")},testID:`${a}-delete-${b}`}):null]}):null,"renaming"===o?_jsxs(View,{style:{gap:r.space.sm},children:[_jsx(Input,{label:s.conversationTitle,value:d,onChangeText:u,maxLength:120,returnKeyType:"done",onSubmitEditing:()=>{saveRename()},testID:`${a}-rename-input-${b}`}),""!==m?_jsx(Text,{variant:"caption",color:"danger",accessibilityLiveRegion:"polite",testID:`${a}-rename-error-${b}`,children:m}):null,_jsxs(View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[_jsx(Button,{label:s.cancel,variant:"ghost",disabled:h,onPress:cancel,testID:`${a}-rename-cancel-${b}`}),_jsx(Button,{label:s.renameSave,disabled:""===d.trim()||h,loading:h,onPress:()=>{saveRename()},testID:`${a}-rename-save-${b}`})]})]}):null,"deleting"===o?_jsxs(View,{style:{gap:r.space.sm},children:[_jsx(Text,{variant:"bodySmall",color:""!==m?"danger":"secondary",accessibilityLiveRegion:""!==m?"polite":void 0,testID:`${a}-delete-message-${b}`,children:""!==m?m:s.deleteConfirmMessage}),_jsxs(View,{style:{flexDirection:"row",justifyContent:"flex-end",gap:r.space.sm},children:[_jsx(Button,{label:s.cancel,variant:"ghost",disabled:h,onPress:cancel,testID:`${a}-delete-cancel-${b}`}),_jsx(Button,{label:s.deleteConfirm,tone:"danger",loading:h,onPress:()=>{(async()=>{if(!h&&t){p(!0),x("");try{await t.remove(b),b===n.conversationId&&n.newConversation(),c("idle")}catch{x(s.deleteFailed)}finally{p(!1)}}})()},testID:`${a}-delete-confirm-${b}`})]})]}):null]})}
@@ -1 +1 @@
1
- "use strict";import{mergeLabels}from"@webority/chat-core";import{useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatFrame}from"./ChatFrame.js";import{jsx as _jsx}from"react/jsx-runtime";export function ChatScreen({chat:e,labels:t,renderers:r,layoutParts:o,loader:a="Steps",motion:s="On",pickAttachments:n,onOpenAttachment:i,onOpenTarget:c,onNavigate:m,openTicket:l,handoffHosts:h,keyboardOffset:f,title:p,headerActions:u,testID:d="chat-screen"}){const b=useTheme();return null===e.profile||e.features.VisitorChat?_jsx(View,{style:{flex:1,backgroundColor:b.colors.bg},testID:d,children:_jsx(ChatFrame,{chat:e,labels:mergeLabels(t),renderers:r,layoutParts:o,loader:a,motion:s,pickAttachments:n,onOpenAttachment:i,onOpenTarget:c,onNavigate:m,openTicket:l,handoffHosts:h,keyboardOffset:f,layout:"screen",title:p,headerActions:u,testID:`${d}-frame`})}):null}
1
+ "use strict";import{mergeLabels}from"@webority/chat-core";import{useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{jsx as _jsx}from"react/jsx-runtime";export function ChatScreen({chat:e,labels:t,renderers:r,layoutParts:a,loader:o="Steps",look:s,appearance:n,pickAttachments:c,onOpenAttachment:i,onOpenTarget:l,onNavigate:p,openTicket:m,handoffHosts:h,resolveLink:f,keyboardOffset:u,title:d,headerActions:b,onClose:k,testID:C="chat-screen"}){const A=useTheme();return null===e.profile||e.features.VisitorChat?_jsx(View,{style:{flex:1,backgroundColor:A.colors.bg},testID:C,children:_jsx(ChatAppearanceScope,{appearance:n,children:_jsx(ChatFrame,{chat:e,labels:mergeLabels(t),renderers:r,layoutParts:a,loader:o,look:s,pickAttachments:c,onOpenAttachment:i,onOpenTarget:l,onNavigate:p,openTicket:m,handoffHosts:h,resolveLink:f,keyboardOffset:u,layout:"screen",title:d,headerActions:b,onClose:k,testID:`${C}-frame`})})}):null}
@@ -1 +1 @@
1
- "use strict";import{mergeLabels,messagePlainText}from"@webority/chat-core";import{BottomSheet,FloatingActionButton,useTheme}from"@webority/mobile-ui";import{useEffect,useRef}from"react";import{AccessibilityInfo,findNodeHandle,View}from"react-native";import{ChatFrame}from"./ChatFrame.js";import{ChatNudge}from"./ChatNudge.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"];export function ChatSheet({chat:e,labels:t,renderers:s,layoutParts:o,loader:n="Steps",motion:i="On",pickAttachments:a,onOpenAttachment:r,onOpenTarget:l,onNavigate:c,keyboardOffset:u,open:f,defaultOpen:m=!1,onOpenChange:p,position:h="end",bottomOffset:d=16,snapPoints:b=DEFAULT_SNAP_POINTS,compact:g=!1,openTicket:y,handoffHosts:A,conversationId:x,testID:O="chat-sheet"}){const T=useTheme(),j=mergeLabels(t),C=void 0!==f,P=C?f:e.open,I=useRef(null),N=useRef(null),_=useRef(!1),k=useRef(x??null),E=e.setChatVisible;useEffect(()=>{_.current||(_.current=!0,C||!m||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[C,m,e.profile,e.open,e.session]),useEffect(()=>{C&&(f&&!e.open&&e.session.open({trigger:"manual"}),!f&&e.open&&e.session.close("button"))},[C,f,e.open,e.session]);const F=useRef(P);if(useEffect(()=>{if(F.current&&!P){const e=findNodeHandle(I.current);null!==e&&AccessibilityInfo.setAccessibilityFocus(e)}F.current=P},[P]),useEffect(()=>{E(P)},[E,P]),useEffect(()=>{!C&&x&&x!==k.current&&null!==e.profile&&(k.current=x,e.open||(e.session.open({trigger:"manual"}),p?.(!0)))},[C,x,e.profile,e.open,e.session,p]),useEffect(()=>{if(null!==N.current){if(P)for(const t of e.messages){if("Assistant"!==t.author.kind||t.streaming||N.current.has(t.id))continue;N.current.add(t.id);const e=messagePlainText(t.parts);""!==e&&AccessibilityInfo.announceForAccessibility(e)}}else N.current=new Set(e.messages.map(e=>e.id))},[e.messages,P]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),p?.(t)},S="start"===h?"bottomLeft":"bottomRight";return _jsxs(View,{testID:O,children:[P?null:_jsx(FloatingActionButton,{ref:I,icon:"messages",label:g?void 0:j.launcher,position:S,bottomOffset:d,accessibilityLabel:j.launcher,onPress:()=>setOpen(!0),testID:`${O}-launcher`}),_jsx(ChatNudge,{chat:e,labels:j,enabled:!P&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:d,position:h,testID:`${O}-nudge`}),_jsx(BottomSheet,{open:P,onClose:()=>setOpen(!1),snapPoints:b,keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:j.panelTitle,children:_jsx(View,{style:{flex:1,backgroundColor:T.colors.bg},children:_jsx(ChatFrame,{chat:e,labels:j,renderers:s,layoutParts:o,loader:n,motion:i,pickAttachments:a,onOpenAttachment:r,onOpenTarget:l,onNavigate:c,openTicket:y,handoffHosts:A,keyboardOffset:u,layout:"sheet",testID:`${O}-frame`})})})]})}
1
+ "use strict";import{mergeLabels,mergeLook}from"@webority/chat-core";import{BottomSheet,useReducedMotion,useTheme}from"@webority/mobile-ui";import{useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{ChatAppearanceScope}from"./ChatAppearanceScope.js";import{ChatFrame}from"./ChatFrame.js";import{ChatLauncher}from"./ChatLauncher.js";import{ChatNudge}from"./ChatNudge.js";import{focusForAccessibility}from"./chatShared.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_SNAP_POINTS=["92%"],DEFAULT_BOTTOM_OFFSET=16;export function ChatSheet({chat:e,labels:t,renderers:o,layoutParts:s,loader:n="Steps",look:r,appearance:a,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,keyboardOffset:f,open:p,defaultOpen:h=!1,onOpenChange:m,snapPoints:d=DEFAULT_SNAP_POINTS,openTicket:b,handoffHosts:g,resolveLink:C,conversationId:S,onClose:j,testID:y="chat-sheet"}){const k=useTheme(),T=mergeLabels(t),x=useMemo(()=>mergeLook(r),[r]),A=useReducedMotion(),_="Reduced"===x.motion||A,O=a?.position??"end",E=void 0!==p,L=E?p:e.open,F=useRef(null),P=useRef(!1),R=useRef(S??null),v=e.setChatVisible,N=useRef(!1),D=!N.current,[I,w]=useState(0),M=useRef(L);useEffect(()=>{L&&(N.current=!0)},[L]),useEffect(()=>{L&&!M.current&&w(e=>e+1),M.current=L},[L]),useEffect(()=>{P.current||(P.current=!0,E||!h||null===e.profile||e.open||e.session.open({trigger:"manual"}))},[E,h,e.profile,e.open,e.session]),useEffect(()=>{E&&(p&&!e.open&&e.session.open({trigger:"manual"}),!p&&e.open&&e.session.close("button"))},[E,p,e.open,e.session]);const V=useRef(L);if(useEffect(()=>{V.current&&!L&&focusForAccessibility(F.current),V.current=L},[L]),useEffect(()=>{v(L)},[v,L]),useEffect(()=>{!E&&S&&S!==R.current&&null!==e.profile&&(R.current=S,e.open||(e.session.open({trigger:"manual"}),m?.(!0)))},[E,S,e.profile,e.open,e.session,m]),null===e.profile||!e.features.VisitorChat)return null;const setOpen=t=>{t?e.session.open({trigger:"manual"}):e.session.close("button"),m?.(t)},closeSheet=()=>{setOpen(!1),j?.()},B=a?.offsetY??16;return _jsx(View,{testID:y,style:StyleSheet.absoluteFill,pointerEvents:"box-none",children:_jsxs(ChatAppearanceScope,{appearance:a,children:[L?null:_jsx(ChatLauncher,{look:x,label:T.launcher,side:O,offsetX:a?.offsetX??0,offsetY:B,enter:D,reduced:_,buttonRef:F,onPress:()=>setOpen(!0),testID:`${y}-launcher`}),_jsx(ChatNudge,{chat:e,labels:T,enabled:!L&&e.features.Nudges,onActivate:()=>setOpen(!0),bottomOffset:B,position:O,testID:`${y}-nudge`}),_jsx(BottomSheet,{open:L,onClose:closeSheet,snapPoints:d,keyboardBehavior:"shift",scrollable:!1,enablePanDownToClose:!0,enableBackdropPress:!0,accessibilityViewIsModal:!0,accessibilityLabel:T.panelTitle,children:_jsx(View,{style:{flex:1,backgroundColor:k.colors.bg},children:_jsx(ChatFrame,{chat:e,labels:T,renderers:o,layoutParts:s,loader:n,look:r,pickAttachments:i,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,openTicket:b,handoffHosts:g,resolveLink:C,keyboardOffset:f,onClose:closeSheet,layout:"sheet",enterKey:I,testID:`${y}-frame`})})})]})})}
@@ -1 +1 @@
1
- "use strict";import{resolveStart}from"@webority/chat-core";import{formatDate}from"@webority/mobile-core";import{Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{useMemo}from"react";import{View}from"react-native";import{ChatOpenTickets}from"./ChatOpenTickets.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function ChatStarters({chat:e,labels:t,openTicket:s,testID:r="chat-starters"}){const a=useTheme(),i=e.profile,n=null!==e.lastConversation,l=useMemo(()=>i?resolveStart(i,{pathname:i.screen??"/",returning:n}).greeting:"",[i,n]);if(!i)return null;const o=e.features.Starters&&e.features.BehaviourStarters&&e.starters.length>0,c=e.lastConversation,m=e.features.ResumeLast&&null!==c;return _jsxs(View,{style:{flex:1,justifyContent:"center",alignItems:"center",gap:a.space.md,padding:a.space.md},testID:r,children:[_jsx(Text,{variant:"h2",align:"center",children:l}),o?_jsx(View,{accessibilityRole:"none",accessibilityLabel:t.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:a.space.xs},children:e.starters.map(s=>_jsx(Chip,{label:s.label,onPress:()=>{e.submit(s.message)},accessibilityLabel:`${t.starters}: ${s.label}`,testID:`${r}-${s.id}`},s.id))}):null,m&&c?_jsxs(Card,{variant:"outline",padding:"sm",onPress:()=>{e.resumeLast()},testID:`${r}-resume`,children:[_jsx(Text,{variant:"caption",color:"secondary",children:t.resumeLast}),_jsx(Text,{variant:"label",numberOfLines:1,children:c.title||t.untitled}),_jsx(Text,{variant:"caption",color:"secondary",children:formatDate(c.lastActivityDateTimeUtc)})]}):null,_jsx(ChatOpenTickets,{chat:e,labels:t,onOpenTicket:s})]})}
1
+ "use strict";import{formatDate}from"@webority/mobile-core";import{Card,Chip,Text,useTheme}from"@webority/mobile-ui";import{View}from"react-native";import{ChatEntrance}from"./ChatEntrance.js";import{ChatOpenTickets}from"./ChatOpenTickets.js";import{ChatPastChats}from"./ChatPastChats.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export function ChatStarters({chat:t,labels:e,openTicket:s,testID:a="chat-starters"}){const r=useTheme(),i=t.profile,n=t.greeting??"";if(!i)return null;const l=t.features.Starters&&t.starters.length>0,c=t.lastConversation,o=t.features.ResumeLast&&!t.features.History&&null!==c;return _jsxs(View,{accessibilityLabel:e.emptyTitle,style:{flex:1,justifyContent:"center",alignItems:"center",gap:r.space.md,padding:r.space.md},testID:a,children:[_jsx(Text,{variant:"h2",align:"center",children:n}),l?_jsx(View,{accessibilityRole:"none",accessibilityLabel:e.starters,style:{flexDirection:"row",flexWrap:"wrap",justifyContent:"center",gap:r.space.xs},children:t.starters.map((e,s)=>_jsx(ChatEntrance,{index:s,children:_jsx(Chip,{label:e.label,leftIcon:e.icon?e.icon:void 0,onPress:()=>{t.submit(e.message)},testID:`${a}-${e.id}`})},e.id))}):null,o&&c?_jsxs(Card,{variant:"outline",padding:"sm",onPress:()=>{t.resumeLast()},testID:`${a}-resume`,children:[_jsx(Text,{variant:"caption",color:"secondary",children:e.resumeLast}),_jsx(Text,{variant:"label",numberOfLines:1,children:c.title||e.untitled}),_jsx(Text,{variant:"caption",color:"secondary",children:formatDate(c.lastActivityDateTimeUtc)})]}):null,t.features.History?_jsx(ChatPastChats,{chat:t,labels:e,testID:`${a}-past-chats`}):null,_jsx(ChatOpenTickets,{chat:t,labels:e,onOpenTicket:s})]})}