@webority/chat-react 0.124.0 → 0.125.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chat-react.js +10 -4
- package/dist/guidance.json +1 -1
- package/dist/types/components/ActionCard.d.ts +4 -4
- package/dist/types/components/ChatComposer.d.ts +4 -4
- package/dist/types/components/ChatConversationList.d.ts +6 -6
- package/dist/types/components/ChatLauncher.d.ts +2 -2
- package/dist/types/components/ChatMessage.d.ts +6 -6
- package/dist/types/components/ChatPanel.d.ts +2 -2
- package/dist/types/components/ChatThread.d.ts +2 -2
- package/dist/types/components/ComposerAttachments.d.ts +4 -4
- package/dist/types/components/ConfirmCard.d.ts +2 -2
- package/dist/types/components/ReplyRating.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/useChat.d.ts +14 -14
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ onto the fetch adapter still works, but the reply then appears whole at the end.
|
|
|
74
74
|
|
|
75
75
|
The client, the stream reader, the conversation rules and the server contract (the routes, the
|
|
76
76
|
request bodies, the events and the error codes) live in
|
|
77
|
-
[`@webority/
|
|
77
|
+
[`@webority/markdown-core/chat`](https://www.npmjs.com/package/@webority/markdown-core/chat). This package draws the
|
|
78
78
|
assistant on top of it and re-exports its names, so a product imports every chat name from
|
|
79
79
|
`@webority/chat-react`. That includes `CHAT_CONTRACT_VERSION`, `createChatClient`,
|
|
80
80
|
`createConversationList`, `DEFAULT_CHAT_LABELS` and `mergeLabels` from the engine, and
|
package/dist/chat-react.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{AppActionIcon as e,AppAlert as t,AppButton as n,AppCard as r,AppChip as i,AppChipGroup as a,AppConfirmDialog as o,AppCopyButton as s,AppDrawer as c,AppEmptyState as l,AppIcon as u,AppInput as d,AppMarkdown as f,AppProgress as p,AppSkeleton as m,AppSpinner as h,AppTextarea as g,useFloatingStack as _}from"@webority/ui-react";import{memo as v,useEffect as y,useId as b,useMemo as x,useRef as S,useState as C,useSyncExternalStore as w}from"react";import{Fragment as T,jsx as E,jsxs as D}from"react/jsx-runtime";import{formatDateTime as O}from"@webority/ui-elements/helpers";import{createPortal as k}from"react-dom";var A=/\[([^[\]\n]+)\](?!\()/g;function j(e,t){let n=[],r=0;A.lastIndex=0;for(let i of e.matchAll(A)){let a=i[1];t(a)&&(i.index>r&&n.push({text:e.slice(r,i.index)}),n.push({citation:a}),r=i.index+i[0].length)}return r<e.length&&n.push({text:e.slice(r)}),n}var M=/* @__PURE__ */ new Set(`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`),N=/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,P=/!\[([^\]\n]*)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,F=new RegExp(A.source,`y`),I=e=>/[\p{L}\p{N}]/u.test(e);function L(e,t){let n=0;for(let r=t-1;r>=0&&e.charAt(r)===`\\`;--r)n+=1;return n%2==1}function R(e,t,n){let r=n.length===1;for(let i=e.indexOf(n,t);i!==-1;i=e.indexOf(n,i+1)){let a=i>t&&!/\s/.test(e.charAt(t))&&!/\s/.test(e.charAt(i-1)),o=r&&(e.charAt(i+1)===n||e.charAt(i-1)===n),s=n===`_`&&I(e.charAt(i+n.length));if(a&&!o&&!s&&!L(e,i))return i}return-1}function z(e,t){let n=t?.isCitation,r=[],i=``,a=()=>{i&&=(r.push({type:`text`,text:i}),``)},o=0;for(;o<e.length;){let s=e.charAt(o),c=e.charAt(o+1);if(s===`\\`&&M.has(c)){i+=c,o+=2;continue}if(s==="`"){let t=e.indexOf("`",o+1);if(t>o+1){a(),r.push({type:`code`,text:e.slice(o+1,t)}),o=t+1;continue}}let l=s+c;if(l===`**`||l===`__`||l===`~~`){let n=R(e,o+2,l);if(n!==-1&&!(l===`__`&&I(e.charAt(o-1)))){a();let i=z(e.slice(o+2,n),t);l===`~~`?r.push({type:`strike`,children:i}):r.push({type:`strong`,children:i}),o=n+2;continue}i+=l,o+=2}else{if(s===`*`||s===`_`){let n=R(e,o+1,s);if(n!==-1&&!(s===`_`&&I(e.charAt(o-1)))){a(),r.push({type:`em`,children:z(e.slice(o+1,n),t)}),o=n+1;continue}}if(s===`[`){N.lastIndex=o;let t=N.exec(e);if(t){a(),r.push({type:`link`,href:t[2],children:z(t[1])}),o+=t[0].length;continue}if(n){F.lastIndex=o;let t=F.exec(e);if(t&&n(t[1])){a(),r.push({type:`citation`,text:t[1]}),o+=t[0].length;continue}}}if(s===`!`){P.lastIndex=o;let t=P.exec(e);if(t){a(),r.push({type:`image`,children:z(t[1])}),o+=t[0].length;continue}}i+=s,o+=1}}return a(),r.map((e,t)=>({...e,key:t}))}var B=/^\s*```/,V=/^\s*```\s*(\S*)/,H=/^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/,U=/^\s*([-*_])(\s*\1){2,}\s*$/,W=/^(\s*)[-*+]\s+(.*)$/,G=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,ee=/^\s*>\s?(.*)$/,te=/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/,ne=e=>e.includes(`|`);function re(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}function ie(e,t){return ne(e[t])&&t+1<e.length&&e[t+1].includes(`|`)&&te.test(e[t+1])}function ae(e,t){let n=e[t];return B.test(n)||ee.test(n)||W.test(n)||G.test(n)||H.test(n)||U.test(n)||ie(e,t)}function oe(e){let t=e.replace(/\t/g,` `).length;return Math.min(Math.floor(t/2),4)}function se(e){let t=G.exec(e);if(t)return{text:t[3],depth:oe(t[1]),ordered:!0,number:Number(t[2])};let n=W.exec(e);return n?{text:n[2],depth:oe(n[1]),ordered:!1,number:0}:null}function ce(e){let t=(e??``).replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r+=1;continue}if(
|
|
4
|
-
`),language:i});continue}if(
|
|
5
|
-
`)}function ge(e,t){return e.kind===`Reply`?t.actionReply(e.ticketNumber):e.kind===`Reopen`?t.actionReopen(e.ticketNumber):t.actionRaiseTicket}function _e(e,t,n){return e===`Reply`?n.actionDoneReply(t):e===`Reopen`?n.actionDoneReopen(t):n.actionDoneRaiseTicket(t)}function ve({action:e,confirmAction:t,onViewTicket:n,labels:r}){let i=u(r),[a,o]=P(`ready`),[s,c]=P(null),[l,d]=P(``);if(a===`dismissed`)return/* @__PURE__ */ L(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:i.actionDismissed});if(a===`done`)return/* @__PURE__ */ L(f,{tone:`success`,role:`status`,size:`sm`,action:n?/* @__PURE__ */ L(p,{size:`sm`,variant:`ghost`,onClick:()=>n(s),children:i.viewTicket}):void 0,children:_e(e.kind,s.number,i)});async function h(){o(`sending`),d(``);try{c(await t(e.token)),o(`done`)}catch(e){d(e?.message||i.actionFailed),o(`ready`)}}let g=a===`sending`,_=new Date(e.expiresDateTimeUtc).getTime()<=Date.now(),v=e.kind===`RaiseTicket`?[e.category,e.subject].filter(Boolean).join(` · `):``;return/* @__PURE__ */ L(m,{padding:`sm`,className:`border`,title:ge(e,i),subtitle:v||void 0,children:/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[e.kind!==`Reopen`&&e.body&&/* @__PURE__ */ L(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e.body}),_?/* @__PURE__ */ L(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:i.actionExpired}):/* @__PURE__ */ R(I,{children:[/* @__PURE__ */ L(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:i.actionNote}),l&&/* @__PURE__ */ L(f,{size:`sm`,tone:`danger`,children:l}),/* @__PURE__ */ R(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ L(p,{size:`sm`,loading:g,onClick:h,children:i.actionConfirm}),/* @__PURE__ */ L(p,{size:`sm`,variant:`secondary`,disabled:g,onClick:()=>o(`dismissed`),children:i.actionDismiss})]})]})]})})}function ye({attachments:e,onRemove:t,labels:n}){return e.length===0?null:/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ L(g,{children:e.map(e=>/* @__PURE__ */ L(h,{label:e.fileName,tone:e.status===`Failed`?`danger`:`neutral`,onRemove:()=>t(e.key),removeLabel:n.removeAttachment(e.fileName)},e.key))}),e.map(e=>e.progress===null?null:/* @__PURE__ */ L(w,{value:e.progress,max:1,size:`sm`,label:e.fileName},e.key)),e.filter(e=>e.status===`Failed`).map(e=>/* @__PURE__ */ L(`span`,{className:`small text-danger`,role:`alert`,children:e.error},e.key))]})}function be({onSubmit:e,busy:t=!1,disabled:n=!1,maxLength:r=4e3,inputRef:i,attachments:a=[],onAttach:o,onRemoveAttachment:s,accept:c,onStop:l,editing:d=null,onCancelEdit:f,labels:m}){let h=u(m),g=j(),_=N(null),[v,y]=P(``),b=a.some(e=>e.status===`Uploading`),x=t||n||b||!v.trim();A(()=>{d&&y(d.text)},[d]);function S(){x||(e(v.trim()),y(``))}function C(e){let t=Array.from(e.target.files??[]);e.target.value=``,t.length>0&&o(t)}return/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[d&&f&&/* @__PURE__ */ R(`div`,{className:`wui-chat-editing`,children:[/* @__PURE__ */ L(`span`,{className:`small text-body-secondary`,children:h.editing}),/* @__PURE__ */ L(p,{type:`button`,size:`sm`,variant:`ghost`,onClick:f,children:h.cancel})]}),/* @__PURE__ */ L(ye,{attachments:a,onRemove:e=>s?.(e),labels:h}),/* @__PURE__ */ R(`form`,{className:`wui-chat-composer d-flex align-items-end gap-2`,"aria-label":h.composer,onSubmit:e=>{e.preventDefault(),S()},children:[o&&/* @__PURE__ */ R(I,{children:[/* @__PURE__ */ L(p,{type:`button`,variant:`ghost`,leftIcon:`paperclip`,disabled:n,"aria-describedby":`${g}-attach-hint`,onClick:()=>_.current?.click(),children:/* @__PURE__ */ L(`span`,{className:`visually-hidden`,children:h.attach})}),/* @__PURE__ */ L(`span`,{id:`${g}-attach-hint`,className:`visually-hidden`,children:h.attachHint}),/* @__PURE__ */ L(`input`,{ref:_,type:`file`,multiple:!0,accept:c,hidden:!0,onChange:C})]}),/* @__PURE__ */ L(D,{id:`${g}-message`,"aria-label":h.composer,"aria-describedby":`${g}-hint`,placeholder:h.placeholder,rows:1,autoGrow:!0,maxLength:r,value:v,disabled:n,ref:i,fieldClassName:`flex-grow-1 mb-0`,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),S())}}),/* @__PURE__ */ L(`span`,{id:`${g}-hint`,className:`visually-hidden`,children:h.composerHint}),t&&l?/* @__PURE__ */ L(p,{type:`button`,leftIcon:`stop`,onClick:l,children:/* @__PURE__ */ L(`span`,{className:`visually-hidden`,children:h.stop})}):/* @__PURE__ */ L(p,{type:`submit`,leftIcon:`send`,disabled:x,children:/* @__PURE__ */ L(`span`,{className:`visually-hidden`,children:h.send})})]})]})}function xe({client:e,onOpen:t,onDeleted:n,pageSize:r=20,labels:i}){let a=u(i),o=M(()=>s({client:e,pageSize:r}),[e,r]),c=F(o.subscribe,o.getState),[l,h]=P(null),[g,v]=P(!1),[y,x]=P(``),[C,w]=P(null),[E,D]=P(``),[O,k]=P(!1),[j,N]=P(``),[I,z]=P(void 0),[B,V]=P(``);A(()=>(o.load(),o.dispose),[o]),A(()=>{if(typeof e.getSettings!=`function`)return;let t=!0;return Promise.resolve().then(()=>e.getSettings()).then(e=>{t&&z(e.titleMaxLength)}).catch(e=>{t&&V(e?.message||a.loadFailed)}),()=>{t=!1}},[e,a.loadFailed]);async function H(){v(!0),x(``);try{await o.remove(l.publicId),n?.(l.publicId),h(null)}catch(e){x(e?.message||a.deleteFailed)}finally{v(!1)}}function U(e){O||(w(e.publicId),D(e.title||``),N(``))}function W(){w(null),N(``)}async function G(e){if(!(O||E.trim()===``)){k(!0),N(``);try{await o.rename(e,E),w(null)}catch(e){N(e?.message||a.renameFailed)}finally{k(!1)}}}let K=c.totalCount===null&&c.error===null;return!c.loading&&!K&&!c.error&&c.items.length===0?/* @__PURE__ */ L(b,{icon:`chat`,size:`sm`,title:a.conversationsEmptyTitle,text:a.conversationsEmptyText}):/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-3`,children:[c.error&&/* @__PURE__ */ L(f,{tone:`danger`,action:/* @__PURE__ */ L(p,{size:`sm`,variant:`secondary`,onClick:()=>o.load(),children:a.retry}),children:c.error.message}),c.items.length>0&&/* @__PURE__ */ L(`ul`,{className:`list-unstyled d-flex flex-column gap-2 mb-0`,"aria-label":a.conversations,children:c.items.map(e=>/* @__PURE__ */ L(`li`,{children:C===e.publicId?/* @__PURE__ */ R(m,{padding:`sm`,className:`border`,bodyClassName:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ R(`div`,{className:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ L(S,{size:`sm`,"aria-label":a.conversationTitle,fieldClassName:`flex-grow-1 mb-0`,value:E,maxLength:I,autoFocus:!0,onChange:e=>D(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),G(e.publicId)):t.key===`Escape`&&(t.preventDefault(),W())}}),/* @__PURE__ */ L(p,{variant:`primary`,size:`sm`,loading:O,disabled:O||E.trim()===``,onClick:()=>G(e.publicId),children:a.renameSave}),/* @__PURE__ */ L(p,{variant:`secondary`,size:`sm`,onClick:W,children:a.cancel})]}),(j||B)&&/* @__PURE__ */ L(f,{tone:`danger`,size:`sm`,children:j||B})]}):/* @__PURE__ */ R(m,{padding:`sm`,className:`border`,bodyClassName:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ L(p,{variant:`ghost`,className:`flex-grow-1 text-start`,style:{minWidth:0},onClick:()=>t(e),children:/* @__PURE__ */ R(`span`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ L(`span`,{className:`text-truncate fw-semibold`,children:e.title||a.untitled}),/* @__PURE__ */ L(`time`,{dateTime:e.lastMessageDateTimeUtc,className:`wui-text-xs text-body-secondary`,children:ee(e.lastMessageDateTimeUtc)})]})}),/* @__PURE__ */ L(d,{icon:`edit`,label:a.renameConversation,onClick:()=>U(e)}),/* @__PURE__ */ L(d,{icon:`trash-2`,danger:!0,label:a.deleteConversation,onClick:()=>{x(``),h(e)}})]})},e.publicId))}),(c.loading||K)&&/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,"aria-hidden":`true`,children:[/* @__PURE__ */ L(T,{height:44}),/* @__PURE__ */ L(T,{height:44}),/* @__PURE__ */ L(T,{height:44})]}),!c.loading&&c.hasMore&&/* @__PURE__ */ L(p,{variant:`secondary`,className:`align-self-center`,onClick:()=>o.loadMore(),children:a.loadMore}),/* @__PURE__ */ L(_,{open:l!==null,title:a.deleteConfirmTitle,message:y?/* @__PURE__ */ L(f,{tone:`danger`,children:y}):a.deleteConfirmMessage,confirmLabel:a.deleteConfirm,cancelLabel:a.cancel,danger:!0,loading:g,onConfirm:H,onClose:()=>{g||h(null)}})]})}var Se={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},Ce={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function we({onClick:e,open:t=!1,position:n=`end`,icon:r=`sparkles`,compact:i=!1,className:a,style:o,labels:s}){let c=u(s);return i?/* @__PURE__ */ L(Te,{onClick:e,open:t,position:n,icon:r,className:a,style:o,label:c.launcher}):/* @__PURE__ */ L(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,a].filter(Boolean).join(` `),style:{...Se,...Ce[n],...o},children:/* @__PURE__ */ L(p,{leftIcon:r,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:c.launcher})})}function Te({onClick:e,open:t,position:n,icon:r,className:i,style:a,label:o}){let s=O(n);return s?z(/* @__PURE__ */ L(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,i].filter(Boolean).join(` `),style:a,children:/* @__PURE__ */ L(p,{className:`wui-floating-btn`,onClick:e,"aria-label":o,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:o,tooltipPlacement:n===`start`?`end`:`start`,children:/* @__PURE__ */ L(x,{name:r,size:24})})}),s):null}function Ee({text:e,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a}){return/* @__PURE__ */ L(C,{value:e,links:`app`,headings:`text`,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a})}function De({rating:e,onRate:t,noteMaxLength:n=1e3,labels:r}){let i=u(r),a=j(),[o,s]=P(!1),[c,l]=P(!1),[d,m]=P(``),[h,g]=P(``),[_,v]=P(!1);async function y(e,n){s(!0),g(``);try{await t(e,n),l(e===`Down`&&n===void 0),v(e===`Up`||n!==void 0),n!==void 0&&m(``)}catch{g(i.ratingFailed)}finally{s(!1)}}return/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ R(`div`,{className:`d-flex flex-wrap align-items-center gap-1`,children:[/* @__PURE__ */ L(p,{size:`sm`,variant:e===`Up`?`neutral`:`ghost`,leftIcon:`check`,"aria-pressed":e===`Up`,disabled:o,onClick:()=>y(`Up`),children:i.rateUp}),/* @__PURE__ */ L(p,{size:`sm`,variant:e===`Down`?`neutral`:`ghost`,leftIcon:`x`,"aria-pressed":e===`Down`,disabled:o,onClick:()=>y(`Down`),children:i.rateDown}),_&&!c&&/* @__PURE__ */ L(`span`,{className:`wui-text-xs text-body-secondary`,role:`status`,children:i.rated})]}),h&&/* @__PURE__ */ L(f,{size:`sm`,tone:`danger`,children:h}),c&&/* @__PURE__ */ R(`form`,{className:`d-flex flex-column gap-2`,onSubmit:e=>{e.preventDefault(),y(`Down`,d)},children:[/* @__PURE__ */ L(D,{id:`${a}-note`,label:i.ratingNote,hint:i.ratingNoteHint,rows:2,maxLength:n,value:d,onChange:e=>m(e.target.value)}),/* @__PURE__ */ R(`div`,{className:`d-flex gap-2`,children:[/* @__PURE__ */ L(p,{type:`submit`,size:`sm`,loading:o,children:i.ratingNoteSend}),/* @__PURE__ */ L(p,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>{l(!1),v(!0)},children:i.ratingNoteSkip})]})]})]})}var Oe={maxWidth:`85%`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function ke({turn:e,onRate:t,onRetry:n,onRegenerate:r,canRegenerate:i,onEdit:a,onOpenAttachment:o,resolveLink:s,linkComponent:c,isCitation:l,onOpenCitation:g,onAskSuggestion:_,confirmAction:y,onViewTicket:b,renderReply:x,labels:S}){let C=u(S),w=e.streaming&&!e.answer,T=!!e.answer&&!e.streaming,D=e.step?C.toolStep(e.step):C.thinking;return/* @__PURE__ */ R(`li`,{className:`d-flex flex-column gap-2`,children:[e.question&&/* @__PURE__ */ R(`div`,{className:`d-flex align-items-center gap-1 align-self-end`,children:[a&&e.questionId&&/* @__PURE__ */ L(d,{icon:`edit`,label:C.edit,onClick:()=>a(e.id)}),/* @__PURE__ */ R(`div`,{style:Oe,children:[/* @__PURE__ */ R(`span`,{className:`visually-hidden`,children:[C.you,`: `]}),/* @__PURE__ */ R(m,{padding:`sm`,variant:`muted`,className:`wui-text-sm`,children:[e.question,e.attachments?.length>0&&/* @__PURE__ */ L(`div`,{className:`wui-chat-question-attachments mt-2`,children:e.attachments.map(e=>/* @__PURE__ */ L(h,{label:e.fileName,leadingIcon:`document`,onClick:o?()=>o(e):void 0},e.publicId))})]})]})]}),/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,style:{minWidth:0},children:[/* @__PURE__ */ R(`span`,{className:`visually-hidden`,children:[C.assistant,`: `]}),/* @__PURE__ */ L(`div`,{"aria-live":`polite`,"aria-busy":e.streaming,children:e.stopped?/* @__PURE__ */ L(f,{size:`sm`,tone:`neutral`,children:C.stopped}):w?/* @__PURE__ */ R(`span`,{className:`d-inline-flex align-items-center gap-2 wui-text-sm text-body-secondary`,children:[/* @__PURE__ */ L(E,{size:`sm`,label:D}),/* @__PURE__ */ L(`span`,{"aria-hidden":`true`,children:D})]}):e.answer&&(x?x(e,{streaming:!!e.streaming}):/* @__PURE__ */ L(Ee,{text:e.answer,resolveLink:s,linkComponent:c,isCitation:l,onOpenCitation:g}))}),e.error&&/* @__PURE__ */ L(f,{size:`sm`,tone:`danger`,children:e.error.message}),n&&(e.error||e.stopped)&&/* @__PURE__ */ L(`div`,{children:/* @__PURE__ */ L(p,{variant:`outline`,size:`sm`,onClick:()=>n(e.id),children:C.retry})}),y&&!e.streaming&&e.actions.map(e=>/* @__PURE__ */ L(ve,{action:e,confirmAction:y,onViewTicket:b,labels:S},e.token)),(T||t&&e.messageId&&!e.streaming)&&/* @__PURE__ */ R(`div`,{className:`wui-chat-turn-actions align-items-center`,children:[T&&/* @__PURE__ */ L(v,{text:he(e.answer),label:C.copy,copiedLabel:C.copied,iconOnly:!0,size:`sm`,variant:`ghost`}),t&&e.messageId&&!e.streaming&&/* @__PURE__ */ L(De,{rating:e.rating,onRate:(n,r)=>t(e.id,n,r),labels:S}),r&&i&&T&&/* @__PURE__ */ L(p,{variant:`outline`,size:`sm`,leftIcon:`refresh`,onClick:()=>r(e.id),children:C.regenerate})]}),_&&!e.streaming&&e.suggestions.length>0&&/* @__PURE__ */ L(`div`,{className:`wui-chat-suggestions`,role:`group`,"aria-label":C.suggestions,children:e.suggestions.map(e=>/* @__PURE__ */ L(p,{variant:`outline`,size:`sm`,onClick:()=>_(e),children:e},e))})]})]})}var Ae=k(ke);function je(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Me({turns:e,empty:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:c,onRegenerate:l,onAskSuggestion:d,isCitation:f,onOpenCitation:p,onEdit:m,onOpenAttachment:h,labels:g}){let _=u(g),v=N(null),y=e[e.length-1];return A(()=>{let e=je(v.current);e&&(e.scrollTop=e.scrollHeight)},[e.length,y?.answer,y?.error,y?.actions]),e.length===0?t??/* @__PURE__ */ L(b,{icon:`sparkles`,size:`sm`,title:_.emptyTitle,text:_.emptyText}):/* @__PURE__ */ R(I,{children:[/* @__PURE__ */ L(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":_.thread,children:e.map((t,u)=>/* @__PURE__ */ L(Ae,{turn:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:u===e.length-1?c:void 0,onRegenerate:l,onAskSuggestion:u===e.length-1?d:void 0,isCitation:f,onOpenCitation:p,canRegenerate:u===e.length-1,onEdit:m,onOpenAttachment:h,labels:g},t.id))}),/* @__PURE__ */ L(`div`,{ref:v})]})}function Ne({chat:e,open:t,onClose:n,title:r,titleIcon:i=`sparkles`,headerActions:a,empty:o,disclaimer:s,maxLength:c=4e3,allowanceThreshold:l=10,width:p=`440px`,resolveLink:m,linkComponent:h,confirmAction:g,onViewTicket:_,rating:v=!0,renderReply:b,openAttachment:S,conversations:C=!1,isCitation:w,onOpenCitation:T,labels:D}){let O=u(D),k=N(null),{refreshAllowance:j}=e,M=e.settings?.attachments,F=M?.contentTypes.join(`,`),[ee,z]=P(`chat`);A(()=>{t&&j().catch(()=>{})},[t,j]),A(()=>{t||z(`chat`)},[t]);let B=e.messagesLeftToday,V=r??O.panelTitle,H=C&&ee===`conversations`,U=/* @__PURE__ */ R(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ R(`div`,{className:`drawer-title`,children:[i&&/* @__PURE__ */ L(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ L(x,{name:i,size:18})}),V]}),/* @__PURE__ */ R(`div`,{className:`d-flex align-items-center gap-1`,children:[a,H?/* @__PURE__ */ L(d,{icon:`arrow-left`,label:O.backToChat,onClick:()=>z(`chat`)}):/* @__PURE__ */ R(I,{children:[C&&/* @__PURE__ */ L(d,{icon:`history`,label:O.conversations,onClick:()=>z(`conversations`)}),/* @__PURE__ */ L(d,{icon:`plus`,label:O.newChat,onClick:e.newConversation,disabled:e.turns.length===0&&!e.loading})]}),/* @__PURE__ */ L(d,{icon:`x`,label:O.close,onClick:n})]})]}),W=/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[B!==null&&B<=l&&/* @__PURE__ */ L(`p`,{className:`wui-text-xs text-body-secondary mb-0`,role:`status`,children:O.allowance(B)}),e.settingsError&&/* @__PURE__ */ L(f,{tone:`danger`,children:e.settingsError.message}),/* @__PURE__ */ L(be,{onSubmit:e.submit,busy:e.streaming||e.loading,disabled:B===0,maxLength:c,inputRef:k,attachments:e.attachments,onAttach:M?e.attach:void 0,onRemoveAttachment:e.removeAttachment,accept:F,onStop:e.streaming?e.stop:void 0,editing:e.editing,onCancelEdit:e.cancelEdit,labels:D}),/* @__PURE__ */ L(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:s??O.disclaimer})]});return/* @__PURE__ */ L(y,{open:t,onClose:n,sheet:!1,width:p,header:U,footer:H?void 0:W,ariaLabel:typeof V==`string`?V:O.panelTitle,onOpened:()=>k.current?.focus(),children:H?/* @__PURE__ */ L(xe,{client:e.client,onOpen:t=>{e.openConversation(t.publicId),z(`chat`)},onDeleted:t=>{t===e.conversationId&&e.newConversation()},labels:D}):e.loading?/* @__PURE__ */ L(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ L(E,{label:O.loadingConversation})}):e.loadError?/* @__PURE__ */ L(f,{tone:`danger`,children:e.loadError.message}):/* @__PURE__ */ L(Me,{turns:e.turns,empty:o,onRate:v?e.rate:void 0,onRetry:e.retry,onRegenerate:e.regenerate,onAskSuggestion:e.submit,isCitation:w,onOpenCitation:T,onEdit:e.startEdit,onOpenAttachment:S,resolveLink:m,linkComponent:h,confirmAction:g,onViewTicket:_,renderReply:b,labels:D})})}function Pe({citation:e,label:t,ariaLabel:n,onOpen:r}){return/* @__PURE__ */ L(h,{label:t??e,size:`sm`,tone:`primary`,variant:`outline`,leadingIcon:`book-1`,"aria-label":n??e,onClick:()=>r(e)})}function Fe({title:e,subtitle:t,lines:n,note:r,onConfirm:i,labels:a}){let o=u(a),[s,c]=P(`ready`),[l,d]=P(null),[h,g]=P(``);if(s===`dismissed`)return/* @__PURE__ */ L(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:o.actionDismissed});if(s===`done`)return/* @__PURE__ */ L(f,{tone:`success`,role:`status`,size:`sm`,children:l?.message||o.actionDone});async function _(){c(`sending`),g(``);try{let e=await i();d(e??null),c(`done`)}catch(e){g(e?.message||o.actionFailed),c(`ready`)}}let v=s===`sending`;return/* @__PURE__ */ L(m,{padding:`sm`,className:`border`,title:e,subtitle:t||void 0,children:/* @__PURE__ */ R(`div`,{className:`d-flex flex-column gap-2`,children:[(n??[]).map((e,t)=>/* @__PURE__ */ L(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e},t)),/* @__PURE__ */ L(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:r??o.actionNote}),h&&/* @__PURE__ */ L(f,{size:`sm`,tone:`danger`,children:h}),/* @__PURE__ */ R(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ L(p,{size:`sm`,loading:v,onClick:_,children:o.actionConfirm}),/* @__PURE__ */ L(p,{size:`sm`,variant:`secondary`,disabled:v,onClick:()=>c(`dismissed`),children:o.actionDismiss})]})]})})}function Ie({client:e,pageContext:t}){let n=N(t);n.current=t;let r=M(()=>a({client:e,pageContext:()=>n.current}),[e]);A(()=>()=>r.dispose(),[r]);let i=F(r.subscribe,r.getState),o=M(()=>({submit:e=>r.submit(e),stop:()=>r.stop(),retry:e=>r.retry(e),regenerate:e=>r.regenerate(e),startEdit:e=>r.startEdit(e),cancelEdit:()=>r.cancelEdit(),attach:e=>r.attach(e),removeAttachment:e=>r.removeAttachment(e),openConversation:e=>r.openConversation(e),newConversation:()=>r.newConversation(),rate:(e,t,n)=>r.rate(e,t,n),refreshAllowance:()=>r.refreshAllowance(),reset:()=>r.reset()}),[r]);return{...i,...o,client:r.client}}export{ve as ActionCard,e as CHAT_CONTRACT_VERSION,t as ChatApiError,be as ChatComposer,xe as ChatConversationList,we as ChatLauncher,Ee as ChatMarkdown,Ae as ChatMessage,Ne as ChatPanel,Me as ChatThread,Pe as CitationChip,Fe as ConfirmCard,n as DEFAULT_CHAT_LABELS,De as ReplyRating,r as createChatClient,i as createChatSession,o as createConversationList,c as createSseParser,l as mergeLabels,V as splitCitations,Ie as useChat};
|
|
3
|
+
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r+=1;continue}if(B.test(e)){let i=V.exec(e)?.[1]||null,a=[];for(r+=1;r<t.length&&!B.test(t[r]);)a.push(t[r]),r+=1;r+=1,n.push({type:`code`,text:a.join(`
|
|
4
|
+
`),language:i});continue}if(ie(t,r)){let i=re(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&ne(t[r]);)a.push(re(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(U.test(e)){n.push({type:`rule`}),r+=1;continue}let i=H.exec(e);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]}),r+=1;continue}if(ee.test(e)){let e=[];for(;r<t.length;){let n=ee.exec(t[r]);if(!n)break;e.push(n[1]),r+=1}n.push({type:`quote`,lines:e});continue}let a=se(e);if(a){let e=[];for(;r<t.length&&t[r].trim();){let n=se(t[r]);if(n){if(n.depth===0&&n.ordered!==a.ordered)break;e.push(n)}else if(ae(t,r))break;else e[e.length-1].text+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!ae(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var le=e=>e.map(e=>e.type===`text`||e.type===`code`||e.type===`citation`?e.text:le(e.children)).join(``),K=e=>le(z(e));function ue(e){switch(e.type){case`paragraph`:case`quote`:return K(e.lines.join(` `));case`heading`:return K(e.text);case`list`:return e.items.map(e=>K(e.text)).join(`. `);case`table`:return[e.header,...e.rows].map(e=>e.map(K).join(`, `)).join(`. `);case`code`:return e.text;case`rule`:return``}}function de(e){return ce(e).map(ue).filter(Boolean).join(`
|
|
5
|
+
`)}var q=Object.freeze({launcher:`Ask the assistant`,panelTitle:`Assistant`,newChat:`New chat`,close:`Close`,thread:`Conversation`,you:`You`,assistant:`Assistant`,thinking:`Thinking`,emptyTitle:`How can I help?`,emptyText:`Ask a question about what you see on this page.`,composer:`Your question`,placeholder:`Ask a question`,send:`Send`,composerHint:`Press Enter to send, Shift and Enter for a new line.`,allowance:e=>e===0?`You have no questions left today.`:e===1?`You have 1 question left today.`:`You have ${e} questions left today.`,disclaimer:`Answers are written by AI and can be wrong. Check anything important.`,loadingConversation:`Loading the conversation`,rateUp:`Helpful`,rateDown:`Not helpful`,rated:`Thanks for the feedback.`,ratingNote:`What was wrong with this answer?`,ratingNoteHint:`Optional.`,ratingNoteSend:`Send`,ratingNoteSkip:`Skip`,ratingFailed:`Your rating did not save. Please try again.`,actionRaiseTicket:`New support ticket`,actionReply:e=>`Reply on ${e}`,actionReopen:e=>`Reopen ${e}`,actionNote:`Nothing is sent until you confirm.`,actionConfirm:`Confirm`,actionDismiss:`Not now`,actionDismissed:`Not sent.`,actionExpired:`This request expired and was not sent. Ask again if you still need it.`,actionFailed:`We could not send this. Please try again.`,actionDone:`Done.`,actionDoneRaiseTicket:e=>`Ticket ${e} raised.`,actionDoneReply:e=>`Your reply was added to ${e}.`,actionDoneReopen:e=>`${e} is open again.`,viewTicket:`View ticket`,conversations:`Past chats`,conversationsEmptyTitle:`No past chats`,conversationsEmptyText:`Your conversations with the assistant show here.`,untitled:`Untitled chat`,deleteConversation:`Delete chat`,deleteConfirmTitle:`Delete this chat?`,deleteConfirmMessage:`The conversation is removed for good.`,deleteConfirm:`Delete`,deleteFailed:`We could not delete this chat. Please try again.`,cancel:`Cancel`,loadMore:`Show more`,loadFailed:`We could not load your chats. Please try again.`,retry:`Try again`,stop:`Stop`,stopped:`Stopped. Your question was not sent.`,regenerate:`New answer`,edit:`Edit`,editing:`Editing your question`,attach:`Attach a file`,attachHint:`Pictures or PDFs.`,removeAttachment:e=>`Remove ${e}`,attachmentUploading:`Uploading`,attachmentFailed:`That file did not upload. Please try again.`,attachmentLimit:e=>`You can attach up to ${e} files.`,assistantOutdated:`The assistant needs an update before it can answer. Please try again later.`,copy:`Copy`,copied:`Copied`,toolStep:e=>`Looking this up`,suggestions:`Suggested questions`,openCitation:e=>`Open ${e}`,renameConversation:`Rename chat`,conversationTitle:`Chat name`,renameSave:`Save`,renameFailed:`We could not rename this chat. Please try again.`,backToChat:`Back to the chat`}),J=e=>e?{...q,...e}:q,fe=e=>{let t=``,n=t=>{let n=`message`,r=[];for(let e of t.split(`
|
|
6
|
+
`)){if(e===``||e.startsWith(`:`))continue;let t=e.indexOf(`:`),i=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1);a.startsWith(` `)&&(a=a.slice(1)),i===`event`?n=a:i===`data`&&r.push(a)}if(r.length===0)return;let i;try{i=JSON.parse(r.join(`
|
|
7
|
+
`))}catch{e({name:`error`,data:{code:`invalid-response`,message:null}});return}e({name:n,data:i})};return{push(e){if(!e)return;t=(t+e).replace(/\r\n/g,`
|
|
8
|
+
`).replace(/\r(?!$)/g,`
|
|
9
|
+
`);let r=t.split(`
|
|
10
|
+
|
|
11
|
+
`);t=r.pop()??``;for(let e of r)n(e)},end(){let e=t.replace(/\r$/,``);t=``,e.trim()&&n(e)}}},Y=`Something went wrong. Please try again.`,pe=2,X=class extends Error{code;status;resetsAtUtc;constructor(e,t,n,r=null){super(t),this.name=`ChatApiError`,this.code=e,this.status=n,this.resetsAtUtc=r}},me=e=>{if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null},he=(e,t)=>!!t?.aborted||e?.code===`ERR_CANCELED`||e?.name===`CanceledError`||e?.name===`AbortError`,ge=(e,t)=>{if(e instanceof X)return e;let n=e;if(he(n,t))return new X(`aborted`,`The request was cancelled.`);let r=n?.response;if(!r)return new X(`network`,Y);let i=me(r.data),a=typeof i?.code==`string`&&i.code?i.code:`unknown`,o=typeof i?.message==`string`&&i.message?i.message:Y,s=typeof i?.resetsAtUtc==`string`?i.resetsAtUtc:null;return new X(a,o,typeof r.status==`number`?r.status:void 0,s)},Z=async e=>{try{return(await e()).data}catch(e){throw ge(e)}},_e=e=>{let t=e?.event?.target;if(t&&typeof t.responseText==`string`&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText},ve=()=>{let e=globalThis.FormData;if(!e)throw Error(`FormData is not available.`);return new e},ye=e=>typeof e.uri==`string`,be=(e,t)=>{if(ye(t)){e.append(`file`,t);return}let n=t.name;if(typeof n!=`string`||n===``)throw Error(`The file needs a name.`);e.append(`file`,t,n)},xe=(e,{base:t})=>{if(typeof t!=`string`||t.trim()===``)throw TypeError(`createChatClient needs a base path, e.g. { base: "/api/assistant" }.`);let n=t.replace(/\/+$/,``),r=e=>`${n}/conversations/${encodeURIComponent(e)}`,i=e=>`${n}/attachments/${encodeURIComponent(e)}`,a=null,o=async()=>{try{let t=await Z(()=>e.get(`${n}/settings`));if(typeof t?.contractVersion!=`number`||t.contractVersion<2)throw new X(`assistant_outdated`,q.assistantOutdated);return t}catch(e){throw e instanceof X&&e.status===404?new X(`assistant_outdated`,q.assistantOutdated,404):e}},s=()=>(a||=o().catch(e=>{throw a=null,e}),a);return{sendMessage:async({message:t,conversationId:r,pageContext:i,replacesMessageId:a,attachmentIds:o},{signal:c,onEvent:l}={})=>{await s();let u=null,d=null,f=fe(({name:e,data:t})=>{d||u&&e!==`suggestions`||(e===`done`?(u=t,l?.(e,t)):e===`error`?d=t??{}:(e===`delta`||e===`reset`||e===`tool`||e===`actions`||e===`suggestions`)&&l?.(e,t))}),p=0,m=e=>{typeof e!=`string`||e.length<=p||(f.push(e.slice(p)),p=e.length)},h={message:t};r&&(h.conversationId=r),i!=null&&(h.pageContext=i),a&&(h.replacesMessageId=a),o&&o.length>0&&(h.attachmentIds=o);let g;try{g=await e.post(`${n}/chat`,h,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:c,onDownloadProgress:e=>m(_e(e))})}catch(e){throw ge(e,c)}m(g.data),f.end();let _=d;if(_)throw new X(_.code||`unknown`,_.message||Y);let v=u;if(!v)throw new X(`invalid-response`,Y,g.status);return v},getSettings:s,uploadAttachment:async(t,{signal:r,onProgress:i}={})=>{await s();let a=ve();return be(a,t),Z(()=>e.post(`${n}/attachments`,a,{headers:{"Content-Type":`multipart/form-data`},timeout:3e5,signal:r,onUploadProgress:({loaded:e,total:t})=>{i&&t&&i((e??0)/t)}}))},deleteAttachment:async t=>{await s(),await Z(()=>e.delete(i(t)))},getAttachment:async t=>(await s(),Z(()=>e.get(i(t),{responseType:`arraybuffer`}))),getAllowance:async()=>(await s(),Z(()=>e.get(`${n}/allowance`))),listConversations:async({page:t,pageSize:r}={})=>{await s();let i=[];t!==void 0&&i.push(`page=${encodeURIComponent(String(t))}`),r!==void 0&&i.push(`pageSize=${encodeURIComponent(String(r))}`);let a=i.join(`&`),o=a?`${n}/conversations?${a}`:`${n}/conversations`;return Z(()=>e.get(o))},getConversation:async t=>(await s(),Z(()=>e.get(r(t)))),renameConversation:async(t,n)=>{await s(),await Z(()=>e.put(`${r(t)}/title`,{title:n}))},deleteConversation:async t=>{await s(),await Z(()=>e.delete(r(t)))},rateMessage:async(t,n,{rating:i,note:a})=>{await s();let o=typeof a==`string`?a.trim():``;await Z(()=>e.put(`${r(t)}/messages/${encodeURIComponent(n)}/rating`,{rating:i,note:o||null}))}}},Se=20,Ce=e=>e instanceof X?{code:e.code,message:e.message||q.loadFailed,resetsAtUtc:e.resetsAtUtc}:{code:`unknown`,message:q.loadFailed,resetsAtUtc:null},we=e=>{let t=e.client,n=e.pageSize??Se,r=/* @__PURE__ */ new Set,i={items:[],totalCount:null,loading:!1,error:null,hasMore:!1},a=0,o=!1,s=e=>{if(!o){i={...i,...e};for(let e of r)e()}};return{getState:()=>i,subscribe:e=>(r.add(e),()=>{r.delete(e)}),load:async()=>{a+=1;let e=a;s({loading:!0,error:null});try{let r=await t.listConversations({page:1,pageSize:n});if(o||e!==a)return;s({items:r.items,totalCount:r.totalCount,hasMore:r.page<r.totalPages,loading:!1})}catch(t){if(o||e!==a)return;s({loading:!1,error:Ce(t)})}},loadMore:async()=>{if(i.loading||!i.hasMore)return;let e=a,r=Math.floor(i.items.length/n)+1;s({loading:!0,error:null});try{let c=await t.listConversations({page:r,pageSize:n});if(o||e!==a)return;let l=new Set(i.items.map(e=>e.publicId)),u=c.items.filter(e=>!l.has(e.publicId));s({items:[...i.items,...u],totalCount:c.totalCount,hasMore:c.page<c.totalPages,loading:!1})}catch(t){if(o||e!==a)return;s({loading:!1,error:Ce(t)})}},rename:async(e,n)=>{let r=n.trim();if(await t.renameConversation(e,r),o)return;let a=r.replace(/\s+/g,` `);s({items:i.items.map(t=>t.publicId===e?{...t,title:a}:t)})},remove:async e=>{await t.deleteConversation(e),o||s({items:i.items.filter(t=>t.publicId!==e),totalCount:i.totalCount===null?null:i.totalCount-1})},dispose:()=>{o=!0,r.clear()}}},Q=globalThis,Te=e=>{if(Q.requestAnimationFrame&&Q.cancelAnimationFrame){let t=Q.requestAnimationFrame(()=>e());return()=>Q.cancelAnimationFrame?.(t)}let t=Q.setTimeout(e,16);return()=>Q.clearTimeout(t)},Ee=()=>({turns:[],conversationId:null,messagesLeftToday:null,streaming:!1,loading:!1,loadError:null,settings:null,settingsError:null,editing:null,attachments:[]}),De=e=>typeof e==`object`&&e?e:{},$=e=>{let t=De(e);return{code:typeof t.code==`string`&&t.code?t.code:`unknown`,message:typeof t.message==`string`&&t.message?t.message:`Something went wrong. Please try again.`,resetsAtUtc:typeof t.resetsAtUtc==`string`?t.resetsAtUtc:null}},Oe=e=>{if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]},ke=e=>{let t=[];for(let n of e){if(n.role===`User`){t.push({id:n.publicId,questionId:n.publicId,question:n.content,attachments:n.attachments,answer:``,streaming:!1,stopped:!1,step:null,error:null,actions:[],messageId:null,rating:null,ratingNote:null,suggestions:[]});continue}let e=t[t.length-1],r={answer:n.content,actions:Oe(n.actionsJson),messageId:n.publicId,rating:n.rating,ratingNote:n.ratingNote};e&&e.messageId===null&&e.answer===``?t[t.length-1]={...e,...r}:t.push({id:n.publicId,questionId:null,question:``,attachments:[],streaming:!1,stopped:!1,step:null,error:null,suggestions:[],...r})}return t},Ae=e=>{let t=De(e);return{fileName:typeof t.name==`string`?t.name:``,contentType:typeof t.type==`string`?t.type:``,length:typeof t.size==`number`?t.size:null}},je=e=>{let t=e.client,n=J(e.labels),r=e.schedule??Te,i=/* @__PURE__ */ new Set,a=Ee(),o=0,s=0,c=0,l=null,u=null,d=null,f=null,p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Set,g=/* @__PURE__ */ new Map,_=e=>{let t={...a,...e};e.turns&&(t.streaming=e.turns.some(e=>e.streaming)),a=t;for(let e of i)e()},v=(e,t)=>_({turns:a.turns.map(n=>n.id===e?{...n,...t}:n)}),y=(e,t)=>_({attachments:a.attachments.map(n=>n.key===e?{...n,...t}:n)}),b=()=>{f?.(),f=null},x=()=>{p.clear(),b()},S=()=>{if(p.size===0)return;let e=new Map(p);p.clear(),_({turns:a.turns.map(t=>{let n=e.get(t.id);return n===void 0?t:{...t,answer:t.answer+n,step:null}})})},C=(e,t)=>{p.set(e,(p.get(e)??``)+t),f||=r(()=>{f=null,S()})},w=()=>{S(),o+=1,l?.abort.abort(),l=null},T=()=>{u?.abort(),u=null},E=e=>{let t=e[e.length-1];return!t||t.suggestions.length===0?e:[...e.slice(0,-1),{...t,suggestions:[]}]},D=()=>{for(let e of g.values())e.abort();g.clear();for(let n of h){let r=m.get(n);r&&t.deleteAttachment(r.publicId).catch(e.onError)}h.clear(),m.clear()},O=()=>{if(d)return d;let e=t.getSettings().then(t=>{d===e&&_({settings:t})},t=>{if(d!==e)return;let r=$(t);r.code===`assistant_outdated`&&(r.message=n.assistantOutdated),_({settingsError:r})});return d=e,e},k=e=>{let t=m.get(e);if(!t)throw Error(`No uploaded file for composer attachment ${e}.`);return t},A=t=>{if(e.onError)e.onError(t);else throw t},j=async(e,r)=>{let i=new Q.AbortController;g.set(e,i);let a;try{a=await t.uploadAttachment(r,{signal:i.signal,onProgress:t=>{g.get(e)===i&&y(e,{progress:t})}})}catch{g.get(e)===i&&(g.delete(e),y(e,{status:`Failed`,progress:null,error:n.attachmentFailed}));return}g.get(e)===i?(g.delete(e),m.set(e,a),h.add(e),y(e,{status:`Ready`,progress:null})):t.deleteAttachment(a.publicId).catch(A)},M=async(n,r)=>{T();let i=o,c=new Q.AbortController;s+=1;let d=`turn-${s}`;l={id:d,abort:c};let f=()=>i===o&&!c.signal.aborted,p={id:d,questionId:null,question:n.text,attachments:n.attachments,answer:``,streaming:!0,stopped:!1,step:null,error:null,actions:[],messageId:null,rating:null,ratingNote:null,suggestions:[]};r&&(h.clear(),m.clear()),_({turns:[...E(n.before),p],...r?{editing:null,attachments:[]}:{}});let g=!1;try{if(await O(),!f())return;let r=a.settingsError;if(r){v(d,{streaming:!1,error:r});return}let i=await t.sendMessage({message:n.text,conversationId:a.conversationId,pageContext:e.pageContext?.(),replacesMessageId:n.replaces,attachmentIds:n.attachments.map(e=>e.publicId)},{signal:c.signal,onEvent:(e,t)=>{if(!f())return;let n=De(t);if(e===`delta`)C(d,typeof n.text==`string`?n.text:``);else if(S(),e===`reset`)v(d,{answer:``,step:null});else if(e===`tool`){let e=n.toolName;v(d,{step:typeof e==`string`&&e?e:null})}else if(e===`actions`)v(d,{actions:Array.isArray(n.actions)?n.actions:[]});else if(e===`suggestions`){let e=Array.isArray(n.suggestions)?n.suggestions:[];a.turns[a.turns.length-1]?.id===d&&v(d,{suggestions:e.filter(e=>typeof e==`string`)})}else if(e===`done`){let e=t;g=!0,v(d,{questionId:e.questionId,answer:e.reply,messageId:e.messageId??null,streaming:!1,step:null}),_({conversationId:e.conversationId,messagesLeftToday:e.messagesLeftToday??null}),l=null,u=c}}});if(S(),!f())return;g||(v(d,{questionId:i.questionId,answer:i.reply,messageId:i.messageId??null,streaming:!1,step:null}),_({conversationId:i.conversationId,messagesLeftToday:i.messagesLeftToday??null}))}catch(e){if(S(),!f()||g)return;let t=$(e);v(d,{answer:``,actions:[],streaming:!1,step:null,error:t}),t.code===`daily_limit`&&_({messagesLeftToday:0}),t.code===`conversation_not_found`&&_({conversationId:null})}finally{l?.id===d&&(l=null)}},N=async e=>{let t=typeof e==`string`?e.trim():``;if(!t||l||a.attachments.some(e=>e.status===`Uploading`))return;let n=a.attachments.filter(e=>e.status===`Ready`).map(e=>k(e.key)),r=a.turns,i=null;if(a.editing){let e=a.turns.findIndex(e=>e.id===a.editing?.turnId);e>=0&&(i=a.turns[e].questionId,r=a.turns.slice(0,e))}await M({text:t,replaces:i,attachments:n,before:r},!0)},P=()=>{if(!l)return;let{id:e,abort:t}=l;l=null,x(),t.abort(),_({turns:a.turns.map(t=>t.id===e?{...t,streaming:!1,stopped:!0,answer:``,step:null,actions:[]}:t)})};return{client:t,getState:()=>a,subscribe:e=>(i.add(e),d||O(),()=>{i.delete(e)}),submit:N,stop:P,retry:async e=>{let t=a.turns.length-1,n=a.turns[t];l||!n||n.id!==e||n.error===null&&!n.stopped||await M({text:n.question,replaces:null,attachments:n.attachments,before:a.turns.slice(0,t)},!1)},regenerate:async e=>{if(l)return;let t=a.turns.length-1;for(;t>=0&&a.turns[t].messageId===null;)--t;let n=a.turns[t];n&&n.id===e&&n.questionId!==null&&await M({text:n.question,replaces:n.questionId,attachments:n.attachments,before:a.turns.slice(0,t)},!1)},startEdit:e=>{let t=a.turns.find(t=>t.id===e);if(t&&t.questionId!==null){D();for(let e of t.attachments)m.set(e.publicId,e);_({turns:E(a.turns),editing:{turnId:e,text:t.question},attachments:t.attachments.map(e=>({key:e.publicId,fileName:e.fileName,contentType:e.contentType,length:e.length,status:`Ready`,progress:null,error:null}))})}},cancelEdit:()=>{a.editing&&(D(),_({editing:null,attachments:[]}))},attach:async e=>{await O();let t=a.settings?.attachments??null,r=t?t.maxFiles-a.attachments.filter(e=>e.status!==`Failed`).length:0,i=[],o=[];for(let a of e){let e=Ae(a);c+=1;let s=`file-${c}`,l={key:s,fileName:e.fileName,contentType:e.contentType,length:e.length??0};t?r<=0?i.push({...l,status:`Failed`,progress:null,error:n.attachmentLimit(t.maxFiles)}):e.length!==null&&e.length>t.maxFileBytes||!t.contentTypes.includes(e.contentType)?i.push({...l,status:`Failed`,progress:null,error:n.attachmentFailed}):(--r,i.push({...l,status:`Uploading`,progress:0,error:null}),o.push({key:s,file:a})):i.push({...l,status:`Failed`,progress:null,error:n.attachmentFailed})}_({attachments:[...a.attachments,...i]}),await Promise.all(o.map(({key:e,file:t})=>j(e,t)))},removeAttachment:async e=>{let n=g.get(e);n&&(g.delete(e),n.abort());let r=h.has(e)?m.get(e):void 0;r&&await t.deleteAttachment(r.publicId),h.delete(e),m.delete(e),_({attachments:a.attachments.filter(t=>t.key!==e)})},openConversation:async e=>{w(),T();let n=o;_({turns:[],conversationId:null,loadError:null,loading:!0,editing:null});try{let r=await t.getConversation(e);if(n!==o)return;_({turns:ke(r.messages),conversationId:r.publicId})}catch(e){if(n!==o)return;_({loadError:$(e)})}finally{n===o&&_({loading:!1})}},newConversation:()=>{D(),w(),T(),_({turns:[],conversationId:null,loadError:null,loading:!1,editing:null,attachments:[]})},rate:async(e,n,r)=>{let i=a.turns.find(t=>t.id===e),o=a.conversationId;if(!i?.messageId||!o)throw Error(`Only a stored reply can be rated.`);let s={rating:i.rating,ratingNote:i.ratingNote},c=typeof r==`string`&&r.trim()?r.trim():null;v(e,{rating:n,ratingNote:c});try{await t.rateMessage(o,i.messageId,{rating:n,note:c})}catch(t){throw v(e,s),t}},refreshAllowance:async()=>{let e=o,n=await t.getAllowance();e===o&&_({messagesLeftToday:n.messagesLeftToday})},reset:()=>{D(),x(),w(),T(),d=null,_(Ee())},dispose:()=>{i.clear(),o+=1,P(),T(),D(),x(),_({attachments:[],editing:null})}}};function Me(e,t){return e.kind===`Reply`?t.actionReply(e.ticketNumber):e.kind===`Reopen`?t.actionReopen(e.ticketNumber):t.actionRaiseTicket}function Ne(e,t,n){return e===`Reply`?n.actionDoneReply(t):e===`Reopen`?n.actionDoneReopen(t):n.actionDoneRaiseTicket(t)}function Pe({action:e,confirmAction:i,onViewTicket:a,labels:o}){let s=J(o),[c,l]=C(`ready`),[u,d]=C(null),[f,p]=C(``);if(c===`dismissed`)return/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:s.actionDismissed});if(c===`done`)return/* @__PURE__ */ E(t,{tone:`success`,role:`status`,size:`sm`,action:a?/* @__PURE__ */ E(n,{size:`sm`,variant:`ghost`,onClick:()=>a(u),children:s.viewTicket}):void 0,children:Ne(e.kind,u.number,s)});async function m(){l(`sending`),p(``);try{d(await i(e.token)),l(`done`)}catch(e){p(e?.message||s.actionFailed),l(`ready`)}}let h=c===`sending`,g=new Date(e.expiresDateTimeUtc).getTime()<=Date.now(),_=e.kind===`RaiseTicket`?[e.category,e.subject].filter(Boolean).join(` · `):``;return/* @__PURE__ */ E(r,{padding:`sm`,className:`border`,title:Me(e,s),subtitle:_||void 0,children:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[e.kind!==`Reopen`&&e.body&&/* @__PURE__ */ E(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e.body}),g?/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:s.actionExpired}):/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:s.actionNote}),f&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:f}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ E(n,{size:`sm`,loading:h,onClick:m,children:s.actionConfirm}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:h,onClick:()=>l(`dismissed`),children:s.actionDismiss})]})]})]})})}function Fe({attachments:e,onRemove:t,labels:n}){return e.length===0?null:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ E(a,{children:e.map(e=>/* @__PURE__ */ E(i,{label:e.fileName,tone:e.status===`Failed`?`danger`:`neutral`,onRemove:()=>t(e.key),removeLabel:n.removeAttachment(e.fileName)},e.key))}),e.map(e=>e.progress===null?null:/* @__PURE__ */ E(p,{value:e.progress,max:1,size:`sm`,label:e.fileName},e.key)),e.filter(e=>e.status===`Failed`).map(e=>/* @__PURE__ */ E(`span`,{className:`small text-danger`,role:`alert`,children:e.error},e.key))]})}function Ie({onSubmit:e,busy:t=!1,disabled:r=!1,maxLength:i=4e3,inputRef:a,attachments:o=[],onAttach:s,onRemoveAttachment:c,accept:l,onStop:u,editing:d=null,onCancelEdit:f,labels:p}){let m=J(p),h=b(),_=S(null),[v,x]=C(``),w=o.some(e=>e.status===`Uploading`),O=t||r||w||!v.trim();y(()=>{d&&x(d.text)},[d]);function k(){O||(e(v.trim()),x(``))}function A(e){let t=Array.from(e.target.files??[]);e.target.value=``,t.length>0&&s(t)}return/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[d&&f&&/* @__PURE__ */ D(`div`,{className:`wui-chat-editing`,children:[/* @__PURE__ */ E(`span`,{className:`small text-body-secondary`,children:m.editing}),/* @__PURE__ */ E(n,{type:`button`,size:`sm`,variant:`ghost`,onClick:f,children:m.cancel})]}),/* @__PURE__ */ E(Fe,{attachments:o,onRemove:e=>c?.(e),labels:m}),/* @__PURE__ */ D(`form`,{className:`wui-chat-composer d-flex align-items-end gap-2`,"aria-label":m.composer,onSubmit:e=>{e.preventDefault(),k()},children:[s&&/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(n,{type:`button`,variant:`ghost`,leftIcon:`paperclip`,disabled:r,"aria-describedby":`${h}-attach-hint`,onClick:()=>_.current?.click(),children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.attach})}),/* @__PURE__ */ E(`span`,{id:`${h}-attach-hint`,className:`visually-hidden`,children:m.attachHint}),/* @__PURE__ */ E(`input`,{ref:_,type:`file`,multiple:!0,accept:l,hidden:!0,onChange:A})]}),/* @__PURE__ */ E(g,{id:`${h}-message`,"aria-label":m.composer,"aria-describedby":`${h}-hint`,placeholder:m.placeholder,rows:1,autoGrow:!0,maxLength:i,value:v,disabled:r,ref:a,fieldClassName:`flex-grow-1 mb-0`,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),k())}}),/* @__PURE__ */ E(`span`,{id:`${h}-hint`,className:`visually-hidden`,children:m.composerHint}),t&&u?/* @__PURE__ */ E(n,{type:`button`,leftIcon:`stop`,onClick:u,children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.stop})}):/* @__PURE__ */ E(n,{type:`submit`,leftIcon:`send`,disabled:O,children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.send})})]})]})}function Le({client:i,onOpen:a,onDeleted:s,pageSize:c=20,labels:u}){let f=J(u),p=x(()=>we({client:i,pageSize:c}),[i,c]),h=w(p.subscribe,p.getState),[g,_]=C(null),[v,b]=C(!1),[S,T]=C(``),[k,A]=C(null),[j,M]=C(``),[N,P]=C(!1),[F,I]=C(``),[L,R]=C(void 0),[z,B]=C(``);y(()=>(p.load(),p.dispose),[p]),y(()=>{if(typeof i.getSettings!=`function`)return;let e=!0;return Promise.resolve().then(()=>i.getSettings()).then(t=>{e&&R(t.titleMaxLength)}).catch(t=>{e&&B(t?.message||f.loadFailed)}),()=>{e=!1}},[i,f.loadFailed]);async function V(){b(!0),T(``);try{await p.remove(g.publicId),s?.(g.publicId),_(null)}catch(e){T(e?.message||f.deleteFailed)}finally{b(!1)}}function H(e){N||(A(e.publicId),M(e.title||``),I(``))}function U(){A(null),I(``)}async function W(e){if(!(N||j.trim()===``)){P(!0),I(``);try{await p.rename(e,j),A(null)}catch(e){I(e?.message||f.renameFailed)}finally{P(!1)}}}let G=h.totalCount===null&&h.error===null;return!h.loading&&!G&&!h.error&&h.items.length===0?/* @__PURE__ */ E(l,{icon:`chat`,size:`sm`,title:f.conversationsEmptyTitle,text:f.conversationsEmptyText}):/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-3`,children:[h.error&&/* @__PURE__ */ E(t,{tone:`danger`,action:/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,onClick:()=>p.load(),children:f.retry}),children:h.error.message}),h.items.length>0&&/* @__PURE__ */ E(`ul`,{className:`list-unstyled d-flex flex-column gap-2 mb-0`,"aria-label":f.conversations,children:h.items.map(i=>/* @__PURE__ */ E(`li`,{children:k===i.publicId?/* @__PURE__ */ D(r,{padding:`sm`,className:`border`,bodyClassName:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ E(d,{size:`sm`,"aria-label":f.conversationTitle,fieldClassName:`flex-grow-1 mb-0`,value:j,maxLength:L,autoFocus:!0,onChange:e=>M(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),W(i.publicId)):e.key===`Escape`&&(e.preventDefault(),U())}}),/* @__PURE__ */ E(n,{variant:`primary`,size:`sm`,loading:N,disabled:N||j.trim()===``,onClick:()=>W(i.publicId),children:f.renameSave}),/* @__PURE__ */ E(n,{variant:`secondary`,size:`sm`,onClick:U,children:f.cancel})]}),(F||z)&&/* @__PURE__ */ E(t,{tone:`danger`,size:`sm`,children:F||z})]}):/* @__PURE__ */ D(r,{padding:`sm`,className:`border`,bodyClassName:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ E(n,{variant:`ghost`,className:`flex-grow-1 text-start`,style:{minWidth:0},onClick:()=>a(i),children:/* @__PURE__ */ D(`span`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ E(`span`,{className:`text-truncate fw-semibold`,children:i.title||f.untitled}),/* @__PURE__ */ E(`time`,{dateTime:i.lastMessageDateTimeUtc,className:`wui-text-xs text-body-secondary`,children:O(i.lastMessageDateTimeUtc)})]})}),/* @__PURE__ */ E(e,{icon:`edit`,label:f.renameConversation,onClick:()=>H(i)}),/* @__PURE__ */ E(e,{icon:`trash-2`,danger:!0,label:f.deleteConversation,onClick:()=>{T(``),_(i)}})]})},i.publicId))}),(h.loading||G)&&/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,"aria-hidden":`true`,children:[/* @__PURE__ */ E(m,{height:44}),/* @__PURE__ */ E(m,{height:44}),/* @__PURE__ */ E(m,{height:44})]}),!h.loading&&h.hasMore&&/* @__PURE__ */ E(n,{variant:`secondary`,className:`align-self-center`,onClick:()=>p.loadMore(),children:f.loadMore}),/* @__PURE__ */ E(o,{open:g!==null,title:f.deleteConfirmTitle,message:S?/* @__PURE__ */ E(t,{tone:`danger`,children:S}):f.deleteConfirmMessage,confirmLabel:f.deleteConfirm,cancelLabel:f.cancel,danger:!0,loading:v,onConfirm:V,onClose:()=>{v||_(null)}})]})}var Re={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},ze={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function Be({onClick:e,open:t=!1,position:r=`end`,icon:i=`sparkles`,compact:a=!1,className:o,style:s,labels:c}){let l=J(c);return a?/* @__PURE__ */ E(Ve,{onClick:e,open:t,position:r,icon:i,className:o,style:s,label:l.launcher}):/* @__PURE__ */ E(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Re,...ze[r],...s},children:/* @__PURE__ */ E(n,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:l.launcher})})}function Ve({onClick:e,open:t,position:r,icon:i,className:a,style:o,label:s}){let c=_(r);return c?k(/* @__PURE__ */ E(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:/* @__PURE__ */ E(n,{className:`wui-floating-btn`,onClick:e,"aria-label":s,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:s,tooltipPlacement:r===`start`?`end`:`start`,children:/* @__PURE__ */ E(u,{name:i,size:24})})}),c):null}function He({text:e,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a}){return/* @__PURE__ */ E(f,{value:e,links:`app`,headings:`text`,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a})}function Ue({rating:e,onRate:r,noteMaxLength:i=1e3,labels:a}){let o=J(a),s=b(),[c,l]=C(!1),[u,d]=C(!1),[f,p]=C(``),[m,h]=C(``),[_,v]=C(!1);async function y(e,t){l(!0),h(``);try{await r(e,t),d(e===`Down`&&t===void 0),v(e===`Up`||t!==void 0),t!==void 0&&p(``)}catch{h(o.ratingFailed)}finally{l(!1)}}return/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap align-items-center gap-1`,children:[/* @__PURE__ */ E(n,{size:`sm`,variant:e===`Up`?`neutral`:`ghost`,leftIcon:`check`,"aria-pressed":e===`Up`,disabled:c,onClick:()=>y(`Up`),children:o.rateUp}),/* @__PURE__ */ E(n,{size:`sm`,variant:e===`Down`?`neutral`:`ghost`,leftIcon:`x`,"aria-pressed":e===`Down`,disabled:c,onClick:()=>y(`Down`),children:o.rateDown}),_&&!u&&/* @__PURE__ */ E(`span`,{className:`wui-text-xs text-body-secondary`,role:`status`,children:o.rated})]}),m&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:m}),u&&/* @__PURE__ */ D(`form`,{className:`d-flex flex-column gap-2`,onSubmit:e=>{e.preventDefault(),y(`Down`,f)},children:[/* @__PURE__ */ E(g,{id:`${s}-note`,label:o.ratingNote,hint:o.ratingNoteHint,rows:2,maxLength:i,value:f,onChange:e=>p(e.target.value)}),/* @__PURE__ */ D(`div`,{className:`d-flex gap-2`,children:[/* @__PURE__ */ E(n,{type:`submit`,size:`sm`,loading:c,children:o.ratingNoteSend}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>{d(!1),v(!0)},children:o.ratingNoteSkip})]})]})]})}var We={maxWidth:`85%`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function Ge({turn:a,onRate:o,onRetry:c,onRegenerate:l,canRegenerate:u,onEdit:d,onOpenAttachment:f,resolveLink:p,linkComponent:m,isCitation:g,onOpenCitation:_,onAskSuggestion:v,confirmAction:y,onViewTicket:b,renderReply:x,labels:S}){let C=J(S),w=a.streaming&&!a.answer,T=!!a.answer&&!a.streaming,O=a.step?C.toolStep(a.step):C.thinking;return/* @__PURE__ */ D(`li`,{className:`d-flex flex-column gap-2`,children:[a.question&&/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-1 align-self-end`,children:[d&&a.questionId&&/* @__PURE__ */ E(e,{icon:`edit`,label:C.edit,onClick:()=>d(a.id)}),/* @__PURE__ */ D(`div`,{style:We,children:[/* @__PURE__ */ D(`span`,{className:`visually-hidden`,children:[C.you,`: `]}),/* @__PURE__ */ D(r,{padding:`sm`,variant:`muted`,className:`wui-text-sm`,children:[a.question,a.attachments?.length>0&&/* @__PURE__ */ E(`div`,{className:`wui-chat-question-attachments mt-2`,children:a.attachments.map(e=>/* @__PURE__ */ E(i,{label:e.fileName,leadingIcon:`document`,onClick:f?()=>f(e):void 0},e.publicId))})]})]})]}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,style:{minWidth:0},children:[/* @__PURE__ */ D(`span`,{className:`visually-hidden`,children:[C.assistant,`: `]}),/* @__PURE__ */ E(`div`,{"aria-live":`polite`,"aria-busy":a.streaming,children:a.stopped?/* @__PURE__ */ E(t,{size:`sm`,tone:`neutral`,children:C.stopped}):w?/* @__PURE__ */ D(`span`,{className:`d-inline-flex align-items-center gap-2 wui-text-sm text-body-secondary`,children:[/* @__PURE__ */ E(h,{size:`sm`,label:O}),/* @__PURE__ */ E(`span`,{"aria-hidden":`true`,children:O})]}):a.answer&&(x?x(a,{streaming:!!a.streaming}):/* @__PURE__ */ E(He,{text:a.answer,resolveLink:p,linkComponent:m,isCitation:g,onOpenCitation:_}))}),a.error&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:a.error.message}),c&&(a.error||a.stopped)&&/* @__PURE__ */ E(`div`,{children:/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,onClick:()=>c(a.id),children:C.retry})}),y&&!a.streaming&&a.actions.map(e=>/* @__PURE__ */ E(Pe,{action:e,confirmAction:y,onViewTicket:b,labels:S},e.token)),(T||o&&a.messageId&&!a.streaming)&&/* @__PURE__ */ D(`div`,{className:`wui-chat-turn-actions align-items-center`,children:[T&&/* @__PURE__ */ E(s,{text:de(a.answer),label:C.copy,copiedLabel:C.copied,iconOnly:!0,size:`sm`,variant:`ghost`}),o&&a.messageId&&!a.streaming&&/* @__PURE__ */ E(Ue,{rating:a.rating,onRate:(e,t)=>o(a.id,e,t),labels:S}),l&&u&&T&&/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,leftIcon:`refresh`,onClick:()=>l(a.id),children:C.regenerate})]}),v&&!a.streaming&&a.suggestions.length>0&&/* @__PURE__ */ E(`div`,{className:`wui-chat-suggestions`,role:`group`,"aria-label":C.suggestions,children:a.suggestions.map(e=>/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,onClick:()=>v(e),children:e},e))})]})]})}var Ke=v(Ge);function qe(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Je({turns:e,empty:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:c,onRegenerate:u,onAskSuggestion:d,isCitation:f,onOpenCitation:p,onEdit:m,onOpenAttachment:h,labels:g}){let _=J(g),v=S(null),b=e[e.length-1];return y(()=>{let e=qe(v.current);e&&(e.scrollTop=e.scrollHeight)},[e.length,b?.answer,b?.error,b?.actions]),e.length===0?t??/* @__PURE__ */ E(l,{icon:`sparkles`,size:`sm`,title:_.emptyTitle,text:_.emptyText}):/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":_.thread,children:e.map((t,l)=>/* @__PURE__ */ E(Ke,{turn:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:l===e.length-1?c:void 0,onRegenerate:u,onAskSuggestion:l===e.length-1?d:void 0,isCitation:f,onOpenCitation:p,canRegenerate:l===e.length-1,onEdit:m,onOpenAttachment:h,labels:g},t.id))}),/* @__PURE__ */ E(`div`,{ref:v})]})}function Ye({chat:n,open:r,onClose:i,title:a,titleIcon:o=`sparkles`,headerActions:s,empty:l,disclaimer:d,maxLength:f=4e3,allowanceThreshold:p=10,width:m=`440px`,resolveLink:g,linkComponent:_,confirmAction:v,onViewTicket:b,rating:x=!0,renderReply:w,openAttachment:O,conversations:k=!1,isCitation:A,onOpenCitation:j,labels:M}){let N=J(M),P=S(null),{refreshAllowance:F}=n,I=n.settings?.attachments,L=I?.contentTypes.join(`,`),[R,z]=C(`chat`);y(()=>{r&&F().catch(()=>{})},[r,F]),y(()=>{r||z(`chat`)},[r]);let B=n.messagesLeftToday,V=a??N.panelTitle,H=k&&R===`conversations`,U=/* @__PURE__ */ D(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ D(`div`,{className:`drawer-title`,children:[o&&/* @__PURE__ */ E(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ E(u,{name:o,size:18})}),V]}),/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-1`,children:[s,H?/* @__PURE__ */ E(e,{icon:`arrow-left`,label:N.backToChat,onClick:()=>z(`chat`)}):/* @__PURE__ */ D(T,{children:[k&&/* @__PURE__ */ E(e,{icon:`history`,label:N.conversations,onClick:()=>z(`conversations`)}),/* @__PURE__ */ E(e,{icon:`plus`,label:N.newChat,onClick:n.newConversation,disabled:n.turns.length===0&&!n.loading})]}),/* @__PURE__ */ E(e,{icon:`x`,label:N.close,onClick:i})]})]}),W=/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[B!==null&&B<=p&&/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,role:`status`,children:N.allowance(B)}),n.settingsError&&/* @__PURE__ */ E(t,{tone:`danger`,children:n.settingsError.message}),/* @__PURE__ */ E(Ie,{onSubmit:n.submit,busy:n.streaming||n.loading,disabled:B===0,maxLength:f,inputRef:P,attachments:n.attachments,onAttach:I?n.attach:void 0,onRemoveAttachment:n.removeAttachment,accept:L,onStop:n.streaming?n.stop:void 0,editing:n.editing,onCancelEdit:n.cancelEdit,labels:M}),/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:d??N.disclaimer})]});return/* @__PURE__ */ E(c,{open:r,onClose:i,sheet:!1,width:m,header:U,footer:H?void 0:W,ariaLabel:typeof V==`string`?V:N.panelTitle,onOpened:()=>P.current?.focus(),children:H?/* @__PURE__ */ E(Le,{client:n.client,onOpen:e=>{n.openConversation(e.publicId),z(`chat`)},onDeleted:e=>{e===n.conversationId&&n.newConversation()},labels:M}):n.loading?/* @__PURE__ */ E(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ E(h,{label:N.loadingConversation})}):n.loadError?/* @__PURE__ */ E(t,{tone:`danger`,children:n.loadError.message}):/* @__PURE__ */ E(Je,{turns:n.turns,empty:l,onRate:x?n.rate:void 0,onRetry:n.retry,onRegenerate:n.regenerate,onAskSuggestion:n.submit,isCitation:A,onOpenCitation:j,onEdit:n.startEdit,onOpenAttachment:O,resolveLink:g,linkComponent:_,confirmAction:v,onViewTicket:b,renderReply:w,labels:M})})}function Xe({citation:e,label:t,ariaLabel:n,onOpen:r}){return/* @__PURE__ */ E(i,{label:t??e,size:`sm`,tone:`primary`,variant:`outline`,leadingIcon:`book-1`,"aria-label":n??e,onClick:()=>r(e)})}function Ze({title:e,subtitle:i,lines:a,note:o,onConfirm:s,labels:c}){let l=J(c),[u,d]=C(`ready`),[f,p]=C(null),[m,h]=C(``);if(u===`dismissed`)return/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:l.actionDismissed});if(u===`done`)return/* @__PURE__ */ E(t,{tone:`success`,role:`status`,size:`sm`,children:f?.message||l.actionDone});async function g(){d(`sending`),h(``);try{let e=await s();p(e??null),d(`done`)}catch(e){h(e?.message||l.actionFailed),d(`ready`)}}let _=u===`sending`;return/* @__PURE__ */ E(r,{padding:`sm`,className:`border`,title:e,subtitle:i||void 0,children:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[(a??[]).map((e,t)=>/* @__PURE__ */ E(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e},t)),/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:o??l.actionNote}),m&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:m}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ E(n,{size:`sm`,loading:_,onClick:g,children:l.actionConfirm}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:_,onClick:()=>d(`dismissed`),children:l.actionDismiss})]})]})})}function Qe({client:e,pageContext:t}){let n=S(t);n.current=t;let r=x(()=>je({client:e,pageContext:()=>n.current}),[e]);y(()=>()=>r.dispose(),[r]);let i=w(r.subscribe,r.getState),a=x(()=>({submit:e=>r.submit(e),stop:()=>r.stop(),retry:e=>r.retry(e),regenerate:e=>r.regenerate(e),startEdit:e=>r.startEdit(e),cancelEdit:()=>r.cancelEdit(),attach:e=>r.attach(e),removeAttachment:e=>r.removeAttachment(e),openConversation:e=>r.openConversation(e),newConversation:()=>r.newConversation(),rate:(e,t,n)=>r.rate(e,t,n),refreshAllowance:()=>r.refreshAllowance(),reset:()=>r.reset()}),[r]);return{...i,...a,client:r.client}}export{Pe as ActionCard,pe as CHAT_CONTRACT_VERSION,X as ChatApiError,Ie as ChatComposer,Le as ChatConversationList,Be as ChatLauncher,He as ChatMarkdown,Ke as ChatMessage,Ye as ChatPanel,Je as ChatThread,Xe as CitationChip,Ze as ConfirmCard,q as DEFAULT_CHAT_LABELS,Ue as ReplyRating,xe as createChatClient,je as createChatSession,we as createConversationList,fe as createSseParser,J as mergeLabels,j as splitCitations,Qe as useChat};
|
package/dist/guidance.json
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* conversation) still shows what was offered, without a button that could only fail.
|
|
6
6
|
*
|
|
7
7
|
* @param {object} props
|
|
8
|
-
* @param {import('@webority/
|
|
8
|
+
* @param {import('@webority/markdown-core/chat').SupportAction} props.action
|
|
9
9
|
* @param {(token: string) => Promise<{ id: string, number: string }>} props.confirmAction Sends the
|
|
10
10
|
* person's yes, e.g. `supportClient.confirmAction`; resolves to the ticket raised, replied on or
|
|
11
11
|
* reopened. A rejection's `message` is shown when present.
|
|
12
12
|
* @param {(ticket: { id: string, number: string }) => void} [props.onViewTicket] Shows a View
|
|
13
13
|
* ticket button once confirmed.
|
|
14
|
-
* @param {Partial<typeof import('@webority/
|
|
14
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
15
15
|
*/
|
|
16
16
|
export default function ActionCard({ action, confirmAction, onViewTicket, labels: labelOverrides }: {
|
|
17
|
-
action: import('@webority/
|
|
17
|
+
action: import('@webority/markdown-core/chat').SupportAction;
|
|
18
18
|
confirmAction: (token: string) => Promise<{
|
|
19
19
|
id: string;
|
|
20
20
|
number: string;
|
|
@@ -23,5 +23,5 @@ export default function ActionCard({ action, confirmAction, onViewTicket, labels
|
|
|
23
23
|
id: string;
|
|
24
24
|
number: string;
|
|
25
25
|
}) => void;
|
|
26
|
-
labels?: Partial<typeof import('@webority/
|
|
26
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
27
27
|
}): import("react").JSX.Element;
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
* @param {boolean} [props.disabled]
|
|
11
11
|
* @param {number} [props.maxLength]
|
|
12
12
|
* @param {import('react').Ref<HTMLTextAreaElement>} [props.inputRef] The question box, for focusing it.
|
|
13
|
-
* @param {import('@webority/
|
|
13
|
+
* @param {import('@webority/markdown-core/chat').ComposerAttachment[]} [props.attachments]
|
|
14
14
|
* @param {(files: File[]) => unknown} [props.onAttach] Shows the attach button; called with the picked files.
|
|
15
15
|
* @param {(key: string) => unknown} [props.onRemoveAttachment] Called with an attachment's key.
|
|
16
16
|
* @param {string} [props.accept] The file types the picker offers, as an `accept` string.
|
|
17
17
|
* @param {() => unknown} [props.onStop] Shows Stop in place of Send while busy.
|
|
18
18
|
* @param {{ text: string } | null} [props.editing] When set, the box takes its text and shows the editing notice.
|
|
19
19
|
* @param {() => unknown} [props.onCancelEdit] Shows the Cancel button beside the editing notice.
|
|
20
|
-
* @param {Partial<typeof import('@webority/
|
|
20
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
21
21
|
*/
|
|
22
22
|
export default function ChatComposer({ onSubmit, busy, disabled, maxLength, inputRef, attachments, onAttach, onRemoveAttachment, accept, onStop, editing, onCancelEdit, labels: labelOverrides, }: {
|
|
23
23
|
onSubmit: (message: string) => unknown;
|
|
@@ -25,7 +25,7 @@ export default function ChatComposer({ onSubmit, busy, disabled, maxLength, inpu
|
|
|
25
25
|
disabled?: boolean;
|
|
26
26
|
maxLength?: number;
|
|
27
27
|
inputRef?: import('react').Ref<HTMLTextAreaElement>;
|
|
28
|
-
attachments?: import('@webority/
|
|
28
|
+
attachments?: import('@webority/markdown-core/chat').ComposerAttachment[];
|
|
29
29
|
onAttach?: (files: File[]) => unknown;
|
|
30
30
|
onRemoveAttachment?: (key: string) => unknown;
|
|
31
31
|
accept?: string;
|
|
@@ -34,5 +34,5 @@ export default function ChatComposer({ onSubmit, busy, disabled, maxLength, inpu
|
|
|
34
34
|
text: string;
|
|
35
35
|
} | null;
|
|
36
36
|
onCancelEdit?: () => unknown;
|
|
37
|
-
labels?: Partial<typeof import('@webority/
|
|
37
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
38
38
|
}): import("react").JSX.Element;
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* more, opens one through `onOpen`, renames one in place, and deletes one after a confirm.
|
|
4
4
|
*
|
|
5
5
|
* @param {object} props
|
|
6
|
-
* @param {import('@webority/
|
|
7
|
-
* @param {(conversation: import('@webority/
|
|
6
|
+
* @param {import('@webority/markdown-core/chat').ChatClient} props.client
|
|
7
|
+
* @param {(conversation: import('@webority/markdown-core/chat').ConversationSummary) => void} props.onOpen
|
|
8
8
|
* E.g. open the panel and call `chat.openConversation(conversation.publicId)`.
|
|
9
9
|
* @param {(id: string) => void} [props.onDeleted] Called after a chat is deleted, e.g. to start a
|
|
10
10
|
* new chat when the open one was deleted.
|
|
11
11
|
* @param {number} [props.pageSize]
|
|
12
|
-
* @param {Partial<typeof import('@webority/
|
|
12
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
13
13
|
*/
|
|
14
14
|
export default function ChatConversationList({ client, onOpen, onDeleted, pageSize, labels: labelOverrides }: {
|
|
15
|
-
client: import('@webority/
|
|
16
|
-
onOpen: (conversation: import('@webority/
|
|
15
|
+
client: import('@webority/markdown-core/chat').ChatClient;
|
|
16
|
+
onOpen: (conversation: import('@webority/markdown-core/chat').ConversationSummary) => void;
|
|
17
17
|
onDeleted?: (id: string) => void;
|
|
18
18
|
pageSize?: number;
|
|
19
|
-
labels?: Partial<typeof import('@webority/
|
|
19
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
20
20
|
}): import("react").JSX.Element;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* @param {boolean} [props.compact]
|
|
18
18
|
* @param {string} [props.className]
|
|
19
19
|
* @param {import('react').CSSProperties} [props.style] Merged over the wrapper's own style.
|
|
20
|
-
* @param {Partial<typeof import('@webority/
|
|
20
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
21
21
|
*/
|
|
22
22
|
export default function ChatLauncher({ onClick, open, position, icon, compact, className, style, labels: labelOverrides, }: {
|
|
23
23
|
onClick: () => void;
|
|
@@ -27,5 +27,5 @@ export default function ChatLauncher({ onClick, open, position, icon, compact, c
|
|
|
27
27
|
compact?: boolean;
|
|
28
28
|
className?: string;
|
|
29
29
|
style?: import('react').CSSProperties;
|
|
30
|
-
labels?: Partial<typeof import('@webority/
|
|
30
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
31
31
|
}): import("react").JSX.Element;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* marked busy. Support actions show under the answer, and the rating once the reply is stored.
|
|
5
5
|
*
|
|
6
6
|
* @param {object} props
|
|
7
|
-
* @param {import('@webority/
|
|
7
|
+
* @param {import('@webority/markdown-core/chat').ChatTurn} props.turn
|
|
8
8
|
* @param {(turnId: string, rating: "Up"|"Down", note?: string) => Promise<unknown>} [props.onRate]
|
|
9
9
|
* Shows the rating under a stored reply.
|
|
10
10
|
* @param {(turnId: string) => void} [props.onRetry] Offers "Try again" under a failed or stopped turn.
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
* @param {(token: string) => Promise<{ id: string, number: string }>} [props.confirmAction] Shows
|
|
22
22
|
* support action cards; see `ActionCard`.
|
|
23
23
|
* @param {(ticket: { id: string, number: string }) => void} [props.onViewTicket]
|
|
24
|
-
* @param {(turn: import('@webority/
|
|
24
|
+
* @param {(turn: import('@webority/markdown-core/chat').ChatTurn, state: { streaming: boolean }) => import('react').ReactNode} [props.renderReply]
|
|
25
25
|
* Draws the assistant's answer in place of `ChatMarkdown` (charts, maths). The question, action
|
|
26
26
|
* cards, rating and layout stay the library's.
|
|
27
|
-
* @param {Partial<import('@webority/
|
|
27
|
+
* @param {Partial<import('@webority/markdown-core/chat').ChatLabels>} [props.labels]
|
|
28
28
|
*/
|
|
29
29
|
declare function ChatMessage({ turn, onRate, onRetry, onRegenerate, canRegenerate, onEdit, onOpenAttachment, resolveLink, linkComponent, isCitation, onOpenCitation, onAskSuggestion, confirmAction, onViewTicket, renderReply, labels: labelOverrides, }: {
|
|
30
|
-
turn: import('@webority/
|
|
30
|
+
turn: import('@webority/markdown-core/chat').ChatTurn;
|
|
31
31
|
onRate?: (turnId: string, rating: "Up" | "Down", note?: string) => Promise<unknown>;
|
|
32
32
|
onRetry?: (turnId: string) => void;
|
|
33
33
|
onRegenerate?: (turnId: string) => void;
|
|
@@ -52,10 +52,10 @@ declare function ChatMessage({ turn, onRate, onRetry, onRegenerate, canRegenerat
|
|
|
52
52
|
id: string;
|
|
53
53
|
number: string;
|
|
54
54
|
}) => void;
|
|
55
|
-
renderReply?: (turn: import('@webority/
|
|
55
|
+
renderReply?: (turn: import('@webority/markdown-core/chat').ChatTurn, state: {
|
|
56
56
|
streaming: boolean;
|
|
57
57
|
}) => import('react').ReactNode;
|
|
58
|
-
labels?: Partial<import('@webority/
|
|
58
|
+
labels?: Partial<import('@webority/markdown-core/chat').ChatLabels>;
|
|
59
59
|
}): import("react").JSX.Element;
|
|
60
60
|
declare const _default: import("react").MemoExoticComponent<typeof ChatMessage>;
|
|
61
61
|
export default _default;
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* @param {boolean} [props.conversations=false] Offers the person's past chats from a header icon.
|
|
34
34
|
* @param {(inner: string) => boolean} [props.isCitation] Passed to `ChatThread`; see `ChatMarkdown`.
|
|
35
35
|
* @param {(citation: string) => void} [props.onOpenCitation] Passed to `ChatThread`; see `ChatMarkdown`.
|
|
36
|
-
* @param {Partial<typeof import('@webority/
|
|
36
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
37
37
|
*/
|
|
38
38
|
export default function ChatPanel({ chat, open, onClose, title, titleIcon, headerActions, empty, disclaimer, maxLength, allowanceThreshold, width, resolveLink, linkComponent, confirmAction, onViewTicket, rating, renderReply, openAttachment, conversations, isCitation, onOpenCitation, labels: labelOverrides, }: {
|
|
39
39
|
chat: ReturnType<typeof import('../useChat.js').useChat>;
|
|
@@ -70,5 +70,5 @@ export default function ChatPanel({ chat, open, onClose, title, titleIcon, heade
|
|
|
70
70
|
conversations?: boolean;
|
|
71
71
|
isCitation?: (inner: string) => boolean;
|
|
72
72
|
onOpenCitation?: (citation: string) => void;
|
|
73
|
-
labels?: Partial<typeof import('@webority/
|
|
73
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
74
74
|
}): import("react").JSX.Element;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* @param {(citation: string) => void} [props.onOpenCitation] Passed to `ChatMessage`; see `ChatMarkdown`.
|
|
20
20
|
* @param {(turnId: string) => void} [props.onEdit]
|
|
21
21
|
* @param {(attachment: { publicId: string, fileName: string, contentType: string, length: number }) => void} [props.onOpenAttachment]
|
|
22
|
-
* @param {Partial<typeof import('@webority/
|
|
22
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
23
23
|
*/
|
|
24
24
|
export default function ChatThread({ turns, empty, onRate, resolveLink, linkComponent, confirmAction, onViewTicket, renderReply, onRetry, onRegenerate, onAskSuggestion, isCitation, onOpenCitation, onEdit, onOpenAttachment, labels: labelOverrides, }: {
|
|
25
25
|
turns: import('../useChat.js').ChatTurn[];
|
|
@@ -50,5 +50,5 @@ export default function ChatThread({ turns, empty, onRate, resolveLink, linkComp
|
|
|
50
50
|
contentType: string;
|
|
51
51
|
length: number;
|
|
52
52
|
}) => void;
|
|
53
|
-
labels?: Partial<typeof import('@webority/
|
|
53
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
54
54
|
}): string | number | bigint | boolean | import("react").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined>;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* error, so the person can remove it.
|
|
4
4
|
*
|
|
5
5
|
* @param {object} props
|
|
6
|
-
* @param {import('@webority/
|
|
6
|
+
* @param {import('@webority/markdown-core/chat').ComposerAttachment[]} props.attachments
|
|
7
7
|
* @param {(key: string) => unknown} props.onRemove Called with the attachment key.
|
|
8
|
-
* @param {import('@webority/
|
|
8
|
+
* @param {import('@webority/markdown-core/chat').ChatLabels} props.labels The merged labels.
|
|
9
9
|
*/
|
|
10
10
|
export default function ComposerAttachments({ attachments, onRemove, labels }: {
|
|
11
|
-
attachments: import('@webority/
|
|
11
|
+
attachments: import('@webority/markdown-core/chat').ComposerAttachment[];
|
|
12
12
|
onRemove: (key: string) => unknown;
|
|
13
|
-
labels: import('@webority/
|
|
13
|
+
labels: import('@webority/markdown-core/chat').ChatLabels;
|
|
14
14
|
}): import("react").JSX.Element | null;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @param {string} [props.note]
|
|
11
11
|
* @param {() => Promise<{ message?: string } | void>} props.onConfirm Sends the person's yes; resolves to
|
|
12
12
|
* an optional message for the done state. A rejection's `message` is shown when present.
|
|
13
|
-
* @param {Partial<typeof import('@webority/
|
|
13
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
14
14
|
*/
|
|
15
15
|
export default function ConfirmCard({ title, subtitle, lines, note, onConfirm, labels: labelsProp }: {
|
|
16
16
|
title: string;
|
|
@@ -20,5 +20,5 @@ export default function ConfirmCard({ title, subtitle, lines, note, onConfirm, l
|
|
|
20
20
|
onConfirm: () => Promise<{
|
|
21
21
|
message?: string;
|
|
22
22
|
} | void>;
|
|
23
|
-
labels?: Partial<typeof import('@webority/
|
|
23
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
24
24
|
}): import("react").JSX.Element;
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* @param {"Up"|"Down"|null} [props.rating]
|
|
7
7
|
* @param {(rating: "Up"|"Down", note?: string) => Promise<unknown>} props.onRate Rejects on failure.
|
|
8
8
|
* @param {number} [props.noteMaxLength]
|
|
9
|
-
* @param {Partial<typeof import('@webority/
|
|
9
|
+
* @param {Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>} [props.labels]
|
|
10
10
|
*/
|
|
11
11
|
export default function ReplyRating({ rating, onRate, noteMaxLength, labels: labelOverrides }: {
|
|
12
12
|
rating?: "Up" | "Down" | null;
|
|
13
13
|
onRate: (rating: "Up" | "Down", note?: string) => Promise<unknown>;
|
|
14
14
|
noteMaxLength?: number;
|
|
15
|
-
labels?: Partial<typeof import('@webority/
|
|
15
|
+
labels?: Partial<typeof import('@webority/markdown-core/chat').DEFAULT_CHAT_LABELS>;
|
|
16
16
|
}): import("react").JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CHAT_CONTRACT_VERSION, ChatApiError, createChatClient, createChatSession, createConversationList, createSseParser, DEFAULT_CHAT_LABELS, mergeLabels, } from "@webority/chat-core";
|
|
2
1
|
export { splitCitations } from "@webority/markdown-core";
|
|
2
|
+
export { CHAT_CONTRACT_VERSION, ChatApiError, createChatClient, createChatSession, createConversationList, createSseParser, DEFAULT_CHAT_LABELS, mergeLabels, } from "@webority/markdown-core/chat";
|
|
3
3
|
export { default as ActionCard } from "./components/ActionCard.jsx";
|
|
4
4
|
export { default as ChatComposer } from "./components/ChatComposer.jsx";
|
|
5
5
|
export { default as ChatConversationList } from "./components/ChatConversationList.jsx";
|
package/dist/types/useChat.d.ts
CHANGED
|
@@ -6,41 +6,41 @@ export type ChatTurnError = {
|
|
|
6
6
|
message: string;
|
|
7
7
|
resetsAtUtc: string | null;
|
|
8
8
|
};
|
|
9
|
-
export type ChatTurn = import('@webority/
|
|
9
|
+
export type ChatTurn = import('@webority/markdown-core/chat').ChatTurn;
|
|
10
10
|
/**
|
|
11
11
|
* @typedef {object} ChatTurnError
|
|
12
12
|
* @property {string} code
|
|
13
13
|
* @property {string} message Written for the person.
|
|
14
14
|
* @property {string|null} resetsAtUtc
|
|
15
15
|
*/
|
|
16
|
-
/** @typedef {import('@webority/
|
|
16
|
+
/** @typedef {import('@webority/markdown-core/chat').ChatTurn} ChatTurn One question and its answer. */
|
|
17
17
|
/**
|
|
18
18
|
* The chat's state and actions. The session lives in the component that calls it: one per client,
|
|
19
19
|
* disposed when the client changes or the component unmounts. Call `reset()` when the signed-in
|
|
20
20
|
* person or account changes so nothing of one person's chat shows to the next.
|
|
21
21
|
*
|
|
22
22
|
* @param {object} options
|
|
23
|
-
* @param {import('@webority/
|
|
23
|
+
* @param {import('@webority/markdown-core/chat').ChatClient} options.client From `createChatClient`.
|
|
24
24
|
* @param {any} [options.pageContext] Sent with each question; read at the moment of sending.
|
|
25
25
|
* @returns {{
|
|
26
|
-
* client: import('@webority/
|
|
26
|
+
* client: import('@webority/markdown-core/chat').ChatClient,
|
|
27
27
|
* turns: ChatTurn[],
|
|
28
28
|
* conversationId: string|null,
|
|
29
29
|
* messagesLeftToday: number|null,
|
|
30
30
|
* streaming: boolean,
|
|
31
31
|
* loading: boolean,
|
|
32
32
|
* loadError: ChatTurnError|null,
|
|
33
|
-
* settings: import('@webority/
|
|
33
|
+
* settings: import('@webority/markdown-core/chat').ChatSettings|null,
|
|
34
34
|
* settingsError: ChatTurnError|null,
|
|
35
|
-
* editing: import('@webority/
|
|
36
|
-
* attachments: import('@webority/
|
|
35
|
+
* editing: import('@webority/markdown-core/chat').ChatEditing|null,
|
|
36
|
+
* attachments: import('@webority/markdown-core/chat').ComposerAttachment[],
|
|
37
37
|
* submit: (message: string) => Promise<void>,
|
|
38
38
|
* stop: () => void,
|
|
39
39
|
* retry: (turnId: string) => Promise<void>,
|
|
40
40
|
* regenerate: (turnId: string) => Promise<void>,
|
|
41
41
|
* startEdit: (turnId: string) => void,
|
|
42
42
|
* cancelEdit: () => void,
|
|
43
|
-
* attach: (files: import('@webority/
|
|
43
|
+
* attach: (files: import('@webority/markdown-core/chat').ChatUploadFile[]) => Promise<void>,
|
|
44
44
|
* removeAttachment: (key: string) => Promise<void>,
|
|
45
45
|
* openConversation: (id: string) => Promise<void>,
|
|
46
46
|
* newConversation: () => void,
|
|
@@ -50,27 +50,27 @@ export type ChatTurn = import('@webority/chat-core').ChatTurn;
|
|
|
50
50
|
* }}
|
|
51
51
|
*/
|
|
52
52
|
export declare function useChat({ client, pageContext }: {
|
|
53
|
-
client: import('@webority/
|
|
53
|
+
client: import('@webority/markdown-core/chat').ChatClient;
|
|
54
54
|
pageContext?: any;
|
|
55
55
|
}): {
|
|
56
|
-
client: import('@webority/
|
|
56
|
+
client: import('@webority/markdown-core/chat').ChatClient;
|
|
57
57
|
turns: ChatTurn[];
|
|
58
58
|
conversationId: string | null;
|
|
59
59
|
messagesLeftToday: number | null;
|
|
60
60
|
streaming: boolean;
|
|
61
61
|
loading: boolean;
|
|
62
62
|
loadError: ChatTurnError | null;
|
|
63
|
-
settings: import('@webority/
|
|
63
|
+
settings: import('@webority/markdown-core/chat').ChatSettings | null;
|
|
64
64
|
settingsError: ChatTurnError | null;
|
|
65
|
-
editing: import('@webority/
|
|
66
|
-
attachments: import('@webority/
|
|
65
|
+
editing: import('@webority/markdown-core/chat').ChatEditing | null;
|
|
66
|
+
attachments: import('@webority/markdown-core/chat').ComposerAttachment[];
|
|
67
67
|
submit: (message: string) => Promise<void>;
|
|
68
68
|
stop: () => void;
|
|
69
69
|
retry: (turnId: string) => Promise<void>;
|
|
70
70
|
regenerate: (turnId: string) => Promise<void>;
|
|
71
71
|
startEdit: (turnId: string) => void;
|
|
72
72
|
cancelEdit: () => void;
|
|
73
|
-
attach: (files: import('@webority/
|
|
73
|
+
attach: (files: import('@webority/markdown-core/chat').ChatUploadFile[]) => Promise<void>;
|
|
74
74
|
removeAttachment: (key: string) => Promise<void>;
|
|
75
75
|
openConversation: (id: string) => Promise<void>;
|
|
76
76
|
newConversation: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/chat-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.0",
|
|
4
4
|
"description": "Webority AI assistant for React portals: a streaming chat client, a store-agnostic chat hook, and the launcher, panel, thread, rating and support action card, built on @webority/ui-react.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,12 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@webority/
|
|
31
|
-
"@webority/markdown-core": "0.124.0"
|
|
30
|
+
"@webority/markdown-core": "0.125.0"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
34
|
-
"@webority/ui-elements": "0.
|
|
35
|
-
"@webority/ui-react": "0.
|
|
33
|
+
"@webority/ui-elements": "0.125.0",
|
|
34
|
+
"@webority/ui-react": "0.125.0",
|
|
36
35
|
"bootstrap": "5.3.3",
|
|
37
36
|
"react": "^19.0.0",
|
|
38
37
|
"react-bootstrap": "^2.10.0",
|
|
@@ -46,9 +45,9 @@
|
|
|
46
45
|
"@types/react": "^19.2.17",
|
|
47
46
|
"@vitejs/plugin-react": "^6.0.1",
|
|
48
47
|
"@vitest/coverage-v8": "5.0.1",
|
|
49
|
-
"@webority/canvas-kit": "0.
|
|
50
|
-
"@webority/ui-elements": "0.
|
|
51
|
-
"@webority/ui-react": "0.
|
|
48
|
+
"@webority/canvas-kit": "0.125.0",
|
|
49
|
+
"@webority/ui-elements": "0.125.0",
|
|
50
|
+
"@webority/ui-react": "0.125.0",
|
|
52
51
|
"bootstrap": "5.3.3",
|
|
53
52
|
"jsdom": "30.1.1",
|
|
54
53
|
"react": "^19.2.6",
|