@useago/sdk 0.4.5 → 0.4.7
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/{AgoClient-rvTz2thR.js → AgoClient-BrYhSO5M.js} +32 -26
- package/dist/AgoClient-CPqPT5s6.cjs +6 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +5 -0
- package/dist/angular.d.ts +5 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-0F_OXdQB.cjs → createConversationSession-CGRO0bs2.cjs} +1 -1
- package/dist/{createConversationSession-DbuVzvoX.js → createConversationSession-Dmqd80DX.js} +1 -1
- package/dist/createFormCollector-CPS2phYq.js +245 -0
- package/dist/createFormCollector-DaWZsBsI.cjs +1 -0
- package/dist/devtools.cjs +3 -3
- package/dist/devtools.d.cts +7 -2
- package/dist/devtools.d.ts +7 -2
- package/dist/devtools.js +41 -35
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +3 -3
- package/dist/react.cjs +19 -19
- package/dist/react.d.cts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +1516 -1490
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +5 -0
- package/dist/vue.d.ts +5 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +5 -1
- package/dist/widget.d.cts +36 -2
- package/dist/widget.d.ts +36 -2
- package/dist/widget.js +431 -234
- package/package.json +1 -1
- package/dist/AgoClient-D4EL6nva.cjs +0 -6
- package/dist/createFormCollector-BMTdfhHg.cjs +0 -1
- package/dist/createFormCollector-Cujr7hW4.js +0 -244
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-CaekUdDJ.cjs"),p=require("./AgoClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-CaekUdDJ.cjs"),p=require("./AgoClient-CPqPT5s6.cjs");let t=require("vue");var I=Symbol("ago-client"),y={install(o,n){const e=new p.AgoClient(n);o.provide(I,e)}};function g(o){if(o)return new p.AgoClient(o);const n=(0,t.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(o={}){const n=o.client??g(),e=(0,t.ref)([]),s=(0,t.ref)(o.conversationId),i=(0,t.ref)(!1),r=(0,t.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.value=!1};(0,t.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,t.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function d(a,u){i.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},L={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,L);try{const l=await n.sendMessage(a,{conversationId:s.value,files:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),i.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:i,error:r,conversationId:s,sendMessage:d,clearMessages:h}}function M(o={}){const n=o.client??g(),e=o.autoLoad??!0,s=(0,t.ref)([]),i=(0,t.ref)(null),r=(0,t.ref)(!1),c=(0,t.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(d){c.value=d instanceof Error?d:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(d){r.value=!0,c.value=null;try{i.value=await n.getConversation(d)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){i.value=null}return(0,t.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function N(o={}){const n=E({client:o.client,conversationId:o.conversationId}),e=M({client:o.client,autoLoad:o.autoLoad}),s=(0,t.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function F(o,n){const e=g();(0,t.onMounted)(()=>{e.registerFunction(o,n.handler,{description:n.description,parameters:n.parameters})}),(0,t.onUnmounted)(()=>{e.unregisterFunction(o)})}function S(o,n){const e=g();(0,t.onMounted)(()=>{e.registerNavigationFunction(o,n)}),(0,t.onUnmounted)(()=>{e.unregisterFunction("navigateToPage")})}function _(o,n){const e=g();(0,t.onMounted)(()=>{e.on(o,n)}),(0,t.onUnmounted)(()=>{e.off(o,n)})}function D(o){const n=(0,t.shallowRef)(o.get());return(0,t.onScopeDispose)(o.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=y;exports.useAgo=g;exports.useAgoEvents=_;exports.useAgoFunction=F;exports.useAgoNavigation=S;exports.useAgoStore=D;exports.useChat=N;exports.useConversation=M;exports.useMessages=E;
|
package/dist/vue.d.cts
CHANGED
|
@@ -224,6 +224,11 @@ declare interface AgoClientEvents {
|
|
|
224
224
|
conversationId: string;
|
|
225
225
|
messageId: string;
|
|
226
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* The main answer text is done (backend emitted `status: "DONE"`), but follow-up
|
|
229
|
+
* replies may still be pending. Fires once, before `message:complete`.
|
|
230
|
+
*/
|
|
231
|
+
"message:answer-complete": AgoMessage;
|
|
227
232
|
"message:complete": AgoMessage;
|
|
228
233
|
"message:error": {
|
|
229
234
|
error: string;
|
package/dist/vue.d.ts
CHANGED
|
@@ -224,6 +224,11 @@ declare interface AgoClientEvents {
|
|
|
224
224
|
conversationId: string;
|
|
225
225
|
messageId: string;
|
|
226
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* The main answer text is done (backend emitted `status: "DONE"`), but follow-up
|
|
229
|
+
* replies may still be pending. Fires once, before `message:complete`.
|
|
230
|
+
*/
|
|
231
|
+
"message:answer-complete": AgoMessage;
|
|
227
232
|
"message:complete": AgoMessage;
|
|
228
233
|
"message:error": {
|
|
229
234
|
error: string;
|
package/dist/vue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as A } from "./AgoClient-
|
|
1
|
+
import { t as A } from "./AgoClient-BrYhSO5M.js";
|
|
2
2
|
import { computed as y, inject as F, onMounted as g, onScopeDispose as N, onUnmounted as I, ref as c, shallowRef as D } from "vue";
|
|
3
3
|
var L = /* @__PURE__ */ Symbol("ago-client"), b = { install(t, n) {
|
|
4
4
|
const e = new A(n);
|
package/dist/widget.cjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ue=require("./AgoClient-D4EL6nva.cjs"),ge=require("./createFormCollector-BMTdfhHg.cjs"),xe=require("./createConversationSession-0F_OXdQB.cjs");var oe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Z={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color"},ne="var(--ago-brand-color, #03182f)",re="var(--ago-brand-text-color, #fff)",me="var(--ago-header-background, var(--ago-brand-color, #03182f))",he="var(--ago-header-text-color, #e8f0fe)",L="var(--ago-panel-background, #fff)",be="var(--ago-messages-background, #fbfbfb)",z="var(--ago-text-color, #30373e)",ve="var(--ago-muted-text-color, #6b6d6f)",E="var(--ago-border-color, #dee3e8)",q="var(--ago-accent-color, #1b5fc4)",Ce="var(--ago-radius, 16px)",ee="var(--ago-message-radius, 16px)";function ye(i,o){if(o)for(const u of Object.keys(Z)){const w=o[u];w!=null&&i.style.setProperty(Z[u],w)}}function m(i,o){Object.assign(i.style,o)}function c(i={}){const o=document.createElement("div");return m(o,i),o}var te="ago-chat-widget-keyframes";function Ee(){if(typeof document>"u"||document.getElementById(te))return;const i=document.createElement("style");i.id=te,i.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(i)}function we(i){const o=typeof i=="string"?document.querySelector(i):i;if(!o)throw new Error(`mountChatWidget: target "${String(i)}" not found.`);return o}function Se(i,o){const{title:u="Chat",welcomeMessage:w="Hello! How can I help you today?",placeholder:O="Type a message...",allowFiles:g=!1,height:x=500,logoUrl:f,showAgentName:v=!1,theme:T,loadThreads:D=!1,forms:B,onFollowUpClick:s,onMessageSent:C,onMessageReceived:$}=o;if(!o.client&&!o.config?.baseUrl)throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");const l=o.client??new ue.AgoClient(o.config),_=we(i),M=o.persistConversation,I=M?xe.createConversationSession(M===!0?{}:M):void 0;let h=o.conversationId??I?.getLastActiveThread()??void 0,n=[],k=!1,N=null;const U=[],A=c({display:"flex",flexDirection:"column",height:typeof x=="number"?`${x}px`:x,border:`1px solid ${E}`,borderRadius:Ce,overflow:"hidden",backgroundColor:L,fontFamily:oe,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});A.className="ago-chat-widget",ye(A,T);const W=c({padding:"14px 16px",borderBottom:`1px solid ${E}`,backgroundColor:me,color:he,display:"flex",alignItems:"center",gap:"10px"});if(W.className="ago-chat-widget__header",f){const e=document.createElement("img");e.src=f,e.alt="Logo",m(e,{height:"24px",width:"auto"}),W.appendChild(e)}const H=document.createElement("h3");H.textContent=u,m(H,{margin:"0",fontSize:"15px",fontWeight:"600"}),W.appendChild(H);const S=c({flex:"1",overflow:"auto",padding:"16px",backgroundColor:be});S.className="ago-chat-widget__messages";const{inputRow:ae,setDisabled:se,focus:ie}=Re({placeholder:O,allowFiles:g,onSend:(e,t)=>{F(e,t)}});Ee(),A.append(W,S,ae),_.appendChild(A);const K=s!==!1,j=s===!1?void 0:s??(e=>{F(e)});function le(e){const t=e.role==="user",d=c({display:"flex",flexDirection:"column",alignItems:t?"flex-end":"flex-start",marginBottom:"16px"});if(d.className=`ago-message ago-message--${e.role}`,!t&&v&&e.agent){const r=c({fontSize:"13px",fontWeight:"500",color:z,marginBottom:"6px",padding:"0 4px"});r.className="ago-message__agent",r.textContent=e.agent.displayName||e.agent.name,d.appendChild(r)}if(!t&&e.sources&&e.sources.length>0){const r=c({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});r.className="ago-message__sources",e.sources.forEach((p,a)=>{const y=p.url?document.createElement("a"):document.createElement("div");p.url&&y instanceof HTMLAnchorElement&&(y.href=p.url,y.target="_blank",y.rel="noopener noreferrer"),m(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${E}`,borderRadius:"8px",backgroundColor:L,textDecoration:"none",color:z,fontSize:"12px",overflow:"hidden"});const Q=c({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${q}`,color:q,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Q.textContent=String(a+1);const P=c({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});P.textContent=p.title,P.title=p.title,y.append(Q,P),r.appendChild(y)}),d.appendChild(r)}const b=c({maxWidth:t?"75%":"100%",padding:t?"10px 14px":"2px 8px",borderRadius:t?ee:"0",backgroundColor:t?ne:"transparent",color:t?re:z,wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6",whiteSpace:"pre-wrap"});if(b.className="ago-message__content",e.content?b.textContent=e.content:e.status==="IN_PROGRESS"&&b.appendChild(fe()),d.appendChild(b),e.followUpReplies&&e.followUpReplies.length>0){const r=c({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});r.className="ago-message__followups";for(const p of e.followUpReplies){const a=document.createElement("button");a.type="button",a.className="ago-message__followup-btn",a.textContent=p,a.disabled=!K,m(a,{padding:"6px 14px",fontSize:"13px",borderRadius:ee,border:`1px solid ${E}`,backgroundColor:L,color:z,cursor:K?"pointer":"default",transition:"border-color 0.15s"}),j&&a.addEventListener("click",()=>j(p)),a.addEventListener("mouseenter",()=>{a.style.borderColor=q}),a.addEventListener("mouseleave",()=>{a.style.borderColor=E}),r.appendChild(a)}d.appendChild(r)}return d}function R(){if(S.replaceChildren(),n.length===0){const e=c({textAlign:"center",color:ve,padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});e.textContent=w,S.appendChild(e)}else for(const e of n)S.appendChild(le(e));if(N){const e=c({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});e.textContent=N,S.appendChild(e)}S.scrollTop=S.scrollHeight,se(k)}function de(){for(let e=n.length-1;e>=0;e--){const t=n[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const X=e=>{h||(h=e.conversationId)},V=e=>{const t=de();t&&(t.content+=e.content,R())},Y=e=>{const t=n.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");t>=0?n[t]=e:n.push(e),k=!1,R(),e.status==="DONE"&&$?.({id:e.id,content:e.content})},J=e=>{N=e.error,k=!1,n=n.filter(t=>!t.id.startsWith("temp-")),R()};l.on("message:start",X),l.on("message:chunk",V),l.on("message:complete",Y),l.on("message:error",J);const ce=(B??[]).map(e=>ge.createFormCollector(e).install(l));async function F(e,t){const d=e.trim();if(!d&&!t?.length||k)return;C?.(d),k=!0,N=null;const b=Date.now();n.push({id:`temp-user-${b}`,conversationId:h||"",content:d,role:"user",status:"DONE",createdAt:new Date}),n.push({id:`temp-assistant-${b}`,conversationId:h||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),R();try{const r=await l.sendMessage(d,{conversationId:h,files:t});r.conversationId&&(h||(h=r.conversationId),I?.setActiveThread(r.conversationId,r.createdAt));const p=n.find(a=>a.id===`temp-user-${b}`);if(p&&(p.id=`user-${b}`,p.conversationId=r.conversationId),!n.some(a=>a.id===r.id)){const a=n.findIndex(y=>y.id===`temp-assistant-${b}`);a>=0?n[a]=r:n.push(r)}n=n.filter(a=>!a.id.startsWith("temp-")),k=!1,R(),D&&G()}catch(r){N=r instanceof Error?r.message:"Failed to send message",k=!1,n=n.filter(p=>!p.id.startsWith("temp-")),R()}}async function G(){try{const e=await l.getConversations();U.splice(0,U.length,...e)}catch{}return U}async function pe(e){try{const t=(await l.getConversation(e))?.messages??[];t.length>0&&n.length===0&&(n=t,R())}catch{n.length===0&&(I?.clear(),h=void 0)}}return R(),ie(),h&&pe(h),D&&G(),{client:l,element:A,sendMessage:F,session:I,threads:U,refreshThreads:G,destroy(){l.off("message:start",X),l.off("message:chunk",V),l.off("message:complete",Y),l.off("message:error",J),ce.forEach(e=>e()),A.remove(),o.client||l.destroy()}};function fe(){const e=c({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const d=c({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(d)}return e}}function Re(i){let o=[];const u=document.createElement("form");m(u,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${E}`,backgroundColor:L}),u.className="ago-chat-input";const w=c({display:"flex",flexWrap:"wrap",gap:"6px"}),O=c({display:"flex",gap:"8px",alignItems:"flex-end"}),g=document.createElement("textarea");g.placeholder=i.placeholder,g.rows=1,m(g,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${E}`,borderRadius:"12px",fontSize:"14px",fontFamily:oe,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const x=document.createElement("button");x.type="submit",x.textContent="Send",m(x,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:ne,color:re,fontSize:"14px",fontWeight:"500",cursor:"pointer"});let f=null,v=null;i.allowFiles&&(f=document.createElement("input"),f.type="file",f.multiple=!0,m(f,{display:"none"}),v=document.createElement("button"),v.type="button",v.textContent="📎",m(v,{padding:"10px 12px",border:`1px solid ${E}`,borderRadius:"12px",backgroundColor:L,cursor:"pointer",fontSize:"14px"}),v.addEventListener("click",()=>f?.click()),f.addEventListener("change",()=>{o=[...o,...Array.from(f?.files??[])],T()}));function T(){w.replaceChildren(),o.forEach((s,C)=>{const $=c({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${E}`,borderRadius:"8px",fontSize:"12px"}),l=document.createElement("span");l.textContent=s.name;const _=document.createElement("button");_.type="button",_.textContent="×",m(_,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),_.addEventListener("click",()=>{o=o.filter((M,I)=>I!==C),T()}),$.append(l,_),w.appendChild($)})}const D=()=>{const s=g.value,C=o;return g.value="",o=[],T(),{content:s,files:C}},B=()=>{const{content:s,files:C}=D();(s.trim()||C.length>0)&&i.onSend(s.trim(),C.length>0?C:void 0)};return u.addEventListener("submit",s=>{s.preventDefault(),B()}),g.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),B())}),v&&O.appendChild(v),O.append(g,x),f&&u.appendChild(f),u.append(w,O),{inputRow:u,getValueAndClear:D,setDisabled:s=>{g.disabled=s,x.disabled=s,x.style.opacity=s?"0.6":"1",x.style.cursor=s?"not-allowed":"pointer"},focus:()=>g.focus()}}exports.mountChatWidget=Se;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ie=require("./AgoClient-CPqPT5s6.cjs"),Te=require("./createFormCollector-DaWZsBsI.cjs"),Ne=require("./createConversationSession-CGRO0bs2.cjs");var Oe={"&":"&","<":"<",">":">",'"':""","'":"'"};function H(o){return o.replace(/[&<>"']/g,n=>Oe[n])}function ce(o){const n=o.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)?n:null}var ge='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',q="";function L(o){const n=[],r=u=>(n.push(u),`${q}${n.length-1}${q}`);let e=o;return e=e.replace(/`([^`]+)`/g,(u,a)=>r(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ge}">${H(a)}</code>`)),e=e.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,a,p)=>{const i=ce(p);return i?r(`<img alt="${H(a)}" src="${H(i)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,a,p)=>{const i=ce(p);return i?r(`<a href="${H(i)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${L(a)}</a>`):u}),e=H(e),e=e.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),e=e.replace(new RegExp(`${q}(\\d+)${q}`,"g"),(u,a)=>n[Number(a)]),e}function w(o,n,r){const e=document.createElement(o);return Object.assign(e.style,n),r!==void 0&&(e.innerHTML=r),e}var he=/^ {0,3}([-*_])( *\1){2,} *$/,me=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,xe=/^ {0,3}(```+|~~~+)/,X=/^ {0,3}>\s?/,B=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Ae=["20px","18px","16px","15px","14px","13px"],J=o=>o.match(/^\s*/)?.[0].length??0;function Le(o){return o.trim()===""||he.test(o)||me.test(o)||xe.test(o)||X.test(o)||B.test(o)}function be(o){const n=o[0].match(B),r=n[1].length,e=/\d/.test(n[2]),u=w(e?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:e?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<o.length;){const p=o[a].match(B),i=[];for(a++;a<o.length&&J(o[a])>r;)i.push(o[a]),a++;const f=w("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),d=p[3].match(/^\[([ xX])\]\s+(.*)$/);d?(f.style.listStyleType="none",f.style.marginLeft="-20px",f.innerHTML=`<span style="margin-right:6px">${d[1].toLowerCase()==="x"?"☑":"☐"}</span>${L(d[2])}`):f.innerHTML=L(p[3]),i.filter(b=>B.test(b)).length>0&&f.appendChild(be(i.filter(b=>b.trim()!==""))),u.appendChild(f)}return u}function De(o){const n=i=>i.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(f=>f.trim()),r=w("div",{overflowX:"auto",margin:"0 0 8px 0"}),e=w("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),a=document.createElement("tr");for(const i of n(o[0]))a.appendChild(w("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},L(i)));u.appendChild(a),e.appendChild(u);const p=document.createElement("tbody");for(const i of o.slice(2)){const f=document.createElement("tr");for(const d of n(i))f.appendChild(w("td",{border:"1px solid #dee3e8",padding:"6px 10px"},L(d)));p.appendChild(f)}return e.appendChild(p),r.appendChild(e),r}var Me=o=>!!o&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);function ee(o){const n=document.createDocumentFragment(),r=o.replace(/\r\n?/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`);let e=0;for(;e<r.length;){const a=r[e];if(a.trim()===""){e++;continue}const p=a.match(xe);if(p){const d=p[1][0],b=[];for(e++;e<r.length&&!new RegExp(`^ {0,3}${d==="`"?"`{3,}":"~{3,}"}\\s*$`).test(r[e]);)b.push(r[e]),e++;e++;const N=w("pre",{margin:"0 0 8px 0"});N.appendChild(w("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:ge,whiteSpace:"pre"},H(b.join(`
|
|
4
|
+
`)))),n.appendChild(N);continue}if(he.test(a)){n.appendChild(w("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),e++;continue}const i=a.match(me);if(i){const d=i[1].length;n.appendChild(w(`h${d}`,{margin:"16px 0 8px 0",fontSize:Ae[d-1],fontWeight:"600",lineHeight:"1.3"},L(i[2]))),e++;continue}if(X.test(a)){const d=[];for(;e<r.length&&X.test(r[e]);)d.push(r[e].replace(X,"")),e++;const b=w("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});b.appendChild(ee(d.join(`
|
|
5
|
+
`))),n.appendChild(b);continue}if(a.includes("|")&&Me(r[e+1])){const d=[a,r[e+1]];for(e+=2;e<r.length&&r[e].includes("|")&&r[e].trim();)d.push(r[e]),e++;n.appendChild(De(d));continue}if(B.test(a)){const d=[],b=J(a);for(;e<r.length&&r[e].trim()!=="";)if(B.test(r[e])||J(r[e])>b)d.push(r[e]),e++;else break;n.appendChild(be(d));continue}const f=[a];for(e++;e<r.length&&!Le(r[e]);)f.push(r[e]),e++;n.appendChild(w("p",{margin:"0 0 8px 0",lineHeight:"1.6"},f.map(d=>L(d)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var Ce='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',pe={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color"},ve="var(--ago-brand-color, #03182f)",ye="var(--ago-brand-text-color, #fff)",He="var(--ago-header-background, var(--ago-brand-color, #03182f))",Be="var(--ago-header-text-color, #e8f0fe)",z="var(--ago-panel-background, #fff)",Ue="var(--ago-messages-background, #fbfbfb)",j="var(--ago-text-color, #30373e)",ze="var(--ago-muted-text-color, #6b6d6f)",$="var(--ago-border-color, #dee3e8)",Z="var(--ago-accent-color, #1b5fc4)",Fe="var(--ago-radius, 16px)",fe="var(--ago-message-radius, 16px)";function We(o,n){if(n)for(const r of Object.keys(pe)){const e=n[r];e!=null&&o.style.setProperty(pe[r],e)}}function S(o,n){Object.assign(o.style,n)}function x(o={}){const n=document.createElement("div");return S(n,o),n}var ue="ago-chat-widget-keyframes";function Pe(){if(typeof document>"u"||document.getElementById(ue))return;const o=document.createElement("style");o.id=ue,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function Ge(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function qe(o,n){const{title:r="Chat",welcomeMessage:e="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:a=!1,height:p=500,logoUrl:i,showAgentName:f=!1,theme:d,loadThreads:b=!1,forms:N,onFollowUpClick:g,onMessageSent:_,onMessageReceived:F}=n;if(!n.client&&!n.config?.baseUrl)throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");const m=n.client??new Ie.AgoClient(n.config),O=Ge(o),W=n.persistConversation,D=W?Ne.createConversationSession(W===!0?{}:W):void 0;let R=n.conversationId??D?.getLastActiveThread()??void 0,l=[],I=!1,U=null;const P=[],M=x({display:"flex",flexDirection:"column",height:typeof p=="number"?`${p}px`:p,border:`1px solid ${$}`,borderRadius:Fe,overflow:"hidden",backgroundColor:z,fontFamily:Ce,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});M.className="ago-chat-widget",We(M,d);const G=x({padding:"14px 16px",borderBottom:`1px solid ${$}`,backgroundColor:He,color:Be,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",i){const t=document.createElement("img");t.src=i,t.alt="Logo",S(t,{height:"24px",width:"auto"}),G.appendChild(t)}const K=document.createElement("h3");K.textContent=r,S(K,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(K);const T=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:Ue});T.className="ago-chat-widget__messages";const{inputRow:Ee,setDisabled:we,focus:Se}=je({placeholder:u,allowFiles:a,onSend:(t,s)=>{V(t,s)}});Pe(),M.append(G,T,Ee),O.appendChild(M);const te=g!==!1,ne=g===!1?void 0:g??(t=>{V(t)});function Re(t,s){const c=t.role==="user",E=x({display:"flex",flexDirection:"column",alignItems:c?"flex-end":"flex-start",marginBottom:"16px"});if(E.className=`ago-message ago-message--${t.role}`,!c&&f&&t.agent){const h=x({fontSize:"13px",fontWeight:"500",color:j,marginBottom:"6px",padding:"0 4px"});h.className="ago-message__agent",h.textContent=t.agent.displayName||t.agent.name,E.appendChild(h)}if(!c&&t.sources&&t.sources.length>0){const h=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});h.className="ago-message__sources",t.sources.forEach((C,y)=>{const A=C.url?document.createElement("a"):document.createElement("div");C.url&&A instanceof HTMLAnchorElement&&(A.href=C.url,A.target="_blank",A.rel="noopener noreferrer"),S(A,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${$}`,borderRadius:"8px",backgroundColor:z,textDecoration:"none",color:j,fontSize:"12px",overflow:"hidden"});const de=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Z}`,color:Z,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});de.textContent=String(y+1);const Y=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});Y.textContent=C.title,Y.title=C.title,A.append(de,Y),h.appendChild(A)}),E.appendChild(h)}const v=x({maxWidth:c?"75%":"100%",padding:c?"10px 14px":"2px 8px",borderRadius:c?fe:"0",backgroundColor:c?ve:"transparent",color:c?ye:j,wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6"});if(v.className="ago-message__content",t.content?v.appendChild(ee(t.content)):t.status==="IN_PROGRESS"&&v.appendChild(le()),E.appendChild(v),s&&I&&t.role==="assistant"&&t.status==="DONE"&&!(t.followUpReplies&&t.followUpReplies.length>0)){const h=x({marginTop:"10px",paddingLeft:"8px"});h.className="ago-message__followups-loading",h.appendChild(le()),E.appendChild(h)}if(s&&t.followUpReplies&&t.followUpReplies.length>0){const h=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});h.className="ago-message__followups";for(const C of t.followUpReplies){const y=document.createElement("button");y.type="button",y.className="ago-message__followup-btn",y.textContent=C,y.disabled=!te,S(y,{padding:"6px 14px",fontSize:"13px",borderRadius:fe,border:`1px solid ${$}`,backgroundColor:z,color:j,cursor:te?"pointer":"default",transition:"border-color 0.15s"}),ne&&y.addEventListener("click",()=>ne(C)),y.addEventListener("mouseenter",()=>{y.style.borderColor=Z}),y.addEventListener("mouseleave",()=>{y.style.borderColor=$}),h.appendChild(y)}E.appendChild(h)}return E}function k(){if(T.replaceChildren(),l.length===0){const s=x({textAlign:"center",color:ze,padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});s.textContent=e,T.appendChild(s)}else l.forEach((s,c)=>{T.appendChild(Re(s,c===l.length-1))});if(U){const s=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});s.textContent=U,T.appendChild(s)}T.scrollTop=T.scrollHeight;const t=l[l.length-1];we(I&&t?.role==="assistant"&&t.status==="IN_PROGRESS")}function _e(){for(let t=l.length-1;t>=0;t--){const s=l[t];if(s.role==="assistant"&&s.status==="IN_PROGRESS")return s}}const oe=t=>{R||(R=t.conversationId)},re=t=>{const s=_e();s&&(s.content+=t.content,k())},ae=t=>{const s=l.findIndex(c=>c.id===t.id||c.role==="assistant"&&c.status==="IN_PROGRESS");s>=0?l[s]=t:l.push(t),k()},se=t=>{const s=l.findIndex(c=>c.id===t.id||c.role==="assistant"&&c.status==="IN_PROGRESS");s>=0?l[s]=t:l.push(t),I=!1,k(),t.status==="DONE"&&F?.({id:t.id,content:t.content})},ie=t=>{U=t.error,I=!1,l=l.filter(s=>!s.id.startsWith("temp-")),k()};m.on("message:start",oe),m.on("message:chunk",re),m.on("message:answer-complete",ae),m.on("message:complete",se),m.on("message:error",ie);const ke=(N??[]).map(t=>Te.createFormCollector(t).install(m));async function V(t,s){const c=t.trim();if(!c&&!s?.length||I)return;_?.(c),I=!0,U=null;const E=Date.now();l.push({id:`temp-user-${E}`,conversationId:R||"",content:c,role:"user",status:"DONE",createdAt:new Date}),l.push({id:`temp-assistant-${E}`,conversationId:R||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const v=await m.sendMessage(c,{conversationId:R,files:s});v.conversationId&&(R||(R=v.conversationId),D?.setActiveThread(v.conversationId,v.createdAt));const h=l.find(C=>C.id===`temp-user-${E}`);if(h&&(h.id=`user-${E}`,h.conversationId=v.conversationId),!l.some(C=>C.id===v.id)){const C=l.findIndex(y=>y.id===`temp-assistant-${E}`);C>=0?l[C]=v:l.push(v)}l=l.filter(C=>!C.id.startsWith("temp-")),I=!1,k(),b&&Q()}catch(v){U=v instanceof Error?v.message:"Failed to send message",I=!1,l=l.filter(h=>!h.id.startsWith("temp-")),k()}}async function Q(){try{const t=await m.getConversations();P.splice(0,P.length,...t)}catch{}return P}async function $e(t){try{const s=(await m.getConversation(t))?.messages??[];s.length>0&&l.length===0&&(l=s,k())}catch{l.length===0&&(D?.clear(),R=void 0)}}return k(),Se(),R&&$e(R),b&&Q(),{client:m,element:M,sendMessage:V,session:D,threads:P,refreshThreads:Q,destroy(){m.off("message:start",oe),m.off("message:chunk",re),m.off("message:answer-complete",ae),m.off("message:complete",se),m.off("message:error",ie),ke.forEach(t=>t()),M.remove(),n.client||m.destroy()}};function le(){const t=x({display:"flex",gap:"4px",padding:"4px 0"});for(let s=0;s<3;s++){const c=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${s*.2}s`});t.appendChild(c)}return t}}function je(o){let n=[];const r=document.createElement("form");S(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${$}`,backgroundColor:z}),r.className="ago-chat-input";const e=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=o.placeholder,a.rows=1,S(a,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",fontSize:"14px",fontFamily:Ce,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const p=document.createElement("button");p.type="submit",p.textContent="Send",S(p,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:ve,color:ye,fontSize:"14px",fontWeight:"500",cursor:"pointer"});let i=null,f=null;o.allowFiles&&(i=document.createElement("input"),i.type="file",i.multiple=!0,S(i,{display:"none"}),f=document.createElement("button"),f.type="button",f.textContent="📎",S(f,{padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",backgroundColor:z,cursor:"pointer",fontSize:"14px"}),f.addEventListener("click",()=>i?.click()),i.addEventListener("change",()=>{n=[...n,...Array.from(i?.files??[])],d()}));function d(){e.replaceChildren(),n.forEach((g,_)=>{const F=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${$}`,borderRadius:"8px",fontSize:"12px"}),m=document.createElement("span");m.textContent=g.name;const O=document.createElement("button");O.type="button",O.textContent="×",S(O,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),O.addEventListener("click",()=>{n=n.filter((W,D)=>D!==_),d()}),F.append(m,O),e.appendChild(F)})}const b=()=>{const g=a.value,_=n;return a.value="",n=[],d(),{content:g,files:_}},N=()=>{const{content:g,files:_}=b();(g.trim()||_.length>0)&&o.onSend(g.trim(),_.length>0?_:void 0)};return r.addEventListener("submit",g=>{g.preventDefault(),N()}),a.addEventListener("keydown",g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),N())}),f&&u.appendChild(f),u.append(a,p),i&&r.appendChild(i),r.append(e,u),{inputRow:r,getValueAndClear:b,setDisabled:g=>{a.disabled=g,p.disabled=g,p.style.opacity=g?"0.6":"1",p.style.cursor=g?"not-allowed":"pointer"},focus:()=>a.focus()}}exports.mountChatWidget=qe;exports.renderMarkdown=ee;
|
package/dist/widget.d.cts
CHANGED
|
@@ -216,6 +216,11 @@ declare interface AgoClientEvents {
|
|
|
216
216
|
conversationId: string;
|
|
217
217
|
messageId: string;
|
|
218
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* The main answer text is done (backend emitted `status: "DONE"`), but follow-up
|
|
221
|
+
* replies may still be pending. Fires once, before `message:complete`.
|
|
222
|
+
*/
|
|
223
|
+
"message:answer-complete": AgoMessage;
|
|
219
224
|
"message:complete": AgoMessage;
|
|
220
225
|
"message:error": {
|
|
221
226
|
error: string;
|
|
@@ -586,8 +591,9 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
|
|
|
586
591
|
* Vue, or Angular required. Mirrors the React `<ChatWidget>`: it streams replies,
|
|
587
592
|
* renders clickable suggested replies, and installs conversational form collectors.
|
|
588
593
|
*
|
|
589
|
-
* Message content is rendered as
|
|
590
|
-
*
|
|
594
|
+
* Message content is rendered as GitHub-flavored markdown by a tiny built-in
|
|
595
|
+
* parser (no dependencies); all message text is HTML-escaped first (see
|
|
596
|
+
* {@link renderMarkdown}).
|
|
591
597
|
*
|
|
592
598
|
* ```ts
|
|
593
599
|
* import { mountChatWidget } from "@useago/sdk/widget";
|
|
@@ -678,6 +684,34 @@ export declare interface MountChatWidgetOptions {
|
|
|
678
684
|
}) => void;
|
|
679
685
|
}
|
|
680
686
|
|
|
687
|
+
/**
|
|
688
|
+
* Tiny, dependency-free markdown → DOM renderer for the vanilla chat widget.
|
|
689
|
+
*
|
|
690
|
+
* The React widget renders GitHub-flavored markdown via `react-markdown` +
|
|
691
|
+
* `remark-gfm`; bundling those into the framework-agnostic widget would defeat
|
|
692
|
+
* its "no dependencies" promise, so this is a hand-rolled subset that mirrors
|
|
693
|
+
* the visible styling of `react/components/Markdown.tsx`.
|
|
694
|
+
*
|
|
695
|
+
* Supported: paragraphs (single newline → `<br>`), ATX headings, **bold**,
|
|
696
|
+
* *italic*, ~~strikethrough~~, `inline code`, fenced code blocks, links,
|
|
697
|
+
* images, ordered/unordered (and nested) lists, blockquotes, horizontal rules,
|
|
698
|
+
* and GFM tables.
|
|
699
|
+
*
|
|
700
|
+
* ## Security
|
|
701
|
+
*
|
|
702
|
+
* The widget is embedded into third-party pages, so the agent's message content
|
|
703
|
+
* is untrusted. Every span of message text is HTML-escaped before it reaches the
|
|
704
|
+
* DOM; only a fixed set of safe tags is ever emitted, and `href`/`src` URLs are
|
|
705
|
+
* scheme-validated (see {@link safeUrl}) so `javascript:`/`data:` payloads can't
|
|
706
|
+
* slip through. Callers should append the returned fragment — never feed raw
|
|
707
|
+
* message content to `innerHTML` directly.
|
|
708
|
+
*/
|
|
709
|
+
/**
|
|
710
|
+
* Parse a markdown string into a {@link DocumentFragment} of safely-built block
|
|
711
|
+
* elements. Append it to the message bubble; do not stringify it back to HTML.
|
|
712
|
+
*/
|
|
713
|
+
export declare function renderMarkdown(source: string): DocumentFragment;
|
|
714
|
+
|
|
681
715
|
/**
|
|
682
716
|
* Options for sending a message
|
|
683
717
|
*/
|
package/dist/widget.d.ts
CHANGED
|
@@ -216,6 +216,11 @@ declare interface AgoClientEvents {
|
|
|
216
216
|
conversationId: string;
|
|
217
217
|
messageId: string;
|
|
218
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* The main answer text is done (backend emitted `status: "DONE"`), but follow-up
|
|
221
|
+
* replies may still be pending. Fires once, before `message:complete`.
|
|
222
|
+
*/
|
|
223
|
+
"message:answer-complete": AgoMessage;
|
|
219
224
|
"message:complete": AgoMessage;
|
|
220
225
|
"message:error": {
|
|
221
226
|
error: string;
|
|
@@ -586,8 +591,9 @@ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCEL
|
|
|
586
591
|
* Vue, or Angular required. Mirrors the React `<ChatWidget>`: it streams replies,
|
|
587
592
|
* renders clickable suggested replies, and installs conversational form collectors.
|
|
588
593
|
*
|
|
589
|
-
* Message content is rendered as
|
|
590
|
-
*
|
|
594
|
+
* Message content is rendered as GitHub-flavored markdown by a tiny built-in
|
|
595
|
+
* parser (no dependencies); all message text is HTML-escaped first (see
|
|
596
|
+
* {@link renderMarkdown}).
|
|
591
597
|
*
|
|
592
598
|
* ```ts
|
|
593
599
|
* import { mountChatWidget } from "@useago/sdk/widget";
|
|
@@ -678,6 +684,34 @@ export declare interface MountChatWidgetOptions {
|
|
|
678
684
|
}) => void;
|
|
679
685
|
}
|
|
680
686
|
|
|
687
|
+
/**
|
|
688
|
+
* Tiny, dependency-free markdown → DOM renderer for the vanilla chat widget.
|
|
689
|
+
*
|
|
690
|
+
* The React widget renders GitHub-flavored markdown via `react-markdown` +
|
|
691
|
+
* `remark-gfm`; bundling those into the framework-agnostic widget would defeat
|
|
692
|
+
* its "no dependencies" promise, so this is a hand-rolled subset that mirrors
|
|
693
|
+
* the visible styling of `react/components/Markdown.tsx`.
|
|
694
|
+
*
|
|
695
|
+
* Supported: paragraphs (single newline → `<br>`), ATX headings, **bold**,
|
|
696
|
+
* *italic*, ~~strikethrough~~, `inline code`, fenced code blocks, links,
|
|
697
|
+
* images, ordered/unordered (and nested) lists, blockquotes, horizontal rules,
|
|
698
|
+
* and GFM tables.
|
|
699
|
+
*
|
|
700
|
+
* ## Security
|
|
701
|
+
*
|
|
702
|
+
* The widget is embedded into third-party pages, so the agent's message content
|
|
703
|
+
* is untrusted. Every span of message text is HTML-escaped before it reaches the
|
|
704
|
+
* DOM; only a fixed set of safe tags is ever emitted, and `href`/`src` URLs are
|
|
705
|
+
* scheme-validated (see {@link safeUrl}) so `javascript:`/`data:` payloads can't
|
|
706
|
+
* slip through. Callers should append the returned fragment — never feed raw
|
|
707
|
+
* message content to `innerHTML` directly.
|
|
708
|
+
*/
|
|
709
|
+
/**
|
|
710
|
+
* Parse a markdown string into a {@link DocumentFragment} of safely-built block
|
|
711
|
+
* elements. Append it to the message bubble; do not stringify it back to HTML.
|
|
712
|
+
*/
|
|
713
|
+
export declare function renderMarkdown(source: string): DocumentFragment;
|
|
714
|
+
|
|
681
715
|
/**
|
|
682
716
|
* Options for sending a message
|
|
683
717
|
*/
|