@webority/chat-core 0.159.6 → 0.161.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/dist/client.js +1 -1
- package/dist/contract.js +1 -1
- package/dist/decode/parts.js +1 -1
- package/dist/index.js +1 -1
- package/dist/links.js +1 -1
- package/dist/look.js +1 -1
- package/dist/session.js +2 -2
- package/dist/types/contract.d.ts +10 -1
- package/dist/types/decode/parts.d.ts +2 -1
- package/dist/types/links.d.ts +2 -0
- package/dist/types/look.d.ts +16 -2
- package/package.json +3 -3
package/dist/client.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import"./contract.js";import{decodeChatConversationSummaryPage as e,decodeChatConversationView as t}from"./decode/messages.js";import{ChatDecodeError as n,array as r,arrayBuffer as i}from"./decode/primitives.js";import{decodeChatProfileView as a}from"./decode/profile.js";import{decodeChatActionView as o,decodeChatAttachment as s,decodeChatOpenTicket as c,decodeChatSpeechToken as l}from"./decode/replies.js";import{asRecord as u,isRecord as d}from"./guards.js";import{DEFAULT_CHAT_LABELS as f}from"./labels.js";import{runtime as p}from"./runtime.js";import{createStreamReader as m}from"./stream.js";var h=class extends Error{code;status;resetsDateTimeUtc;errors;constructor(e,t){super(t.message,`cause`in t?{cause:t.cause}:void 0),this.name=`ChatApiError`,this.code=e,this.status=t.status,this.resetsDateTimeUtc=t.resetsDateTimeUtc??null,this.errors=t.errors??null}},g=e=>{if(!d(e))return null;let t={errors:e.errors};return typeof e.code==`string`&&(t.code=e.code),typeof e.detail==`string`&&(t.detail=e.detail),typeof e.resetsDateTimeUtc==`string`&&(t.resetsDateTimeUtc=e.resetsDateTimeUtc),t},_=e=>{if(typeof e==`string`)try{return g(JSON.parse(e))}catch{return null}return g(e)},v=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return null;let t={};for(let[n,r]of Object.entries(u(e)))Array.isArray(r)&&typeof r[0]==`string`&&(t[n]=r[0]);return Object.keys(t).length>0?t:null},y=(e,t)=>{let n=u(e);return!!t?.aborted||n.code===`ERR_CANCELED`||n.name===`CanceledError`||n.name===`AbortError`},b=(e,t)=>{if(e instanceof h)return e;if(y(e,t))return new h(`aborted`,{message:`The request was cancelled.`});let n=u(e).response;if(!n)return new h(`network`,{message:f.errorGeneric});let r=u(n),i=_(r.data),a=typeof i?.code==`string`&&i.code?i.code:`unknown`,o=typeof i?.detail==`string`&&i.detail?i.detail:f.errorGeneric,s=typeof i?.resetsDateTimeUtc==`string`?i.resetsDateTimeUtc:null;return new h(a,{message:o,status:typeof r.status==`number`?r.status:void 0,resetsDateTimeUtc:s,errors:v(i?.errors)})},x=e=>{try{return e()}catch(e){throw e instanceof n?new h(`invalid-response`,{message:f.errorGeneric,cause:e}):e}},S=async(e,t)=>{let n;try{n=(await e()).data}catch(e){throw b(e)}return x(()=>t(n,`response`))},C=()=>void 0,w=e=>{let t=u(u(e).event).target;if(d(t)&&typeof t.responseText==`string`&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText},T=()=>{let e=p.createFormData;if(!e)throw Error(`FormData is not available.`);return e()},E=e=>typeof u(e).uri==`string`,D=(e,t)=>{if(E(t)){e.append(`file`,t);return}let n=u(t).name;if(typeof n!=`string`||n===``)throw Error(`The file needs a name.`);e.append(`file`,t,n)},O=()=>{let e=p.crypto;if(e?.randomUUID)return e.randomUUID();if(e?.getRandomValues){let t=e.getRandomValues(/* @__PURE__ */ new Uint8Array(16));return Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}throw Error(`A chat idempotency key needs crypto.randomUUID or crypto.getRandomValues, and this runtime has neither.`)},k=e=>{let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t},A=e=>{let t=``,n=null;return r=>{let i=(t+r).split(`
|
|
2
|
-
`);t=i.pop()??``;for(let t of i){let r=t.endsWith(`\r`)?t.slice(0,-1):t;if(!r.startsWith(`id:`))continue;let i=r.slice(3).replace(/^ /,``);if(!/^\d+$/.test(i))continue;let a=Number(i);(n===null||a>n)&&(n=a,e?.(a))}}},j=(n,{base:u})=>{if(typeof u!=`string`||u.trim()===``)throw TypeError(`createChatClient needs a base path, e.g. { base: "/api/assistant" }.`);let d=u.replace(/\/+$/,``),g=e=>`${d}/conversations/${encodeURIComponent(e)}`,_=e=>`${d}/attachments/${encodeURIComponent(e)}`,v=e=>`${d}/actions/${encodeURIComponent(e)}`,y=/* @__PURE__ */ new Map,x=async e=>{let t=e===void 0?``:`?screen=${encodeURIComponent(e)}`;try{let e=await S(()=>n.get(`${d}/profile${t}`),a);if(typeof e?.contractVersion!=`number`||e.contractVersion<
|
|
2
|
+
`);t=i.pop()??``;for(let t of i){let r=t.endsWith(`\r`)?t.slice(0,-1):t;if(!r.startsWith(`id:`))continue;let i=r.slice(3).replace(/^ /,``);if(!/^\d+$/.test(i))continue;let a=Number(i);(n===null||a>n)&&(n=a,e?.(a))}}},j=(n,{base:u})=>{if(typeof u!=`string`||u.trim()===``)throw TypeError(`createChatClient needs a base path, e.g. { base: "/api/assistant" }.`);let d=u.replace(/\/+$/,``),g=e=>`${d}/conversations/${encodeURIComponent(e)}`,_=e=>`${d}/attachments/${encodeURIComponent(e)}`,v=e=>`${d}/actions/${encodeURIComponent(e)}`,y=/* @__PURE__ */ new Map,x=async e=>{let t=e===void 0?``:`?screen=${encodeURIComponent(e)}`;try{let e=await S(()=>n.get(`${d}/profile${t}`),a);if(typeof e?.contractVersion!=`number`||e.contractVersion<5)throw new h(`assistant_outdated`,{message:f.assistantOutdated});return e}catch(e){throw e instanceof h&&e.status===404?new h(`assistant_outdated`,{message:f.assistantOutdated,status:404,cause:e}):e}},E=e=>{let t=e??``,n=y.get(t);return n||(n=x(e).catch(e=>{throw y.delete(t),e}),y.set(t,n)),n},j=async(e,t,r)=>{let i=m(r.onEvent),a=0,o=e=>{typeof e!=`string`||e.length<=a||(i.push(e.slice(a)),a=e.length)},s;try{s=await n.post(e,t,{responseType:`text`,headers:r.headers,...r.signal===void 0?{}:{signal:r.signal},onDownloadProgress:e=>o(w(e))})}catch(e){throw b(e,r.signal)}o(s.data),i.end();let c=i.failure;if(c)throw new h(c.code||`unknown`,{message:c.message||f.errorGeneric});let l=i.last;if(!l)throw new h(`invalid-response`,{message:f.errorGeneric,status:s.status});return l};return{getProfile:E,send:(e,t={})=>{let n=k({conversationId:e.conversationId,text:e.text,quickReplyId:e.quickReplyId,attachmentIds:e.attachmentIds&&e.attachmentIds.length>0?e.attachmentIds:void 0,replacesMessageId:e.replacesMessageId,repliesToMessageId:e.repliesToMessageId,pageContext:e.pageContext,captchaToken:e.captchaToken});return j(`${d}/messages`,n,{signal:t.signal,onEvent:t.onEvent,headers:{Accept:`text/event-stream`,"Idempotency-Key":O()}})},answerInput:(e,t,n={})=>{let r=k({values:t.values,captchaToken:t.captchaToken,codes:t.codes,attribution:t.attribution});return j(`${d}/inputs/${encodeURIComponent(e)}`,r,{signal:n.signal,onEvent:n.onEvent,headers:{Accept:`text/event-stream`,"Idempotency-Key":O()}})},confirmAction:e=>S(()=>n.post(`${v(e)}/confirm`,{}),o),rejectAction:(e,t)=>S(()=>n.post(`${v(e)}/reject`,t===void 0?{}:{reason:t}),o),listConversations:(t={})=>{let r=[];t.page!==void 0&&r.push(`page=${encodeURIComponent(String(t.page))}`),t.pageSize!==void 0&&r.push(`pageSize=${encodeURIComponent(String(t.pageSize))}`);let i=r.join(`&`),a=i?`${d}/conversations?${i}`:`${d}/conversations`;return S(()=>n.get(a),e)},getConversation:(e,r)=>{let i=r===void 0?g(e):`${g(e)}?afterSequence=${r}`;return S(()=>n.get(i),t)},renameConversation:async(e,t)=>{await S(()=>n.put(`${g(e)}/title`,{title:t}),C)},deleteConversation:async e=>{await S(()=>n.delete(g(e)),C)},rateMessage:async(e,t)=>{let r=typeof t.note==`string`?t.note.trim():``;await S(()=>n.put(`${d}/messages/${encodeURIComponent(e)}/rating`,{rating:t.rating,note:r||null}),C)},uploadAttachment:(e,t={})=>{let r=T();return D(r,e),S(()=>n.post(`${d}/attachments`,r.native,{headers:{"Content-Type":`multipart/form-data`},timeout:3e5,...t.signal===void 0?{}:{signal:t.signal},onUploadProgress:({loaded:e,total:n})=>{t.onProgress&&n&&t.onProgress((e??0)/n)}}),s)},deleteAttachment:async e=>{await S(()=>n.delete(_(e)),C)},getAttachment:e=>S(()=>n.get(_(e),{responseType:`arraybuffer`}),i),sendOtp:async(e,t)=>{await S(()=>n.post(`${d}/inputs/${encodeURIComponent(e)}/otp`,t),C)},requestHandoff:(e,t={})=>{let n=typeof e.reason==`string`&&e.reason.trim()!==``?e.reason:void 0,r=n===void 0?{conversationId:e.conversationId}:{conversationId:e.conversationId,reason:n};return j(`${d}/handoff`,r,{signal:t.signal,onEvent:t.onEvent,headers:{Accept:`text/event-stream`,"Idempotency-Key":O()}})},watchConversation:async(e,t)=>{let r=new p.AbortController,i=()=>r.abort();t.signal?.aborted&&r.abort(),t.signal?.addEventListener(`abort`,i);let a=!1,o=null,s=()=>{o!==null&&p.clearTimeout(o),o=p.setTimeout(()=>{a=!0,r.abort()},t.stallTimeoutMs??9e4)},c=A(t.onCursor),l=m(t.onEvent),u=0,d=e=>{if(typeof e!=`string`||e.length<=u)return;let t=e.slice(u);u=e.length,c(t),l.push(t),l.failure&&r.abort()},_={Accept:`text/event-stream`};typeof t.afterSequence==`number`&&Number.isFinite(t.afterSequence)&&(_[`Last-Event-ID`]=String(t.afterSequence)),s();try{d((await n.get(`${g(e)}/events`,{headers:_,responseType:`text`,timeout:0,signal:r.signal,onDownloadProgress:e=>{let t=w(e);t!==void 0&&(s(),d(t))}})).data),c(`
|
|
3
3
|
`),l.end();let t=l.failure;if(t)throw new h(t.code||`unknown`,{message:t.message||f.errorGeneric})}catch(e){if(t.signal?.aborted)return;let n=l.failure;throw n?new h(n.code||`unknown`,{message:n.message||f.errorGeneric,cause:e}):a?new h(`stalled`,{message:f.errorGeneric,cause:e}):b(e,r.signal)}finally{o!==null&&p.clearTimeout(o),t.signal?.removeEventListener(`abort`,i)}},sendTyping:async e=>{await S(()=>n.post(`${g(e)}/typing`,void 0),C)},listOpenTickets:()=>S(()=>n.get(`${d}/tickets/open`),r(c)),getSpeechToken:()=>S(()=>n.post(`${d}/speech/token`,void 0),l)}};export{h as ChatApiError,j as createChatClient,O as newIdempotencyKey};
|
package/dist/contract.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=
|
|
1
|
+
var e=5,t=`handoff.request`;export{e as CHAT_CONTRACT_VERSION,t as CHAT_HANDOFF_REQUEST_ID};
|
package/dist/decode/parts.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ChatActionStateValues as e,ChatChartTypeValues as t,ChatColumnTypeValues as n,ChatFieldTypeValues as r,ChatFieldVerificationValues as i,ChatFigureStatusValues as a,ChatHandoffStateValues as o,ChatInputRequestStateValues as s,ChatNoticeCodeValues as c,ChatPartKindValues as l,ChatQuickReplyActionValues as u,ChatQuickReplyPlacementValues as d,ChatQuickReplyVariantValues as f}from"./enums.js";import{ChatDecodeError as p,array as m,boolean as h,field as g,nullable as _,number as v,oneOf as y,record as b,string as x,unionByKind as S}from"./primitives.js";var C=(e,t)=>{if(e===null||typeof e==`string`||typeof e==`number`)return e;throw new p(t,`text, a number or null`)},w=(e,t)=>{let n=b(e,t);return Object.fromEntries(Object.keys(n).map(e=>[e,x(n[e],`${t}.${e}`)]))},T=(e,t)=>{let n=b(e,t);return{marker:g(n,`marker`,v,t),title:g(n,`title`,x,t),reference:g(n,`reference`,x,t),url:g(n,`url`,_(x),t)}},E=(e,t)=>{let n=b(e,t);return{id:g(n,`id`,x,t),label:g(n,`label`,x,t)}},D=(e,t)=>{let n=b(e,t);return{id:g(n,`id`,x,t),startDateTimeUtc:g(n,`startDateTimeUtc`,x,t),endDateTimeUtc:g(n,`endDateTimeUtc`,x,t)}},
|
|
1
|
+
import{ChatActionStateValues as e,ChatChartTypeValues as t,ChatColumnTypeValues as n,ChatFieldTypeValues as r,ChatFieldVerificationValues as i,ChatFigureStatusValues as a,ChatHandoffStateValues as o,ChatInputRequestStateValues as s,ChatNoticeCodeValues as c,ChatPartKindValues as l,ChatQuickReplyActionValues as u,ChatQuickReplyPlacementValues as d,ChatQuickReplyVariantValues as f}from"./enums.js";import{ChatDecodeError as p,array as m,boolean as h,field as g,nullable as _,number as v,oneOf as y,record as b,string as x,unionByKind as S}from"./primitives.js";var C=(e,t)=>{if(e===null||typeof e==`string`||typeof e==`number`)return e;throw new p(t,`text, a number or null`)},w=(e,t)=>{let n=b(e,t);return Object.fromEntries(Object.keys(n).map(e=>[e,x(n[e],`${t}.${e}`)]))},T=(e,t)=>{let n=b(e,t);return{marker:g(n,`marker`,v,t),title:g(n,`title`,x,t),reference:g(n,`reference`,x,t),url:g(n,`url`,_(x),t)}},E=(e,t)=>{let n=b(e,t);return{id:g(n,`id`,x,t),label:g(n,`label`,x,t)}},D=(e,t)=>{let n=b(e,t);return{title:g(n,`title`,x,t),detail:g(n,`detail`,_(x),t),href:g(n,`href`,x,t),icon:g(n,`icon`,_(x),t)}},O=(e,t)=>{let n=b(e,t);return{id:g(n,`id`,x,t),startDateTimeUtc:g(n,`startDateTimeUtc`,x,t),endDateTimeUtc:g(n,`endDateTimeUtc`,x,t)}},k=(e,t)=>{let n=b(e,t);return{id:g(n,`id`,x,t),label:g(n,`label`,x,t),action:g(n,`action`,y(u),t),target:g(n,`target`,_(x),t),navigateAfterMs:g(n,`navigateAfterMs`,_(v),t),icon:g(n,`icon`,_(x),t),variant:g(n,`variant`,_(y(f)),t)}},A=(e,t)=>{let n=b(e,t);return{key:g(n,`key`,x,t),type:g(n,`type`,y(r),t),label:g(n,`label`,x,t),placeholder:g(n,`placeholder`,_(x),t),required:g(n,`required`,h,t),maxLength:g(n,`maxLength`,_(v),t),options:g(n,`options`,_(m(E)),t),slots:g(n,`slots`,_(m(O)),t),consentText:g(n,`consentText`,_(x),t),verify:g(n,`verify`,y(i),t),accept:g(n,`accept`,_(m(x)),t),secret:g(n,`secret`,h,t),validator:g(n,`validator`,_(x),t)}},j=(e,t)=>{let r=b(e,t);return{key:g(r,`key`,x,t),label:g(r,`label`,x,t),type:g(r,`type`,y(n),t)}},M=(e,t)=>{let n=b(e,t);return{label:g(n,`label`,x,t),value:g(n,`value`,v,t)}},N=(e,t)=>{let n=b(e,t);return{name:g(n,`name`,x,t),points:g(n,`points`,m(M),t)}},P=(e,t)=>{let n=b(e,t);return{label:g(n,`label`,x,t),value:g(n,`value`,v,t),unit:g(n,`unit`,_(x),t),status:g(n,`status`,y(a),t)}},F=(e,t)=>{let r=b(e,t);return{label:g(r,`label`,x,t),value:g(r,`value`,x,t),type:g(r,`type`,y(n),t)}},I=(e,t)=>{let n=b(e,t);return{route:g(n,`route`,x,t),params:g(n,`params`,w,t)}},L=(e,t)=>{let n=b(e,t);return{displayName:g(n,`displayName`,x,t),avatarUrl:g(n,`avatarUrl`,_(x),t)}},R=S(l,{Text:(e,t)=>{let n=b(e,t);return{kind:`Text`,text:g(n,`text`,x,t)}},Sources:(e,t)=>{let n=b(e,t);return{kind:`Sources`,sources:g(n,`sources`,m(T),t)}},QuickReplies:(e,t)=>{let n=b(e,t);return{kind:`QuickReplies`,replies:g(n,`replies`,m(k),t),placement:g(n,`placement`,y(d),t)}},InputRequest:(e,t)=>{let n=b(e,t);return{kind:`InputRequest`,requestId:g(n,`requestId`,x,t),title:g(n,`title`,_(x),t),fields:g(n,`fields`,m(A),t),submitLabel:g(n,`submitLabel`,x,t),state:g(n,`state`,y(s),t),answeredSummary:g(n,`answeredSummary`,_(x),t),allowTyped:g(n,`allowTyped`,h,t),cancellable:g(n,`cancellable`,h,t)}},Action:(t,n)=>{let r=b(t,n);return{kind:`Action`,actionId:g(r,`actionId`,x,n),actionKind:g(r,`actionKind`,x,n),title:g(r,`title`,x,n),lines:g(r,`lines`,m(x),n),state:g(r,`state`,y(e),n),decidedDateTimeUtc:g(r,`decidedDateTimeUtc`,_(x),n),note:g(r,`note`,_(x),n),consentText:g(r,`consentText`,_(x),n),confirmLabel:g(r,`confirmLabel`,_(x),n),rejectLabel:g(r,`rejectLabel`,_(x),n),editFields:g(r,`editFields`,_(m(E)),n)}},Notice:(e,t)=>{let n=b(e,t);return{kind:`Notice`,code:g(n,`code`,y(c),t),text:g(n,`text`,x,t),actions:g(n,`actions`,_(m(D)),t)}},Table:(e,t)=>{let n=b(e,t);return{kind:`Table`,title:g(n,`title`,_(x),t),columns:g(n,`columns`,m(j),t),rows:g(n,`rows`,m(m(C)),t),currency:g(n,`currency`,_(x),t)}},Chart:(e,n)=>{let r=b(e,n);return{kind:`Chart`,title:g(r,`title`,_(x),n),chartType:g(r,`chartType`,y(t),n),unit:g(r,`unit`,_(x),n),series:g(r,`series`,m(N),n)}},Figures:(e,t)=>{let n=b(e,t);return{kind:`Figures`,figures:g(n,`figures`,m(P),t)}},RecordCard:(e,t)=>{let n=b(e,t);return{kind:`RecordCard`,recordType:g(n,`recordType`,x,t),recordId:g(n,`recordId`,x,t),title:g(n,`title`,x,t),subtitle:g(n,`subtitle`,_(x),t),fields:g(n,`fields`,m(F),t),target:g(n,`target`,_(I),t)}},Image:(e,t)=>{let n=b(e,t);return{kind:`Image`,attachmentId:g(n,`attachmentId`,x,t),alt:g(n,`alt`,x,t),width:g(n,`width`,_(v),t),height:g(n,`height`,_(v),t)}},File:(e,t)=>{let n=b(e,t);return{kind:`File`,attachmentId:g(n,`attachmentId`,x,t),fileName:g(n,`fileName`,x,t),contentType:g(n,`contentType`,x,t),length:g(n,`length`,v,t)}},Ticket:(e,t)=>{let n=b(e,t);return{kind:`Ticket`,ticketId:g(n,`ticketId`,x,t),number:g(n,`number`,x,t),subject:g(n,`subject`,x,t),status:g(n,`status`,x,t)}},Handoff:(e,t)=>{let n=b(e,t);return{kind:`Handoff`,state:g(n,`state`,y(o),t),queuePosition:g(n,`queuePosition`,_(v),t),agent:g(n,`agent`,_(L),t)}},VoiceClip:(e,t)=>{let n=b(e,t);return{kind:`VoiceClip`,attachmentId:g(n,`attachmentId`,x,t),durationMs:g(n,`durationMs`,v,t),transcript:g(n,`transcript`,_(x),t)}}});export{M as decodeChatChartPoint,N as decodeChatChartSeries,P as decodeChatFigure,A as decodeChatInputField,E as decodeChatInputOption,D as decodeChatNoticeAction,R as decodeChatPart,L as decodeChatParticipant,k as decodeChatQuickReply,F as decodeChatRecordField,I as decodeChatRecordTarget,T as decodeChatSource,j as decodeChatTableColumn,O as decodeChatTimeSlot};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{sniffAudioType as e}from"./audioType.js";import{ChatApiError as t,createChatClient as n,newIdempotencyKey as r}from"./client.js";import{ChatDecodeError as i}from"./decode/primitives.js";import{decodeChatPart as a}from"./decode/parts.js";import{decodeChatConversationView as o,decodeChatMessageView as s}from"./decode/messages.js";import{CHAT_CONTRACT_VERSION as c,CHAT_HANDOFF_REQUEST_ID as l}from"./contract.js";import{createConversationList as u}from"./conversationList.js";import{decodeChatProfileView as d}from"./decode/profile.js";import{DICTATION_NO_SPEECH_MS as f,DICTATION_SILENCE_MS as p,createDictation as m}from"./dictation.js";import{decodeChatStreamEvent as h}from"./decode/events.js";import{createExplain as g}from"./explain.js";import{formatFigure as _,toFigureRuns as v,toFigureText as y}from"./figures.js";import{createFixtureClient as b}from"./fixtureClient.js";import{decodeChatFixture as x}from"./decode/fixture.js";import{formatChatDate as S,formatChatDateTime as C,formatChatDay as w,formatChatValue as T,formatFileSize as E,messagePlainText as D}from"./format.js";import{isHandoffTarget as O}from"./handoff.js";import{IDLE_CHAT_SESSION as k,IDLE_CHAT_STATE as A}from"./idleSession.js";import{DEFAULT_CHAT_LABELS as j,mergeLabels as M}from"./labels.js";import{isSafeLinkUrl as
|
|
1
|
+
import{sniffAudioType as e}from"./audioType.js";import{ChatApiError as t,createChatClient as n,newIdempotencyKey as r}from"./client.js";import{ChatDecodeError as i}from"./decode/primitives.js";import{decodeChatPart as a}from"./decode/parts.js";import{decodeChatConversationView as o,decodeChatMessageView as s}from"./decode/messages.js";import{CHAT_CONTRACT_VERSION as c,CHAT_HANDOFF_REQUEST_ID as l}from"./contract.js";import{createConversationList as u}from"./conversationList.js";import{decodeChatProfileView as d}from"./decode/profile.js";import{DICTATION_NO_SPEECH_MS as f,DICTATION_SILENCE_MS as p,createDictation as m}from"./dictation.js";import{decodeChatStreamEvent as h}from"./decode/events.js";import{createExplain as g}from"./explain.js";import{formatFigure as _,toFigureRuns as v,toFigureText as y}from"./figures.js";import{createFixtureClient as b}from"./fixtureClient.js";import{decodeChatFixture as x}from"./decode/fixture.js";import{formatChatDate as S,formatChatDateTime as C,formatChatDay as w,formatChatValue as T,formatFileSize as E,messagePlainText as D}from"./format.js";import{isHandoffTarget as O}from"./handoff.js";import{IDLE_CHAT_SESSION as k,IDLE_CHAT_STATE as A}from"./idleSession.js";import{DEFAULT_CHAT_LABELS as j,mergeLabels as M}from"./labels.js";import{isSafeActionHref as N,isSafeLinkUrl as P}from"./links.js";import{defaultChatLook as F,mergeLook as I}from"./look.js";import{pacingDelayMs as L}from"./pacing.js";import{CHAT_FEATURES as R,LOADER_STYLES as z,emptyFeatures as B,featureRecord as V,loaderView as H,resolveFeatures as U,resolveNudge as W,resolveStart as G,showsCaptchaNote as K}from"./profile.js";import{provideRuntimeCrypto as q}from"./runtime.js";import{createChatSession as J,createTurnApi as Y,handoffSettledIds as X}from"./session.js";import{CHAT_SPEECH_TOKEN_MARGIN_MS as Z,ChatSpeechError as Q,createSpeechTokenSource as $}from"./speech.js";import{humanizeService as ee,selectStarters as te}from"./starters.js";import{createSseParser as ne,createStreamReader as re}from"./stream.js";import{buildTranscript as ie,transcriptToText as ae}from"./transcript.js";import{formatClipTime as oe,voiceClipBars as se}from"./voiceClip.js";export{c as CHAT_CONTRACT_VERSION,R as CHAT_FEATURES,l as CHAT_HANDOFF_REQUEST_ID,Z as CHAT_SPEECH_TOKEN_MARGIN_MS,t as ChatApiError,i as ChatDecodeError,Q as ChatSpeechError,j as DEFAULT_CHAT_LABELS,f as DICTATION_NO_SPEECH_MS,p as DICTATION_SILENCE_MS,k as IDLE_CHAT_SESSION,A as IDLE_CHAT_STATE,z as LOADER_STYLES,ie as buildTranscript,n as createChatClient,J as createChatSession,u as createConversationList,m as createDictation,g as createExplain,b as createFixtureClient,$ as createSpeechTokenSource,ne as createSseParser,re as createStreamReader,Y as createTurnApi,o as decodeChatConversationView,x as decodeChatFixture,s as decodeChatMessageView,a as decodeChatPart,d as decodeChatProfileView,h as decodeChatStreamEvent,F as defaultChatLook,B as emptyFeatures,V as featureRecord,S as formatChatDate,C as formatChatDateTime,w as formatChatDay,T as formatChatValue,oe as formatClipTime,_ as formatFigure,E as formatFileSize,X as handoffSettledIds,ee as humanizeService,O as isHandoffTarget,N as isSafeActionHref,P as isSafeLinkUrl,H as loaderView,M as mergeLabels,I as mergeLook,D as messagePlainText,r as newIdempotencyKey,L as pacingDelayMs,q as provideRuntimeCrypto,U as resolveFeatures,W as resolveNudge,G as resolveStart,te as selectStarters,K as showsCaptchaNote,e as sniffAudioType,v as toFigureRuns,y as toFigureText,ae as transcriptToText,se as voiceClipBars};
|
package/dist/links.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=/^https?:\/\//i,t=t=>typeof t==`string`&&e.test(t);export{
|
|
1
|
+
var e=/^https?:\/\//i,t=/^(https?:\/\/|tel:|mailto:)/i,n=e=>typeof e==`string`&&t.test(e),r=t=>typeof t==`string`&&e.test(t);export{n as isSafeActionHref,r as isSafeLinkUrl};
|
package/dist/look.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={launcher:{style:`Round`,entrance:`Rise`,idle:`None`,labelReveal:`Bubble`,compact:!1,mark:`Icon`},panel:{motion:`Spring`,widthPx:420,maxHeightPx:650,bottomGapPx:24,height:`Fixed`,replyAvatars
|
|
1
|
+
var e={launcher:{style:`Round`,entrance:`Rise`,idle:`None`,labelReveal:`Bubble`,compact:!1,mark:`Icon`},panel:{motion:`Spring`,widthPx:420,maxHeightPx:650,bottomGapPx:24,height:`Fixed`,placement:`Floating`,replyAvatars:`First`,greetingLoaderMs:0},phone:{maxWidthPx:768,mode:`FullScreen`,sheetHeightDvh:85,sheetMaxHeightPx:640,hideLauncher:!1},input:{ring:!0,sendReveal:`OnText`,sendIcon:`arrow-up`,mark:`None`},avoid:{liftSelectors:[`footer`,`.form-actions-sticky`,`.wui-tabbar`],menuSelectors:[`.offcanvas.show`,`wui-drawer[open]`,`[data-menu-open]`],darkSelectors:[`[data-theme='dark']`,`[data-bs-theme='dark']`],autoOpenOptOutSelector:`[data-chat-no-autoopen]`,autoOpenBusySelectors:[`[data-chat-busy]`]},motion:`On`,avatar:null,avatarMotion:`Still`,expressive:!1};function t(t){let n=t??{};return{launcher:{...e.launcher,...n.launcher},panel:{...e.panel,...n.panel},phone:{...e.phone,...n.phone},input:{...e.input,...n.input},avoid:{...e.avoid,...n.avoid},motion:n.motion??e.motion,avatar:n.avatar??e.avatar,avatarMotion:n.avatarMotion??e.avatarMotion,expressive:n.expressive??e.expressive}}export{e as defaultChatLook,t as mergeLook};
|
package/dist/session.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ChatApiError as e}from"./client.js";import"./contract.js";import{messagePlainText as t}from"./format.js";import{asRecord as n}from"./guards.js";import{DEFAULT_CHAT_LABELS as r,mergeLabels as i}from"./labels.js";import{startLiveConnection as a}from"./live.js";import{pacingDelayMs as o}from"./pacing.js";import{emptyFeatures as s,resolveFeatures as
|
|
1
|
+
import{ChatApiError as e}from"./client.js";import"./contract.js";import{messagePlainText as t}from"./format.js";import{asRecord as n}from"./guards.js";import{DEFAULT_CHAT_LABELS as r,mergeLabels as i}from"./labels.js";import{startLiveConnection as a}from"./live.js";import{pacingDelayMs as o}from"./pacing.js";import{emptyFeatures as s,resolveFeatures as c,resolveStart as l}from"./profile.js";import{runtime as u}from"./runtime.js";import{selectStarters as ee}from"./starters.js";var te=5e3,ne=3e3,re=300,ie=1200,ae=e=>{if(u.requestAnimationFrame&&u.cancelAnimationFrame){let t=u.requestAnimationFrame(()=>e());return()=>u.cancelAnimationFrame?.(t)}let t=u.setTimeout(e,16);return()=>u.clearTimeout(t)},d=e=>{let t=n(e);return{code:typeof t.code==`string`&&t.code?t.code:`unknown`,message:typeof t.message==`string`&&t.message?t.message:r.errorGeneric,resetsDateTimeUtc:typeof t.resetsDateTimeUtc==`string`?t.resetsDateTimeUtc:null}},oe=(e,t)=>({id:e.publicId,author:e.author,createdDateTimeUtc:e.createdDateTimeUtc,parts:e.parts,sequence:e.sequence,rating:e.rating,ratingNote:e.ratingNote,streaming:!1,stored:!0,restored:t}),se=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n<0?[...e,t]:e.map((e,r)=>r===n?t:e)},ce=(e,t)=>{for(let n=e.length-1;n>=0;--n){let r=e[n];if(r!==void 0&&t(r))return n}return-1},le=e=>e.flatMap(e=>e.kind===`Text`?[e.text]:[]).join(`
|
|
2
2
|
|
|
3
|
-
`),f=e=>e.flatMap(e=>e.kind===`File`?[{publicId:e.attachmentId,fileName:e.fileName,contentType:e.contentType,length:e.length}]:[]),ue=e=>{let t=n(e);return{fileName:typeof t.name==`string`?t.name:``,contentType:typeof t.type==`string`?t.type:``,length:typeof t.size==`number`?t.size:null}},de=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!==void 0&&e.id===r.id&&e.label===r.label&&e.message===r.message}),fe=e=>{for(let t of e){if(!t.startsWith(`Enquiry type:`))continue;let e=t.slice(13).trim();return e===``?null:e}return null},pe=e=>e.some(e=>e.kind===`Handoff`)?null:e.find(e=>e.kind===`InputRequest`)?.requestId??null,me=(e,t)=>e.some(e=>e.parts.some(e=>e.kind===`InputRequest`&&e.requestId===t&&(e.state===`Skipped`||e.state===`Expired`))),he=(e,t)=>{if(t!==`WithAgent`)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n!==void 0){for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(t?.kind===`Handoff`){if(t.state===`Left`||t.state===`Ended`)return null;if(t.state===`Joined`&&t.agent)return t.agent}}if(n.author.kind===`Agent`)return{displayName:n.author.displayName??``,avatarUrl:n.author.avatarUrl}}}return null},ge=(e,t)=>{(e.cursor===null||t>e.cursor)&&(e.cursor=t)},_e=(e,t)=>{let n=[];e!==``&&n.push({kind:`Text`,text:e});for(let e of t)n.push({kind:`File`,attachmentId:e.publicId,fileName:e.fileName,contentType:e.contentType,length:e.length});return n},ve=e=>{let t=le(e.parts);return{wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:null,attachments:f(e.parts)}},ye=e=>({profile:null,profileError:null,features:s(),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:e?.get(`wchat:muted`)===`1`,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffContactRequestId:null,handoffPause:!1,openTickets:[],draft:null}),p=(s,f)=>{let p=i(f.labels),be=f.schedule??oe,m=f.prefs,h=/* @__PURE__ */ new Set,g=ye(m),_=0,v=null,y=null,xe=0,Se=0,Ce=null,b=null,x=/* @__PURE__ */ new Map,S=/* @__PURE__ */ new Set,C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Set,T=/* @__PURE__ */ new Map,E={name:null,email:null,phone:null},D=/* @__PURE__ */ new Set,O=null,k=null,A=null,j=null,M=null,we=!0,Te=!1,N=/* @__PURE__ */ new Set,P=/* @__PURE__ */ new Map,F=Promise.resolve(),I=0,Ee=()=>f.pathname?.()??l.location?.pathname??`/`,De=()=>f.reducedMotion?.()===!0||g.profile?.experience.motion===!1,L=()=>g.streaming||g.thinking,Oe=e=>{if(!e.profile)return{...e,greeting:null,starters:[]};let t=Ee(),n=e.lastConversation!==null,r=c(e.profile,{pathname:t,returning:n}).greeting,i=te(e.profile.start,{pathname:t,returning:n,behaviour:f.behaviour?.()??null,behaviourStarters:e.features.BehaviourStarters});return{...e,greeting:r,starters:de(e.starters,i)?e.starters:i}},R=()=>{O!==null&&(l.clearTimeout(O),O=null)},ke=()=>{A!==null&&(l.clearTimeout(A),A=null)},Ae=e=>e.flatMap(e=>e.parts.flatMap(e=>e.kind===`Action`&&e.actionKind===`ChatLeadCapture`&&e.state===`Done`?[{actionId:e.actionId,leadType:fe(e.lines)}]:[])),je=()=>{E.name=null,E.email=null,E.phone=null,D.clear()},Me=e=>{for(let t of Ae(e))D.add(t.actionId)},Ne=()=>{for(let e of Ae(g.messages))D.has(e.actionId)||(D.add(e.actionId),f.onEvent?.(`leadSubmitted`,{conversationId:g.conversationId,fields:{name:E.name,email:E.email,phone:E.phone},leadType:e.leadType}))},Pe=(e,t)=>{let n=g.messages.flatMap(e=>e.parts).find(t=>t.kind===`InputRequest`&&t.requestId===e);if(n)for(let e of n.fields){let n=t[e.key];typeof n==`string`&&n.trim()!==``&&(e.type===`Email`?E.email=n.trim():e.type===`Phone`?E.phone=n.trim():(e.type===`Name`||e.key.toLowerCase()===`name`)&&(E.name=n.trim()))}},z=e=>{let t=M;t!==null&&(M=null,t.handle?.stop(),e!==null&&V({live:e}))},Fe=()=>!Te&&we&&g.features.HumanHandoff&&g.conversationId!==null&&(g.conversationState===`WaitingForAgent`||g.conversationState===`WithAgent`),B=()=>{if(!Fe()){M!==null&&z(`Off`);return}let e=g.conversationId;if(e===null||M!==null&&M.conversationId===e)return;z(null);let t={conversationId:e,cursor:null,handle:null};M=t;let n=a({watch:(n,r,i)=>s.watchConversation(e,{afterSequence:n,signal:r,onCursor:e=>ge(t,e),onEvent:e=>{i(),M===t&&(e.name===`messageCompleted`&&ge(t,e.data.message.sequence),Z(e,`live`,()=>M===t))}}),beforeReconnect:()=>Q(),getCursor:()=>{let e=t.cursor;for(let t of g.messages)t.sequence!==null&&(e===null||t.sequence>e)&&(e=t.sequence);return e},onStatus:e=>{M===t&&g.live!==e&&V({live:e})},onError:e=>K(e)});t.handle=n,M!==t&&n.stop()},V=e=>{let t={...g,...e};g.conversationState===`WithAgent`&&t.conversationState!==`WithAgent`&&t.agentTyping!==null&&(R(),t.agentTyping=null),(e.messages!==void 0||e.conversationState!==void 0)&&(t.agent=he(t.messages,t.conversationState)),e.messages!==void 0&&t.handoffContactRequestId!==null&&me(t.messages,t.handoffContactRequestId)&&(t.handoffContactRequestId=null),g=Oe(t);for(let e of h)e();e.messages!==void 0&&Ne(),B()},H=(e,t)=>V({attachments:g.attachments.map(n=>n.key===e?{...n,...t}:n)}),U=()=>{if(x.size===0)return;let e=[...x.values()];x.clear(),V({messages:g.messages.map(t=>{let n=e.filter(e=>e.messageId===t.id);if(n.length===0)return t;let r=t.parts.map((e,t)=>{let r=n.filter(e=>e.index===t).map(e=>e.text).join(``);return e.kind===`Text`&&r!==``?{...e,text:e.text+r}:e});return{...t,parts:r}})})},W=()=>{x.clear(),y?.(),y=null},Ie=(e,t,n)=>{let r=`${e}#${t}`,i=x.get(r);x.set(r,{messageId:e,index:t,text:(i?.text??``)+n}),y||=be(()=>{y=null,U()})},G=()=>{U(),_+=1,v?.abort(),v=null},K=e=>{if(f.onError)f.onError(e);else throw e},q=()=>{for(let e of T.values())e.abort();T.clear();for(let e of w){let t=C.get(e);t&&s.deleteAttachment(t.publicId).catch(K)}w.clear(),C.clear()},Le=e=>{let t=C.get(e);if(!t)throw Error(`No uploaded file for composer attachment ${e}.`);return t},Re=async(e,t)=>{let n=new l.AbortController;T.set(e,n);let r;try{r=await s.uploadAttachment(t,{signal:n.signal,onProgress:t=>{T.get(e)===n&&H(e,{progress:t})}})}catch{T.get(e)===n&&(T.delete(e),H(e,{status:`Failed`,progress:null,error:p.attachmentFailed}));return}T.get(e)===n?(T.delete(e),C.set(e,r),w.add(e),H(e,{status:`Ready`,progress:null})):s.deleteAttachment(r.publicId).catch(K)},ze=e=>{let t={...n(f.pageContext?.()),path:Ee(),behaviour:f.behaviour?.()??null};return e&&(t.attribution=f.attribution?.()??null),t},J=async()=>{let t=g.profile?.captcha;if(!t)return null;if(t.testToken)return t.testToken;if(!f.getCaptchaToken||t.mode===`Off`&&!t.siteKey)return null;let n;try{n=await f.getCaptchaToken(t.action)}catch(t){throw f.onError?.(t),new e(`captcha_unavailable`,{message:p.captchaUnavailable,cause:t})}if(!n)throw new e(`captcha_unavailable`,{message:p.captchaUnavailable});return n},Be=(e,t,n)=>{let r=se(g.messages,d(e,!1));V(n?{messages:r,messagesLeftToday:t??g.messagesLeftToday,steps:[],thinking:!1}:{messages:r})},Ve=e=>{let n=g.profile?.experience.pacing;return!n||S.has(e.publicId)||e.author.kind!==`Assistant`&&e.author.kind!==`Script`?0:o(t(e.parts),n,De())},He=(e,t,n,r,i)=>{I+=1,V({pending:{typing:!0,authorKind:e.author.kind}}),F=F.then(()=>new Promise(e=>l.setTimeout(e,n))).then(()=>{--I,r()&&Be(e,t,i),I===0&&V({pending:null})})},Ue=(e,t,n)=>{let r=[...e];return r[t]=n,r},Y=(e,t)=>g.messages.map(n=>n.id===e?t(n):n),X=e=>g.messages.some(t=>t.id===e),We=()=>{R(),g.agentTyping!==null&&V({agentTyping:null})},Ge=e=>{R(),O=l.setTimeout(()=>{O=null,V({agentTyping:null})},ne),V({agentTyping:{displayName:e}})},Z=(e,t,n)=>{if(!n())return;let r=t===`turn`;if(e.name===`partDelta`)S.add(e.data.messageId),Ie(e.data.messageId,e.data.index,e.data.text);else switch(U(),e.name){case`messageStarted`:{let t=e.data.message;if(t.author.kind===`Agent`&&We(),X(t.publicId))break;V({messages:[...g.messages,{id:t.publicId,author:t.author,createdDateTimeUtc:t.createdDateTimeUtc,parts:[...t.parts],sequence:t.sequence,rating:t.rating,ratingNote:t.ratingNote,streaming:!0,stored:!1,restored:!1}]});break}case`partStarted`:{let{messageId:t,index:n,part:i}=e.data;if(!X(t))break;V({messages:Y(t,e=>({...e,parts:Ue(e.parts,n,i)})),...r?{thinking:!1}:{}});break}case`partCompleted`:{let{messageId:t,index:n,part:r}=e.data;if(!X(t))break;V({messages:Y(t,e=>({...e,parts:Ue(e.parts,n,r)}))});break}case`messageReset`:{let{messageId:t}=e.data;if(!X(t))break;for(let e of[...x.keys()])x.get(e)?.messageId===t&&x.delete(e);V({messages:Y(t,e=>({...e,parts:[]})),...r?{thinking:!0,steps:[]}:{}});break}case`step`:{if(!r)break;let t=e.data.label;g.steps[g.steps.length-1]!==t&&V({steps:[...g.steps,t]});break}case`messageCompleted`:{let{message:t,messagesLeftToday:i}=e.data;t.author.kind===`Agent`&&We();let a=Ve(t);a>0||I>0?He(t,i,a,n,r):Be(t,i,r);break}case`conversationUpdated`:{let t=e.data;V({conversationId:t.conversationId,conversationState:t.state,title:t.title,continuesConversationId:t.continuesConversationId});break}case`typing`:e.data.authorKind===`Agent`&&Ge(e.data.displayName)}},Q=async()=>{let e=g.conversationId;if(e===null)return;let t=_;try{let n=await s.getConversation(e);if(t!==_)return;let r=new Set(g.messages.filter(e=>e.restored).map(e=>e.id));V({messages:n.messages.map(e=>d(e,r.has(e.publicId))),title:n.title,conversationState:n.state,continuesConversationId:n.continuesConversationId})}catch(e){K(e)}},$=async(e,t,n)=>{let r=_,i=new l.AbortController,a=()=>r===_&&!i.signal.aborted;v=i;let o=g.conversationId===null;xe+=1;let ee={id:`local-${xe}`,author:{kind:`Visitor`,displayName:null,avatarUrl:null},createdDateTimeUtc:(/* @__PURE__ */ new Date()).toISOString(),parts:_e(e.displayText,e.attachments),sequence:null,rating:null,ratingNote:null,streaming:!1,stored:!1,restored:!1};n&&(w.clear(),C.clear()),V({messages:[...t,ee],thinking:!0,streaming:!0,steps:[],turnError:null,stopped:!1,...n?{editing:null,attachments:[]}:{}});try{let t=await J();await s.send({conversationId:g.conversationId,text:e.wireText,quickReplyId:e.quickReplyId,attachmentIds:e.attachments.map(e=>e.publicId),replacesMessageId:e.replacesMessageId,pageContext:ze(o),captchaToken:t},{signal:i.signal,onEvent:e=>Z(e,`turn`,a)})}catch(e){if(U(),!a())return;let t=u(e);V({messages:g.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,turnError:t,...t.code===`daily_limit`?{messagesLeftToday:0}:{},...t.code===`conversation_not_found`?{conversationId:null}:{}});return}finally{v===i&&(v=null)}if(await F,!a())return;U(),V({thinking:!1,streaming:!1}),await Q();let c=g.conversationId;o&&c!==null&&c!==Ce&&(Ce=c,f.onEvent?.(`chatStarted`,{conversationId:c}))},Ke=e=>V({messages:g.messages.map(t=>({...t,parts:t.parts.map(t=>t.kind===`Action`&&t.actionId===e.actionId?{...t,state:e.state,decidedDateTimeUtc:e.decidedDateTimeUtc,note:e.note}:t)}))}),qe=async()=>{try{V({openTickets:await s.listOpenTickets()})}catch(e){K(e)}},Je=async()=>{try{let e=await s.listConversations({page:1,pageSize:1});V({lastConversation:e.items[0]??null})}catch(e){K(e)}},Ye=async()=>{let e;try{e=await s.getProfile(f.screen)}catch(e){V({profileError:u(e)});return}let t=ee(e,f.narrow);V({profile:e,profileError:null,features:t,messagesLeftToday:e.messagesLeftToday}),t.OpenTickets&&qe(),t.ResumeLast&&t.History&&Je(),f.conversationId&&await ut(f.conversationId)},Xe=()=>(b||=Ye(),b),Ze=async e=>{let t=typeof e==`string`?e.trim():``,n=g.attachments.filter(e=>e.status===`Ready`);if(t===``&&n.length===0||g.streaming||g.attachments.some(e=>e.status===`Uploading`))return;let r=g.messages,i=null;if(g.editing){let e=g.messages.findIndex(e=>e.id===g.editing?.messageId),t=g.messages[e];if(!t?.stored)return;i=t.id,r=g.messages.slice(0,e)}let a=n.map(e=>Le(e.key));await $({wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:i,attachments:a},r,!0)},Qe=async e=>{e.action!==`Send`||L()||(e.id===`handoff.request`&&g.features.HumanHandoff&&g.conversationId!==null&&!g.handoffPending?await xt():await $({wireText:null,displayText:e.label,quickReplyId:e.id,replacesMessageId:null,attachments:[]},g.messages,!1))},$e=async(e,t)=>{let n=await J();await s.sendOtp(e,{...t,captchaToken:n})},et=async(t,n,r=null)=>{if(g.streaming)return{ok:!1,errors:{},message:p.errorGeneric};let i=_,a=new l.AbortController,o=()=>i===_&&!a.signal.aborted;v=a,Pe(t,n);let ee=t===g.handoffContactRequestId;V({streaming:!0,thinking:!0});try{let e=await J();await s.answerInput(t,{values:n,codes:r,captchaToken:e,attribution:f.attribution?.()??null},{signal:a.signal,onEvent:e=>Z(e,`turn`,o)})}catch(t){return U(),V({thinking:!1,streaming:!1}),a.signal.aborted?{ok:!1,errors:{},message:p.errorGeneric}:t instanceof e&&t.code===`validation_failed`?{ok:!1,errors:t.errors??{},message:t.message}:t instanceof e&&t.code===`input_request_closed`?(await Q(),{ok:!1,errors:{},message:t.message}):{ok:!1,errors:{},message:u(t).message}}finally{v===a&&(v=null)}return await F,o()&&(U(),V({thinking:!1,streaming:!1}),f.onEvent?.(`inputSubmitted`,{requestId:t}),await Q(),ee&&(V({handoffContactRequestId:null}),await xt().catch(K))),{ok:!0}},tt=async e=>{let t=await s.confirmAction(e);Ke(t),f.onEvent?.(`chatActionConfirmed`,{actionId:t.actionId,kind:t.actionKind}),await Q()},nt=async(e,t)=>{Ke(await s.rejectAction(e,t)),await Q()},rt=()=>{if(!g.streaming)return;W();let e=v;v=null,e?.abort(),V({messages:g.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,stopped:!0,steps:[],pending:null})},it=async()=>{if(g.streaming||g.turnError===null&&!g.stopped)return;let e=ce(g.messages,e=>e.author.kind===`Visitor`),t=g.messages[e];t!==void 0&&await $(ve(t),g.messages.slice(0,e),!1)},at=async()=>{if(L())return;let e=ce(g.messages,e=>e.author.kind===`Visitor`&&e.stored),t=g.messages[e];t!==void 0&&await $({...ve(t),replacesMessageId:t.id},g.messages.slice(0,e),!1)},ot=e=>{let t=g.messages.find(t=>t.id===e);t?.stored&&t.author.kind===`Visitor`&&(q(),V({editing:{messageId:e,text:le(t.parts)},attachments:[]}))},st=()=>{g.editing&&(q(),V({editing:null,attachments:[]}))},ct=async e=>{let t=g.profile;if(!t||!g.features.Attachments)return;let n=t.limits,r=n.maxAttachments-g.attachments.filter(e=>e.status!==`Failed`).length,i=[],a=[];for(let t of e){let e=ue(t);Se+=1;let o=`file-${Se}`,s={key:o,fileName:e.fileName,contentType:e.contentType,length:e.length??0};r<=0?i.push({...s,status:`Failed`,progress:null,error:p.attachmentLimit(n.maxAttachments)}):e.length!==null&&e.length>n.maxFileBytes||!n.contentTypes.includes(e.contentType)?i.push({...s,status:`Failed`,progress:null,error:p.attachmentFailed}):(--r,i.push({...s,status:`Uploading`,progress:0,error:null}),a.push({key:o,file:t}))}V({attachments:[...g.attachments,...i]}),await Promise.all(a.map(({key:e,file:t})=>Re(e,t)))},lt=async e=>{let t=T.get(e);t&&(T.delete(e),t.abort());let n=w.has(e)?C.get(e):void 0;n&&await s.deleteAttachment(n.publicId),w.delete(e),C.delete(e),V({attachments:g.attachments.filter(t=>t.key!==e)})};async function ut(e){G();let t=_;V({messages:[],conversationId:null,loadError:null,loading:!0,editing:null,thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1});try{let n=await s.getConversation(e);if(t!==_)return;let r=n.messages.map(e=>d(e,!0));je(),Me(r),V({messages:r,conversationId:n.publicId,title:n.title,conversationState:n.state,continuesConversationId:n.continuesConversationId})}catch(e){if(t!==_)return;V({loadError:u(e)})}finally{t===_&&V({loading:!1})}}let dt=async()=>{let e=g.lastConversation;e&&await ut(e.publicId)},ft=()=>{q(),G(),W(),je(),V({messages:[],conversationId:null,title:null,conversationState:`Open`,continuesConversationId:null,loadError:null,loading:!1,editing:null,attachments:[],thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1,pending:null}),g.features.OpenTickets&&qe()},pt=(e,t,n)=>{V({messages:Y(e,e=>({...e,rating:t,ratingNote:n}))})},mt=async(e,t,n)=>{let r=g.messages.find(t=>t.id===e);if(!r?.stored)throw Error(`Only a stored reply can be rated.`);let i={rating:r.rating,ratingNote:r.ratingNote},a=typeof n==`string`&&n.trim()?n.trim():null;pt(e,t,a);try{await s.rateMessage(e,{rating:t,note:a})}catch(t){throw pt(e,i.rating,i.ratingNote),t}f.onEvent?.(`rated`,{messageId:e,rating:t})},ht=e=>{let t=g.open,n=e?.trigger??`manual`,r=e?.draft,i={open:!0};typeof r==`string`&&r.trim()!==``&&(i.draft=r),!t&&n===`auto`&&m?.set(`wchat:auto-opened`,`1`),V(i),t||f.onEvent?.(`chatOpened`,{layout:f.layout??null,trigger:n})},gt=e=>{g.open&&(m?.set(`wchat:dismissed`,`1`),V({open:!1}),f.onEvent?.(`chatClosed`,{layout:f.layout??null,reason:e}))},_t=e=>{m?.set(`wchat:muted`,e?`1`:`0`),V({muted:e}),f.onEvent?.(`chatSoundToggled`,{muted:e})},vt=async e=>{L()||(e===g.handoffContactRequestId&&V({handoffContactRequestId:null}),f.onEvent?.(`chatLeadSkipped`,{requestId:e}),await $({wireText:null,displayText:p.skip,quickReplyId:`lead.skip`,replacesMessageId:null,attachments:[]},g.messages,!1))},yt=async()=>{L()||(f.onEvent?.(`chatLeadCancelled`,{}),await $({wireText:null,displayText:p.cancel,quickReplyId:`lead.cancel`,replacesMessageId:null,attachments:[]},g.messages,!1))},bt=async(e,t)=>{L()||g.messages.some(t=>t.parts.some(t=>t.kind===`Action`&&t.actionId===e))&&await $({wireText:null,displayText:p.editSomething,quickReplyId:`lead.edit:${t}`,replacesMessageId:null,attachments:[]},g.messages,!1)},xt=async t=>{if(!g.features.HumanHandoff)throw new e(`chat_feature_off`,{message:r.errorGeneric,status:403});let n=g.conversationId;if(n===null)throw new e(`conversation_required`,{message:r.errorGeneric});if(g.streaming||g.handoffPending)throw new e(`busy`,{message:r.errorGeneric});let i=new l.AbortController;j=i,V({handoffPending:!0}),f.onEvent?.(`chatHandoffRequested`,{conversationId:n});let a=null;try{a=pe((await s.requestHandoff({conversationId:n,reason:t??null},{signal:i.signal,onEvent:e=>Z(e,`handoff`,()=>!i.signal.aborted)})).parts)}catch(e){throw V({messages:g.messages.filter(e=>!e.streaming),handoffPending:!1}),e}finally{j===i&&(j=null)}V({handoffPending:!1,handoffContactRequestId:a}),await Q(),f.onEvent?.(`chatHandoff`,{destination:`person`})},St=()=>{let e=g.conversationId;if(!g.features.HumanHandoff||e===null||g.conversationState!==`WithAgent`)return;let t=Date.now();k!==null&&t-k<re||(k=t,Promise.allSettled([s.sendTyping(e)]))},Ct=e=>{we=e,B()},wt=()=>{g.live===`Lost`&&Fe()&&(z(null),B())},Tt=e=>{if(f.reducedMotion?.()===!0)return ie;let t=e.navigateAfterMs;if(typeof t==`number`&&Number.isFinite(t)&&t>=0)return t;let n=g.profile?.experience.pacing.handoffPauseMs;return typeof n==`number`&&Number.isFinite(n)?n:ae},Et=()=>{ke(),g.handoffPause&&V({handoffPause:!1})};return{client:s,getState:()=>g,subscribe:e=>(h.add(e),b||Xe(),()=>{h.delete(e)}),load:Xe,submit:Ze,chooseQuickReply:Qe,answerInput:et,sendOtp:$e,confirmAction:tt,rejectAction:nt,stop:rt,retry:it,regenerate:at,startEdit:ot,cancelEdit:st,attach:ct,removeAttachment:lt,openConversation:ut,resumeLast:dt,newConversation:ft,rate:mt,open:ht,close:gt,setMuted:_t,skipField:vt,cancelLead:yt,editLeadField:bt,requestHandoff:xt,notifyTyping:St,setLiveActive:Ct,resumeLive:wt,beginHandoff:(e,t)=>{g.handoffPause||(V({handoffPause:!0}),f.onEvent?.(`chatHandoff`,{destination:e.id}),A=l.setTimeout(()=>{A=null;try{t()}catch(e){Et(),K(e)}},Tt(e)))},endHandoffPause:Et,consumeDraft:()=>{g.draft!==null&&V({draft:null})},loadAttachmentUrl:t=>{let n=P.get(t);if(n!==void 0)return n;let r=(async()=>{let n=l.createObjectUrl;if(!n)throw new e(`unsupported`,{message:p.errorGeneric});let r=await s.getAttachment(t);if(Te)throw new e(`aborted`,{message:p.errorGeneric});let i=n(r);return N.add(i),i})();return P.set(t,r),r.catch(()=>{P.get(t)===r&&P.delete(t)}),r},reset:()=>{q(),W(),G(),b=null,F=Promise.resolve(),I=0,S.clear(),Ce=null,je(),R(),ke(),V(ye(m))},dispose:()=>{h.clear(),Te=!0,_+=1;let e=v;v=null,e?.abort(),j?.abort(),j=null,ke(),R(),z(null),q(),W();let t=l.revokeObjectUrl;for(let e of N)t?.(e);N.clear(),P.clear(),V({attachments:[],editing:null,agentTyping:null})}}},be=e=>{let t=-1;for(let n=e.length-1;n>=0;--n)if(e[n]?.parts.some(e=>e.kind===`Handoff`)){t=n;break}let n=/* @__PURE__ */ new Set;for(let r=0;r<t;r+=1){let t=e[r]?.id;t!==void 0&&n.add(t)}return n},m=(e,t)=>({get features(){return e.getState().features},labels:t.labels,get isLast(){let n=e.getState().messages;return n[n.length-1]?.id===t.messageId},get busy(){let t=e.getState();return t.streaming||t.thinking},get handoffPause(){return e.getState().handoffPause},get handoffSettled(){return be(e.getState().messages).has(t.messageId)},chooseQuickReply(t){e.chooseQuickReply(t)},skipInput(t){e.skipField(t)},cancelLead(){e.cancelLead()},answerInput:(t,n,r)=>e.answerInput(t,n,r),uploadInputFile:async(t,n)=>(await e.client.uploadAttachment(t,n?{onProgress:n}:{})).publicId,sendOtp:(t,n)=>e.sendOtp(t,n),confirmAction:t=>e.confirmAction(t),rejectAction:(t,n)=>e.rejectAction(t,n),requestHandoff:t=>e.requestHandoff(t),beginHandoff:(t,n)=>e.beginHandoff(t,n),readAttachment:t=>e.client.getAttachment(t),loadAttachmentUrl:t=>e.loadAttachmentUrl(t),...t.openAttachment?{openAttachment:t.openAttachment}:{},...t.openRecord?{openRecord:t.openRecord}:{},...t.openTicket?{openTicket:t.openTicket}:{},...t.attachmentUrl?{attachmentUrl:t.attachmentUrl}:{},...t.handoffHosts?{handoffHosts:t.handoffHosts}:{},...t.openCitation?{openCitation:t.openCitation}:{},...t.isCitation?{isCitation:t.isCitation}:{},...t.openTarget?{openTarget:t.openTarget}:{},...t.onNavigate?{onNavigate:t.onNavigate}:{}});export{p as createChatSession,m as createTurnApi,be as handoffSettledIds};
|
|
3
|
+
`),f=e=>e.flatMap(e=>e.kind===`File`?[{publicId:e.attachmentId,fileName:e.fileName,contentType:e.contentType,length:e.length}]:[]),ue=e=>{let t=n(e);return{fileName:typeof t.name==`string`?t.name:``,contentType:typeof t.type==`string`?t.type:``,length:typeof t.size==`number`?t.size:null}},de=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!==void 0&&e.id===r.id&&e.label===r.label&&e.message===r.message}),fe=e=>{for(let t of e){if(!t.startsWith(`Enquiry type:`))continue;let e=t.slice(13).trim();return e===``?null:e}return null},pe=e=>e.some(e=>e.kind===`Handoff`)?null:e.find(e=>e.kind===`InputRequest`)?.requestId??null,me=(e,t)=>e.some(e=>e.parts.some(e=>e.kind===`InputRequest`&&e.requestId===t&&(e.state===`Skipped`||e.state===`Expired`))),he=(e,t)=>{if(t!==`WithAgent`)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n!==void 0){for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(t?.kind===`Handoff`){if(t.state===`Left`||t.state===`Ended`)return null;if(t.state===`Joined`&&t.agent)return t.agent}}if(n.author.kind===`Agent`)return{displayName:n.author.displayName??``,avatarUrl:n.author.avatarUrl}}}return null},ge=(e,t)=>{(e.cursor===null||t>e.cursor)&&(e.cursor=t)},_e=(e,t)=>{let n=[];e!==``&&n.push({kind:`Text`,text:e});for(let e of t)n.push({kind:`File`,attachmentId:e.publicId,fileName:e.fileName,contentType:e.contentType,length:e.length});return n},ve=e=>{let t=le(e.parts);return{wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:null,repliesToMessageId:null,attachments:f(e.parts)}},ye=e=>({profile:null,profileError:null,features:s(),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:e?.get(`wchat:muted`)===`1`,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffContactRequestId:null,handoffPause:!1,openTickets:[],draft:null}),p=(s,f)=>{let p=i(f.labels),m=f.schedule??ae,h=f.prefs,g=/* @__PURE__ */ new Set,_=ye(h),v=0,y=null,b=null,be=0,xe=0,Se=null,x=null,S=/* @__PURE__ */ new Map,Ce=/* @__PURE__ */ new Set,C=/* @__PURE__ */ new Map,w=/* @__PURE__ */ new Set,T=/* @__PURE__ */ new Map,E={name:null,email:null,phone:null},D=/* @__PURE__ */ new Set,O=null,k=null,A=null,j=null,M=null,we=!0,N=!1,P=/* @__PURE__ */ new Set,F=/* @__PURE__ */ new Map,I=Promise.resolve(),L=0,Te=()=>f.pathname?.()??u.location?.pathname??`/`,Ee=()=>f.reducedMotion?.()===!0||_.profile?.experience.motion===!1,R=()=>_.streaming||_.thinking,De=e=>{if(!e.profile)return{...e,greeting:null,starters:[]};let t=Te(),n=e.lastConversation!==null,r=l(e.profile,{pathname:t,returning:n}).greeting,i=ee(e.profile.start,{pathname:t,returning:n,behaviour:f.behaviour?.()??null,behaviourStarters:e.features.BehaviourStarters});return{...e,greeting:r,starters:de(e.starters,i)?e.starters:i}},z=()=>{O!==null&&(u.clearTimeout(O),O=null)},B=()=>{A!==null&&(u.clearTimeout(A),A=null)},Oe=e=>e.flatMap(e=>e.parts.flatMap(e=>e.kind===`Action`&&e.actionKind===`ChatLeadCapture`&&e.state===`Done`?[{actionId:e.actionId,leadType:fe(e.lines)}]:[])),V=()=>{E.name=null,E.email=null,E.phone=null,D.clear()},ke=e=>{for(let t of Oe(e))D.add(t.actionId)},Ae=()=>{for(let e of Oe(_.messages))D.has(e.actionId)||(D.add(e.actionId),f.onEvent?.(`leadSubmitted`,{conversationId:_.conversationId,fields:{name:E.name,email:E.email,phone:E.phone},leadType:e.leadType}))},je=(e,t)=>{let n=_.messages.flatMap(e=>e.parts).find(t=>t.kind===`InputRequest`&&t.requestId===e);if(n)for(let e of n.fields){let n=t[e.key];typeof n==`string`&&n.trim()!==``&&(e.type===`Email`?E.email=n.trim():e.type===`Phone`?E.phone=n.trim():(e.type===`Name`||e.key.toLowerCase()===`name`)&&(E.name=n.trim()))}},H=e=>{let t=M;t!==null&&(M=null,t.handle?.stop(),e!==null&&W({live:e}))},Me=()=>!N&&we&&_.features.HumanHandoff&&_.conversationId!==null&&(_.conversationState===`WaitingForAgent`||_.conversationState===`WithAgent`),U=()=>{if(!Me()){M!==null&&H(`Off`);return}let e=_.conversationId;if(e===null||M!==null&&M.conversationId===e)return;H(null);let t={conversationId:e,cursor:null,handle:null};M=t;let n=a({watch:(n,r,i)=>s.watchConversation(e,{afterSequence:n,signal:r,onCursor:e=>ge(t,e),onEvent:e=>{i(),M===t&&(e.name===`messageCompleted`&&ge(t,e.data.message.sequence),Z(e,`live`,()=>M===t))}}),beforeReconnect:()=>Q(),getCursor:()=>{let e=t.cursor;for(let t of _.messages)t.sequence!==null&&(e===null||t.sequence>e)&&(e=t.sequence);return e},onStatus:e=>{M===t&&_.live!==e&&W({live:e})},onError:e=>q(e)});t.handle=n,M!==t&&n.stop()},W=e=>{let t={..._,...e};_.conversationState===`WithAgent`&&t.conversationState!==`WithAgent`&&t.agentTyping!==null&&(z(),t.agentTyping=null),(e.messages!==void 0||e.conversationState!==void 0)&&(t.agent=he(t.messages,t.conversationState)),e.messages!==void 0&&t.handoffContactRequestId!==null&&me(t.messages,t.handoffContactRequestId)&&(t.handoffContactRequestId=null),_=De(t);for(let e of g)e();e.messages!==void 0&&Ae(),U()},Ne=(e,t)=>W({attachments:_.attachments.map(n=>n.key===e?{...n,...t}:n)}),G=()=>{if(S.size===0)return;let e=[...S.values()];S.clear(),W({messages:_.messages.map(t=>{let n=e.filter(e=>e.messageId===t.id);if(n.length===0)return t;let r=t.parts.map((e,t)=>{let r=n.filter(e=>e.index===t).map(e=>e.text).join(``);return e.kind===`Text`&&r!==``?{...e,text:e.text+r}:e});return{...t,parts:r}})})},K=()=>{S.clear(),b?.(),b=null},Pe=(e,t,n)=>{let r=`${e}#${t}`,i=S.get(r);S.set(r,{messageId:e,index:t,text:(i?.text??``)+n}),b||=m(()=>{b=null,G()})},Fe=()=>{G(),v+=1,y?.abort(),y=null},q=e=>{if(f.onError)f.onError(e);else throw e},J=()=>{for(let e of T.values())e.abort();T.clear();for(let e of w){let t=C.get(e);t&&s.deleteAttachment(t.publicId).catch(q)}w.clear(),C.clear()},Ie=e=>{let t=C.get(e);if(!t)throw Error(`No uploaded file for composer attachment ${e}.`);return t},Le=async(e,t)=>{let n=new u.AbortController;T.set(e,n);let r;try{r=await s.uploadAttachment(t,{signal:n.signal,onProgress:t=>{T.get(e)===n&&Ne(e,{progress:t})}})}catch{T.get(e)===n&&(T.delete(e),Ne(e,{status:`Failed`,progress:null,error:p.attachmentFailed}));return}T.get(e)===n?(T.delete(e),C.set(e,r),w.add(e),Ne(e,{status:`Ready`,progress:null})):s.deleteAttachment(r.publicId).catch(q)},Re=e=>{let t={...n(f.pageContext?.()),path:Te(),behaviour:f.behaviour?.()??null};return e&&(t.attribution=f.attribution?.()??null),t},ze=async()=>{let t=_.profile?.captcha;if(!t)return null;if(t.testToken)return t.testToken;if(!f.getCaptchaToken||t.mode===`Off`&&!t.siteKey)return null;let n;try{n=await f.getCaptchaToken(t.action)}catch(t){throw f.onError?.(t),new e(`captcha_unavailable`,{message:p.captchaUnavailable,cause:t})}if(!n)throw new e(`captcha_unavailable`,{message:p.captchaUnavailable});return n},Be=(e,t,n)=>{let r=se(_.messages,oe(e,!1));W(n?{messages:r,messagesLeftToday:t??_.messagesLeftToday,steps:[],thinking:!1}:{messages:r})},Ve=e=>{let n=_.profile?.experience.pacing;return!n||Ce.has(e.publicId)||e.author.kind!==`Assistant`&&e.author.kind!==`Script`?0:o(t(e.parts),n,Ee())},He=(e,t,n,r,i)=>{L+=1,W({pending:{typing:!0,authorKind:e.author.kind}}),I=I.then(()=>new Promise(e=>u.setTimeout(e,n))).then(()=>{--L,r()&&Be(e,t,i),L===0&&W({pending:null})})},Ue=(e,t,n)=>{let r=[...e];return r[t]=n,r},Y=(e,t)=>_.messages.map(n=>n.id===e?t(n):n),X=e=>_.messages.some(t=>t.id===e),We=()=>{z(),_.agentTyping!==null&&W({agentTyping:null})},Ge=e=>{z(),O=u.setTimeout(()=>{O=null,W({agentTyping:null})},te),W({agentTyping:{displayName:e}})},Z=(e,t,n)=>{if(!n())return;let r=t===`turn`;if(e.name===`partDelta`)Ce.add(e.data.messageId),Pe(e.data.messageId,e.data.index,e.data.text);else switch(G(),e.name){case`messageStarted`:{let t=e.data.message;if(t.author.kind===`Agent`&&We(),X(t.publicId))break;W({messages:[..._.messages,{id:t.publicId,author:t.author,createdDateTimeUtc:t.createdDateTimeUtc,parts:[...t.parts],sequence:t.sequence,rating:t.rating,ratingNote:t.ratingNote,streaming:!0,stored:!1,restored:!1}]});break}case`partStarted`:{let{messageId:t,index:n,part:i}=e.data;if(!X(t))break;W({messages:Y(t,e=>({...e,parts:Ue(e.parts,n,i)})),...r?{thinking:!1}:{}});break}case`partCompleted`:{let{messageId:t,index:n,part:r}=e.data;if(!X(t))break;W({messages:Y(t,e=>({...e,parts:Ue(e.parts,n,r)}))});break}case`messageReset`:{let{messageId:t}=e.data;if(!X(t))break;for(let e of[...S.keys()])S.get(e)?.messageId===t&&S.delete(e);W({messages:Y(t,e=>({...e,parts:[]})),...r?{thinking:!0,steps:[]}:{}});break}case`step`:{if(!r)break;let t=e.data.label;_.steps[_.steps.length-1]!==t&&W({steps:[..._.steps,t]});break}case`messageCompleted`:{let{message:t,messagesLeftToday:i}=e.data;t.author.kind===`Agent`&&We();let a=Ve(t);a>0||L>0?He(t,i,a,n,r):Be(t,i,r);break}case`conversationUpdated`:{let t=e.data;W({conversationId:t.conversationId,conversationState:t.state,title:t.title,continuesConversationId:t.continuesConversationId});break}case`typing`:e.data.authorKind===`Agent`&&Ge(e.data.displayName)}},Q=async()=>{let e=_.conversationId;if(e===null)return;let t=v;try{let n=await s.getConversation(e);if(t!==v)return;let r=new Set(_.messages.filter(e=>e.restored).map(e=>e.id));W({messages:n.messages.map(e=>oe(e,r.has(e.publicId))),title:n.title,conversationState:n.state,continuesConversationId:n.continuesConversationId})}catch(e){q(e)}},$=async(e,t,n)=>{let r=v,i=new u.AbortController,a=()=>r===v&&!i.signal.aborted;y=i;let o=_.conversationId===null;be+=1;let c={id:`local-${be}`,author:{kind:`Visitor`,displayName:null,avatarUrl:null},createdDateTimeUtc:(/* @__PURE__ */ new Date()).toISOString(),parts:_e(e.displayText,e.attachments),sequence:null,rating:null,ratingNote:null,streaming:!1,stored:!1,restored:!1};n&&(w.clear(),C.clear()),W({messages:[...t,c],thinking:!0,streaming:!0,steps:[],turnError:null,stopped:!1,...n?{editing:null,attachments:[]}:{}});try{let t=await ze();await s.send({conversationId:_.conversationId,text:e.wireText,quickReplyId:e.quickReplyId,attachmentIds:e.attachments.map(e=>e.publicId),replacesMessageId:e.replacesMessageId,repliesToMessageId:e.repliesToMessageId,pageContext:Re(o),captchaToken:t},{signal:i.signal,onEvent:e=>Z(e,`turn`,a)})}catch(e){if(G(),!a())return;let t=d(e);W({messages:_.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,turnError:t,...t.code===`daily_limit`?{messagesLeftToday:0}:{},...t.code===`conversation_not_found`?{conversationId:null}:{}});return}finally{y===i&&(y=null)}if(await I,!a())return;G(),W({thinking:!1,streaming:!1}),await Q();let l=_.conversationId;o&&l!==null&&l!==Se&&(Se=l,f.onEvent?.(`chatStarted`,{conversationId:l}))},Ke=e=>W({messages:_.messages.map(t=>({...t,parts:t.parts.map(t=>t.kind===`Action`&&t.actionId===e.actionId?{...t,state:e.state,decidedDateTimeUtc:e.decidedDateTimeUtc,note:e.note}:t)}))}),qe=async()=>{try{W({openTickets:await s.listOpenTickets()})}catch(e){q(e)}},Je=async()=>{try{let e=await s.listConversations({page:1,pageSize:1});W({lastConversation:e.items[0]??null})}catch(e){q(e)}},Ye=async()=>{let e;try{e=await s.getProfile(f.screen)}catch(e){W({profileError:d(e)});return}let t=c(e,f.narrow);W({profile:e,profileError:null,features:t,messagesLeftToday:e.messagesLeftToday}),t.OpenTickets&&qe(),t.ResumeLast&&t.History&&Je(),f.conversationId&&await dt(f.conversationId)},Xe=()=>(x||=Ye(),x),Ze=async e=>{let t=typeof e==`string`?e.trim():``,n=_.attachments.filter(e=>e.status===`Ready`);if(t===``&&n.length===0||_.streaming||_.attachments.some(e=>e.status===`Uploading`))return;let r=_.messages,i=null;if(_.editing){let e=_.messages.findIndex(e=>e.id===_.editing?.messageId),t=_.messages[e];if(!t?.stored)return;i=t.id,r=_.messages.slice(0,e)}let a=n.map(e=>Ie(e.key));await $({wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:i,repliesToMessageId:null,attachments:a},r,!0)},Qe=e=>{for(let t=_.messages.length-1;t>=0;t--){let n=_.messages[t];if(n?.parts.some(t=>t.kind===`QuickReplies`&&t.replies.includes(e)))return n}},$e=async e=>{if(e.action!==`Send`||R())return;if(e.id===`handoff.request`&&_.features.HumanHandoff&&_.conversationId!==null&&!_.handoffPending){await St();return}let t=Qe(e);await $({wireText:null,displayText:e.label,quickReplyId:e.id,replacesMessageId:null,repliesToMessageId:t?.stored&&_.conversationId!==null?t.id:null,attachments:[]},_.messages,!1)},et=async(e,t)=>{let n=await ze();await s.sendOtp(e,{...t,captchaToken:n})},tt=async(t,n,r=null)=>{if(_.streaming)return{ok:!1,errors:{},message:p.errorGeneric};let i=v,a=new u.AbortController,o=()=>i===v&&!a.signal.aborted;y=a,je(t,n);let c=t===_.handoffContactRequestId;W({streaming:!0,thinking:!0});try{let e=await ze();await s.answerInput(t,{values:n,codes:r,captchaToken:e,attribution:f.attribution?.()??null},{signal:a.signal,onEvent:e=>Z(e,`turn`,o)})}catch(t){return G(),W({thinking:!1,streaming:!1}),a.signal.aborted?{ok:!1,errors:{},message:p.errorGeneric}:t instanceof e&&t.code===`validation_failed`?{ok:!1,errors:t.errors??{},message:t.message}:t instanceof e&&t.code===`input_request_closed`?(await Q(),{ok:!1,errors:{},message:t.message}):{ok:!1,errors:{},message:d(t).message}}finally{y===a&&(y=null)}return await I,o()&&(G(),W({thinking:!1,streaming:!1}),f.onEvent?.(`inputSubmitted`,{requestId:t}),await Q(),c&&(W({handoffContactRequestId:null}),await St().catch(q))),{ok:!0}},nt=async e=>{let t=await s.confirmAction(e);Ke(t),f.onEvent?.(`chatActionConfirmed`,{actionId:t.actionId,kind:t.actionKind}),await Q()},rt=async(e,t)=>{Ke(await s.rejectAction(e,t)),await Q()},it=()=>{if(!_.streaming)return;K();let e=y;y=null,e?.abort(),W({messages:_.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,stopped:!0,steps:[],pending:null})},at=async()=>{if(_.streaming||_.turnError===null&&!_.stopped)return;let e=ce(_.messages,e=>e.author.kind===`Visitor`),t=_.messages[e];t!==void 0&&await $(ve(t),_.messages.slice(0,e),!1)},ot=async()=>{if(R())return;let e=ce(_.messages,e=>e.author.kind===`Visitor`&&e.stored),t=_.messages[e];t!==void 0&&await $({...ve(t),replacesMessageId:t.id},_.messages.slice(0,e),!1)},st=e=>{let t=_.messages.find(t=>t.id===e);t?.stored&&t.author.kind===`Visitor`&&(J(),W({editing:{messageId:e,text:le(t.parts)},attachments:[]}))},ct=()=>{_.editing&&(J(),W({editing:null,attachments:[]}))},lt=async e=>{let t=_.profile;if(!t||!_.features.Attachments)return;let n=t.limits,r=n.maxAttachments-_.attachments.filter(e=>e.status!==`Failed`).length,i=[],a=[];for(let t of e){let e=ue(t);xe+=1;let o=`file-${xe}`,s={key:o,fileName:e.fileName,contentType:e.contentType,length:e.length??0};r<=0?i.push({...s,status:`Failed`,progress:null,error:p.attachmentLimit(n.maxAttachments)}):e.length!==null&&e.length>n.maxFileBytes||!n.contentTypes.includes(e.contentType)?i.push({...s,status:`Failed`,progress:null,error:p.attachmentFailed}):(--r,i.push({...s,status:`Uploading`,progress:0,error:null}),a.push({key:o,file:t}))}W({attachments:[..._.attachments,...i]}),await Promise.all(a.map(({key:e,file:t})=>Le(e,t)))},ut=async e=>{let t=T.get(e);t&&(T.delete(e),t.abort());let n=w.has(e)?C.get(e):void 0;n&&await s.deleteAttachment(n.publicId),w.delete(e),C.delete(e),W({attachments:_.attachments.filter(t=>t.key!==e)})};async function dt(e){Fe();let t=v;W({messages:[],conversationId:null,loadError:null,loading:!0,editing:null,thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1});try{let n=await s.getConversation(e);if(t!==v)return;let r=n.messages.map(e=>oe(e,!0));V(),ke(r),W({messages:r,conversationId:n.publicId,title:n.title,conversationState:n.state,continuesConversationId:n.continuesConversationId})}catch(e){if(t!==v)return;W({loadError:d(e)})}finally{t===v&&W({loading:!1})}}let ft=async()=>{let e=_.lastConversation;e&&await dt(e.publicId)},pt=()=>{J(),Fe(),K(),V(),W({messages:[],conversationId:null,title:null,conversationState:`Open`,continuesConversationId:null,loadError:null,loading:!1,editing:null,attachments:[],thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1,pending:null}),_.features.OpenTickets&&qe()},mt=(e,t,n)=>{W({messages:Y(e,e=>({...e,rating:t,ratingNote:n}))})},ht=async(e,t,n)=>{let r=_.messages.find(t=>t.id===e);if(!r?.stored)throw Error(`Only a stored reply can be rated.`);let i={rating:r.rating,ratingNote:r.ratingNote},a=typeof n==`string`&&n.trim()?n.trim():null;mt(e,t,a);try{await s.rateMessage(e,{rating:t,note:a})}catch(t){throw mt(e,i.rating,i.ratingNote),t}f.onEvent?.(`rated`,{messageId:e,rating:t})},gt=e=>{let t=_.open,n=e?.trigger??`manual`,r=e?.draft,i={open:!0};typeof r==`string`&&r.trim()!==``&&(i.draft=r),!t&&n===`auto`&&h?.set(`wchat:auto-opened`,`1`),W(i),t||f.onEvent?.(`chatOpened`,{layout:f.layout??null,trigger:n})},_t=e=>{_.open&&(h?.set(`wchat:dismissed`,`1`),W({open:!1}),f.onEvent?.(`chatClosed`,{layout:f.layout??null,reason:e}))},vt=e=>{h?.set(`wchat:muted`,e?`1`:`0`),W({muted:e}),f.onEvent?.(`chatSoundToggled`,{muted:e})},yt=async e=>{R()||(e===_.handoffContactRequestId&&W({handoffContactRequestId:null}),f.onEvent?.(`chatLeadSkipped`,{requestId:e}),await $({wireText:null,displayText:p.skip,quickReplyId:`lead.skip`,replacesMessageId:null,repliesToMessageId:null,attachments:[]},_.messages,!1))},bt=async()=>{R()||(f.onEvent?.(`chatLeadCancelled`,{}),await $({wireText:null,displayText:p.cancel,quickReplyId:`lead.cancel`,replacesMessageId:null,repliesToMessageId:null,attachments:[]},_.messages,!1))},xt=async(e,t)=>{R()||_.messages.some(t=>t.parts.some(t=>t.kind===`Action`&&t.actionId===e))&&await $({wireText:null,displayText:p.editSomething,quickReplyId:`lead.edit:${t}`,replacesMessageId:null,repliesToMessageId:null,attachments:[]},_.messages,!1)},St=async t=>{if(!_.features.HumanHandoff)throw new e(`chat_feature_off`,{message:r.errorGeneric,status:403});let n=_.conversationId;if(n===null)throw new e(`conversation_required`,{message:r.errorGeneric});if(_.streaming||_.handoffPending)throw new e(`busy`,{message:r.errorGeneric});let i=new u.AbortController;j=i,W({handoffPending:!0}),f.onEvent?.(`chatHandoffRequested`,{conversationId:n});let a=null;try{a=pe((await s.requestHandoff({conversationId:n,reason:t??null},{signal:i.signal,onEvent:e=>Z(e,`handoff`,()=>!i.signal.aborted)})).parts)}catch(e){throw W({messages:_.messages.filter(e=>!e.streaming),handoffPending:!1}),e}finally{j===i&&(j=null)}W({handoffPending:!1,handoffContactRequestId:a}),await Q(),f.onEvent?.(`chatHandoff`,{destination:`person`})},Ct=()=>{let e=_.conversationId;if(!_.features.HumanHandoff||e===null||_.conversationState!==`WithAgent`)return;let t=Date.now();k!==null&&t-k<ne||(k=t,Promise.allSettled([s.sendTyping(e)]))},wt=e=>{we=e,U()},Tt=()=>{_.live===`Lost`&&Me()&&(H(null),U())},Et=e=>{if(f.reducedMotion?.()===!0)return re;let t=e.navigateAfterMs;if(typeof t==`number`&&Number.isFinite(t)&&t>=0)return t;let n=_.profile?.experience.pacing.handoffPauseMs;return typeof n==`number`&&Number.isFinite(n)?n:ie},Dt=()=>{B(),_.handoffPause&&W({handoffPause:!1})};return{client:s,getState:()=>_,subscribe:e=>(g.add(e),x||Xe(),()=>{g.delete(e)}),load:Xe,submit:Ze,chooseQuickReply:$e,answerInput:tt,sendOtp:et,confirmAction:nt,rejectAction:rt,stop:it,retry:at,regenerate:ot,startEdit:st,cancelEdit:ct,attach:lt,removeAttachment:ut,openConversation:dt,resumeLast:ft,newConversation:pt,rate:ht,open:gt,close:_t,setMuted:vt,skipField:yt,cancelLead:bt,editLeadField:xt,requestHandoff:St,notifyTyping:Ct,setLiveActive:wt,resumeLive:Tt,beginHandoff:(e,t)=>{_.handoffPause||(W({handoffPause:!0}),f.onEvent?.(`chatHandoff`,{destination:e.id}),A=u.setTimeout(()=>{A=null;try{t()}catch(e){Dt(),q(e)}},Et(e)))},endHandoffPause:Dt,consumeDraft:()=>{_.draft!==null&&W({draft:null})},loadAttachmentUrl:t=>{let n=F.get(t);if(n!==void 0)return n;let r=(async()=>{let n=u.createObjectUrl;if(!n)throw new e(`unsupported`,{message:p.errorGeneric});let r=await s.getAttachment(t);if(N)throw new e(`aborted`,{message:p.errorGeneric});let i=n(r);return P.add(i),i})();return F.set(t,r),r.catch(()=>{F.get(t)===r&&F.delete(t)}),r},reset:()=>{J(),K(),Fe(),x=null,I=Promise.resolve(),L=0,Ce.clear(),Se=null,V(),z(),B(),W(ye(h))},dispose:()=>{g.clear(),N=!0,v+=1;let e=y;y=null,e?.abort(),j?.abort(),j=null,B(),z(),H(null),J(),K();let t=u.revokeObjectUrl;for(let e of P)t?.(e);P.clear(),F.clear(),W({attachments:[],editing:null,agentTyping:null})}}},m=e=>{let t=-1;for(let n=e.length-1;n>=0;--n)if(e[n]?.parts.some(e=>e.kind===`Handoff`)){t=n;break}let n=/* @__PURE__ */ new Set;for(let r=0;r<t;r+=1){let t=e[r]?.id;t!==void 0&&n.add(t)}return n},h=(e,t)=>({get features(){return e.getState().features},labels:t.labels,get isLast(){let n=e.getState().messages;return n[n.length-1]?.id===t.messageId},get busy(){let t=e.getState();return t.streaming||t.thinking},get handoffPause(){return e.getState().handoffPause},get handoffSettled(){return m(e.getState().messages).has(t.messageId)},chooseQuickReply(t){e.chooseQuickReply(t)},skipInput(t){e.skipField(t)},cancelLead(){e.cancelLead()},answerInput:(t,n,r)=>e.answerInput(t,n,r),uploadInputFile:async(t,n)=>(await e.client.uploadAttachment(t,n?{onProgress:n}:{})).publicId,sendOtp:(t,n)=>e.sendOtp(t,n),confirmAction:t=>e.confirmAction(t),rejectAction:(t,n)=>e.rejectAction(t,n),requestHandoff:t=>e.requestHandoff(t),beginHandoff:(t,n)=>e.beginHandoff(t,n),readAttachment:t=>e.client.getAttachment(t),loadAttachmentUrl:t=>e.loadAttachmentUrl(t),...t.openAttachment?{openAttachment:t.openAttachment}:{},...t.openRecord?{openRecord:t.openRecord}:{},...t.openTicket?{openTicket:t.openTicket}:{},...t.attachmentUrl?{attachmentUrl:t.attachmentUrl}:{},...t.handoffHosts?{handoffHosts:t.handoffHosts}:{},...t.openCitation?{openCitation:t.openCitation}:{},...t.isCitation?{isCitation:t.isCitation}:{},...t.openTarget?{openTarget:t.openTarget}:{},...t.onNavigate?{onNavigate:t.onNavigate}:{}});export{p as createChatSession,h as createTurnApi,m as handoffSettledIds};
|
package/dist/types/contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const CHAT_CONTRACT_VERSION =
|
|
1
|
+
export declare const CHAT_CONTRACT_VERSION = 5;
|
|
2
2
|
export type ChatPartKind = "Text" | "Sources" | "QuickReplies" | "InputRequest" | "Action" | "Notice" | "Table" | "Chart" | "Figures" | "RecordCard" | "Image" | "File" | "Ticket" | "Handoff" | "VoiceClip";
|
|
3
3
|
export type ChatAuthorKind = "Visitor" | "Customer" | "Assistant" | "Agent" | "Script" | "System";
|
|
4
4
|
export type ChatFeature = "VisitorChat" | "Starters" | "Nudges" | "ResumeLast" | "OpenTickets" | "History" | "Rename" | "Delete" | "SuggestedReplies" | "Stop" | "Retry" | "Edit" | "Regenerate" | "Sources" | "Rating" | "Copy" | "Share" | "Print" | "Attachments" | "RichAnswers" | "InputRequests" | "LeadCapture" | "Booking" | "Scripts" | "AiAnswers" | "HumanHandoff" | "Dictation" | "ReadAloud" | "VoiceClips" | "Sounds" | "AutoOpen" | "BehaviourStarters" | "LeadShortcuts" | "LeadRecap" | "FigureText" | "LinkHandoff" | "Explain" | "PanelSwitch";
|
|
@@ -40,6 +40,7 @@ export type ChatPart = {
|
|
|
40
40
|
kind: "Notice";
|
|
41
41
|
code: ChatNoticeCode;
|
|
42
42
|
text: string;
|
|
43
|
+
actions: ChatNoticeAction[] | null;
|
|
43
44
|
} | ChatRichPart;
|
|
44
45
|
export type ChatStreamEventName = "messageStarted" | "partStarted" | "partDelta" | "partCompleted" | "messageReset" | "step" | "messageCompleted" | "conversationUpdated" | "typing" | "error";
|
|
45
46
|
export interface ChatClient {
|
|
@@ -116,6 +117,12 @@ export interface ChatInputOption {
|
|
|
116
117
|
id: string;
|
|
117
118
|
label: string;
|
|
118
119
|
}
|
|
120
|
+
export interface ChatNoticeAction {
|
|
121
|
+
title: string;
|
|
122
|
+
detail: string | null;
|
|
123
|
+
href: string;
|
|
124
|
+
icon: string | null;
|
|
125
|
+
}
|
|
119
126
|
export interface ChatTimeSlot {
|
|
120
127
|
id: string;
|
|
121
128
|
startDateTimeUtc: string;
|
|
@@ -449,6 +456,8 @@ export interface ChatSendRequest {
|
|
|
449
456
|
quickReplyId: string | null;
|
|
450
457
|
attachmentIds: string[] | null;
|
|
451
458
|
replacesMessageId: string | null;
|
|
459
|
+
/** The message in the same conversation this one answers; null when it answers none. */
|
|
460
|
+
repliesToMessageId: string | null;
|
|
452
461
|
pageContext: unknown;
|
|
453
462
|
captchaToken: string | null;
|
|
454
463
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ChatChartPoint, ChatChartSeries, ChatFigure, ChatInputField, ChatInputOption, ChatPart, ChatParticipant, ChatQuickReply, ChatRecordField, ChatRecordTarget, ChatSource, ChatTableColumn, ChatTimeSlot } from "../contract";
|
|
1
|
+
import type { ChatChartPoint, ChatChartSeries, ChatFigure, ChatInputField, ChatInputOption, ChatNoticeAction, ChatPart, ChatParticipant, ChatQuickReply, ChatRecordField, ChatRecordTarget, ChatSource, ChatTableColumn, ChatTimeSlot } from "../contract";
|
|
2
2
|
import { type Decoder } from "./primitives";
|
|
3
3
|
export declare const decodeChatSource: Decoder<ChatSource>;
|
|
4
4
|
export declare const decodeChatInputOption: Decoder<ChatInputOption>;
|
|
5
|
+
export declare const decodeChatNoticeAction: Decoder<ChatNoticeAction>;
|
|
5
6
|
export declare const decodeChatTimeSlot: Decoder<ChatTimeSlot>;
|
|
6
7
|
export declare const decodeChatQuickReply: Decoder<ChatQuickReply>;
|
|
7
8
|
export declare const decodeChatInputField: Decoder<ChatInputField>;
|
package/dist/types/links.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
/** True only for an http, https, tel or mailto address, tested on the raw string like `isSafeLinkUrl`; a notice action row draws a link only when this holds. */
|
|
2
|
+
export declare const isSafeActionHref: (href: string | null | undefined) => href is string;
|
|
1
3
|
/** True only for an http or https address, tested on the raw string so a leading space or control character cannot hide another scheme. */
|
|
2
4
|
export declare const isSafeLinkUrl: (url: string | null | undefined) => url is string;
|
package/dist/types/look.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** Expanding rests as the launcher mark alone and grows into a pill with the label on hover, focus or the peek. */
|
|
2
|
+
export type ChatLauncherStyle = "Round" | "Pill" | "Expanding";
|
|
2
3
|
export type ChatEntrance = "SlideUp" | "BounceIn" | "FadeInPulse" | "SpinScale" | "WiggleIn" | "ElasticIn" | "Rise" | "None";
|
|
3
4
|
export type ChatIdleMotion = "FloatAndPulse" | "Ring" | "None";
|
|
4
5
|
export type ChatLabelReveal = "Bubble" | "Expand";
|
|
@@ -10,6 +11,14 @@ export type ChatMotion = "On" | "Reduced";
|
|
|
10
11
|
export type ChatLauncherMark = "Icon" | "Avatar" | "Orb";
|
|
11
12
|
/** Fixed keeps the panel at its height; Content grows it with the conversation up to that height. */
|
|
12
13
|
export type ChatPanelHeight = "Fixed" | "Content";
|
|
14
|
+
/** Floating keeps the panel above the launcher; Side fills the full height at the screen's edge. */
|
|
15
|
+
export type ChatPanelPlacement = "Floating" | "Side";
|
|
16
|
+
/** What the ask box shows at its start: nothing, or the assistant's avatar. */
|
|
17
|
+
export type ChatInputMark = "None" | "Avatar";
|
|
18
|
+
/** Which assistant replies carry the avatar: none, the first of each run of replies, or every reply. */
|
|
19
|
+
export type ChatReplyAvatars = "None" | "First" | "Every";
|
|
20
|
+
/** Drift slowly turns the gradient of the header, greeting and reply orbs; it applies only while no avatar picture is set. */
|
|
21
|
+
export type ChatAvatarMotion = "Still" | "Drift";
|
|
13
22
|
export interface ChatLook {
|
|
14
23
|
launcher: {
|
|
15
24
|
style: ChatLauncherStyle;
|
|
@@ -26,21 +35,25 @@ export interface ChatLook {
|
|
|
26
35
|
/** Space in pixels between the top of the launcher and the bottom of the panel. */
|
|
27
36
|
bottomGapPx: number;
|
|
28
37
|
height: ChatPanelHeight;
|
|
29
|
-
|
|
38
|
+
placement: ChatPanelPlacement;
|
|
39
|
+
replyAvatars: ChatReplyAvatars;
|
|
30
40
|
/** How long the typing pill shows before the greeting on first open; 0 shows the greeting at once. */
|
|
31
41
|
greetingLoaderMs: number;
|
|
32
42
|
};
|
|
43
|
+
/** hideLauncher hides the launcher while the panel is open on a phone. */
|
|
33
44
|
phone: {
|
|
34
45
|
maxWidthPx: number;
|
|
35
46
|
mode: ChatPhoneMode;
|
|
36
47
|
sheetHeightDvh: number;
|
|
37
48
|
sheetMaxHeightPx: number;
|
|
49
|
+
hideLauncher: boolean;
|
|
38
50
|
};
|
|
39
51
|
/** sendIcon is a shared icon name for the send button. */
|
|
40
52
|
input: {
|
|
41
53
|
ring: boolean;
|
|
42
54
|
sendReveal: ChatSendReveal;
|
|
43
55
|
sendIcon: string;
|
|
56
|
+
mark: ChatInputMark;
|
|
44
57
|
};
|
|
45
58
|
avoid: {
|
|
46
59
|
liftSelectors: string[];
|
|
@@ -52,6 +65,7 @@ export interface ChatLook {
|
|
|
52
65
|
motion: ChatMotion;
|
|
53
66
|
/** The assistant's avatar picture (an image URL) for the header, the replies and an Avatar launcher mark; null draws the gradient. */
|
|
54
67
|
avatar: string | null;
|
|
68
|
+
avatarMotion: ChatAvatarMotion;
|
|
55
69
|
/** Expressive motion: the ring that turns around the thinking mark through a reply and the launcher shrinking as the panel opens. Off by default; reduced motion switches it off. */
|
|
56
70
|
expressive: boolean;
|
|
57
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/chat-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.161.0",
|
|
4
4
|
"description": "The headless Webority Chat engine: the client over the chat routes, the session state machine over message parts, the stream reader, profile resolution with screen narrowing, the default English labels and a fixture client for sandboxes and tests. No DOM and no UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@webority/markdown-core": "^0.
|
|
29
|
+
"@webority/markdown-core": "^0.191.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@webority/markdown-core": "0.
|
|
32
|
+
"@webority/markdown-core": "0.191.0",
|
|
33
33
|
"typescript": "^7.0.2",
|
|
34
34
|
"vite": "^8.1.6",
|
|
35
35
|
"vitest": "5.1.0"
|