@useago/sdk 1.0.9 → 1.0.10
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/devtools.cjs +7 -7
- package/dist/devtools.d.cts +11 -0
- package/dist/devtools.d.ts +11 -0
- package/dist/devtools.js +57 -54
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +8 -0
- package/dist/widget.d.ts +8 -0
- package/dist/widget.js +376 -354
- package/package.json +1 -1
package/dist/devtools.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function E(e,t,d){if(!e)return;const a=document.createElement("div");a.className=`dev-log-line dev-log-${d}`,a.textContent=`${new Date().toLocaleTimeString()} ${t}`,e.appendChild(a),e.scrollTop=e.scrollHeight}function k(e){let t;return e.type?t=e.type:e.content!==void 0?t="content":e.full_content!==void 0?t="full_content":e.status?t=`status:${e.status}`:t="event",`${t} ${JSON.stringify(e)}`}var T="ago_dev_panel_collapsed",N="ago_dev_events_collapsed";function u(e,t,d,a){e.classList.toggle("collapsed",t);const l=e.querySelector(".dev-toggle");l&&(l.textContent=t?"▢":"—",l.title=t?`Expand ${a}`:`Collapse ${a}`,l.setAttribute("aria-expanded",String(!t)));try{localStorage.setItem(d,t?"1":"0")}catch{}}function $(e,t,d){e.querySelector(".dev-toggle")?.addEventListener("click",l=>{l.stopPropagation(),u(e,!e.classList.contains("collapsed"),t,d)}),e.addEventListener("click",()=>{e.classList.contains("collapsed")&&u(e,!1,t,d)});let a=!1;try{a=localStorage.getItem(t)==="1"}catch{}u(e,a,t,d)}function _(e){const{client:t,target:d,label:a,side:l="right"}=e,f=document.querySelectorAll("#ago-dev-panel").length,x=f===0?"":`-${f+1}`,h=document.querySelectorAll(`#ago-dev-panel[data-ago-dev-side="${l}"]`).length,r=h>0?`${16+h*376}px`:"";let g=null,m=null,b=null;const L=()=>{const o=t.getContextSnapshot()?.entries??{};return Object.fromEntries(Object.entries(o).map(([n,{name:p,data:O}])=>[n,{name:p,data:O}]))},c=()=>{g&&(g.textContent=JSON.stringify(L(),null,2))},v=(o,n)=>{E(m,o,n)};q();const y=typeof d=="string"?document.querySelector(d):d instanceof Element?d:document.body,S=o=>{o.dataset.agoDevSide=l,l==="left"?(o.style.right="auto",o.style.left=r||"16px"):r&&(o.style.right=r)},s=document.createElement("aside");s.id="ago-dev-panel",s.className="ago-dev-card",S(s),(y??document.body).appendChild(s);const w=(t.getRegisteredFunctions?.()??[]).map(o=>o.name).join(", ")||"—";s.innerHTML=`
|
|
2
2
|
<div class="dev-head">
|
|
3
3
|
<span class="dev-badge">DEV</span>
|
|
4
|
-
<span class="dev-title"
|
|
4
|
+
<span class="dev-title">${a?`DEV TOOLS · ${a}`:"DEV TOOLS · client-side function state — not for production"}</span>
|
|
5
5
|
<button type="button" class="dev-toggle" aria-label="Toggle dev tools">—</button>
|
|
6
6
|
</div>
|
|
7
7
|
<div class="dev-body">
|
|
8
|
-
<div class="dev-fns">Registered functions: <code>${
|
|
8
|
+
<div class="dev-fns">Registered functions: <code>${w}</code></div>
|
|
9
9
|
<div class="dev-section-label">JSON object (built by the agent)</div>
|
|
10
10
|
<pre class="dev-state" id="ago-dev-state"></pre>
|
|
11
11
|
<div class="dev-section-label">Function calls</div>
|
|
12
12
|
<div class="dev-log" id="ago-dev-log"></div>
|
|
13
13
|
</div>
|
|
14
|
-
`,
|
|
14
|
+
`,g=s.querySelector(".dev-state"),m=s.querySelector(".dev-log"),$(s,T+x,"dev tools");const i=document.createElement("aside");i.id="ago-dev-events",i.className="ago-dev-card",S(i),(y??document.body).appendChild(i),i.innerHTML=`
|
|
15
15
|
<div class="dev-head">
|
|
16
16
|
<span class="dev-badge">SSE</span>
|
|
17
|
-
<span class="dev-title"
|
|
17
|
+
<span class="dev-title">${a?`SSE EVENT LOG · ${a}`:"SSE EVENT LOG · raw stream messages"}</span>
|
|
18
18
|
<button type="button" class="dev-toggle" aria-label="Toggle SSE event log">—</button>
|
|
19
19
|
</div>
|
|
20
20
|
<div class="dev-body">
|
|
21
21
|
<div class="dev-log" id="ago-dev-event-log"></div>
|
|
22
22
|
</div>
|
|
23
|
-
`,
|
|
23
|
+
`,b=i.querySelector(".dev-log"),$(i,N+x,"SSE event log"),t.on("stream:message",o=>{E(b,k(o),"event")}),t.on("function:invoke",({functionName:o,arguments:n})=>{v(`→ ${o}(${JSON.stringify(n??{})})`,"invoke")}),t.on("function:result",({result:o,error:n})=>{v(n?`✗ error: ${n}`:`← ${JSON.stringify(o)}`,n?"error":"result"),c()}),t.on("context:changed",c),t.on("conversation:loaded",o=>{const n=(o.messages??[]).flatMap(p=>p.toolCalls??[]);v(`⟳ hydrated "${o.title||o.id}" — replayed ${n.length} tool call${n.length===1?"":"s"}`,"hydrate"),c()}),c()}var C="ago-dev-panel-styles";function q(){if(document.getElementById(C))return;const e=document.createElement("style");e.id=C,e.textContent=z,document.head.appendChild(e)}var z=`
|
|
24
24
|
.ago-dev-card {
|
|
25
25
|
position: fixed;
|
|
26
26
|
right: 16px;
|
|
@@ -120,4 +120,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v,x,p,h=(
|
|
|
120
120
|
.ago-dev-card .dev-log-error { color: #fca5a5; }
|
|
121
121
|
.ago-dev-card .dev-log-hydrate { color: #d8b4fe; }
|
|
122
122
|
.ago-dev-card .dev-log-event { color: #7c8a99; }
|
|
123
|
-
`;exports.initDevPanel=
|
|
123
|
+
`;exports.initDevPanel=_;
|
package/dist/devtools.d.cts
CHANGED
|
@@ -468,6 +468,17 @@ export declare interface DevPanelOptions {
|
|
|
468
468
|
client: Pick<AgoClient, "on" | "getRegisteredFunctions" | "getContextSnapshot">;
|
|
469
469
|
/** Where to mount: a CSS selector, an Element, or `document.body` (default). */
|
|
470
470
|
target?: string | Element;
|
|
471
|
+
/**
|
|
472
|
+
* Which screen edge the panels pin to: `"right"` (default) or `"left"`. With
|
|
473
|
+
* several widgets on a page, give each panel the same side as its widget. Panels
|
|
474
|
+
* on the same side stack beside each other automatically.
|
|
475
|
+
*/
|
|
476
|
+
side?: "left" | "right";
|
|
477
|
+
/**
|
|
478
|
+
* Optional caption shown in the panel header. Handy when several panels share a
|
|
479
|
+
* page (one per widget): pass e.g. the agent or widget name to tell them apart.
|
|
480
|
+
*/
|
|
481
|
+
label?: string;
|
|
471
482
|
}
|
|
472
483
|
|
|
473
484
|
/**
|
package/dist/devtools.d.ts
CHANGED
|
@@ -468,6 +468,17 @@ export declare interface DevPanelOptions {
|
|
|
468
468
|
client: Pick<AgoClient, "on" | "getRegisteredFunctions" | "getContextSnapshot">;
|
|
469
469
|
/** Where to mount: a CSS selector, an Element, or `document.body` (default). */
|
|
470
470
|
target?: string | Element;
|
|
471
|
+
/**
|
|
472
|
+
* Which screen edge the panels pin to: `"right"` (default) or `"left"`. With
|
|
473
|
+
* several widgets on a page, give each panel the same side as its widget. Panels
|
|
474
|
+
* on the same side stack beside each other automatically.
|
|
475
|
+
*/
|
|
476
|
+
side?: "left" | "right";
|
|
477
|
+
/**
|
|
478
|
+
* Optional caption shown in the panel header. Handy when several panels share a
|
|
479
|
+
* page (one per widget): pass e.g. the agent or widget name to tell them apart.
|
|
480
|
+
*/
|
|
481
|
+
label?: string;
|
|
471
482
|
}
|
|
472
483
|
|
|
473
484
|
/**
|
package/dist/devtools.js
CHANGED
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
function i() {
|
|
3
|
-
v && (v.textContent = JSON.stringify(h(), null, 2));
|
|
4
|
-
}
|
|
5
|
-
function m(e, t, d) {
|
|
1
|
+
function E(e, t, d) {
|
|
6
2
|
if (!e) return;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
function c(e, t) {
|
|
11
|
-
m(x, e, t);
|
|
3
|
+
const a = document.createElement("div");
|
|
4
|
+
a.className = `dev-log-line dev-log-${d}`, a.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${t}`, e.appendChild(a), e.scrollTop = e.scrollHeight;
|
|
12
5
|
}
|
|
13
|
-
function
|
|
6
|
+
function O(e) {
|
|
14
7
|
let t;
|
|
15
8
|
return e.type ? t = e.type : e.content !== void 0 ? t = "content" : e.full_content !== void 0 ? t = "full_content" : e.status ? t = `status:${e.status}` : t = "event", `${t} ${JSON.stringify(e)}`;
|
|
16
9
|
}
|
|
17
|
-
var
|
|
18
|
-
function
|
|
10
|
+
var T = "ago_dev_panel_collapsed", N = "ago_dev_events_collapsed";
|
|
11
|
+
function u(e, t, d, a) {
|
|
19
12
|
e.classList.toggle("collapsed", t);
|
|
20
|
-
const
|
|
21
|
-
|
|
13
|
+
const l = e.querySelector(".dev-toggle");
|
|
14
|
+
l && (l.textContent = t ? "▢" : "—", l.title = t ? `Expand ${a}` : `Collapse ${a}`, l.setAttribute("aria-expanded", String(!t)));
|
|
22
15
|
try {
|
|
23
16
|
localStorage.setItem(d, t ? "1" : "0");
|
|
24
17
|
} catch {
|
|
25
18
|
}
|
|
26
19
|
}
|
|
27
|
-
function
|
|
28
|
-
e.querySelector(".dev-toggle")?.addEventListener("click", (
|
|
29
|
-
|
|
20
|
+
function $(e, t, d) {
|
|
21
|
+
e.querySelector(".dev-toggle")?.addEventListener("click", (l) => {
|
|
22
|
+
l.stopPropagation(), u(e, !e.classList.contains("collapsed"), t, d);
|
|
30
23
|
}), e.addEventListener("click", () => {
|
|
31
|
-
e.classList.contains("collapsed") &&
|
|
24
|
+
e.classList.contains("collapsed") && u(e, !1, t, d);
|
|
32
25
|
});
|
|
33
|
-
let
|
|
26
|
+
let a = !1;
|
|
34
27
|
try {
|
|
35
|
-
|
|
28
|
+
a = localStorage.getItem(t) === "1";
|
|
36
29
|
} catch {
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
u(e, a, t, d);
|
|
39
32
|
}
|
|
40
|
-
function
|
|
41
|
-
const { client: t, target: d } = e;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
function z(e) {
|
|
34
|
+
const { client: t, target: d, label: a, side: l = "right" } = e, f = document.querySelectorAll("#ago-dev-panel").length, x = f === 0 ? "" : `-${f + 1}`, h = document.querySelectorAll(`#ago-dev-panel[data-ago-dev-side="${l}"]`).length, r = h > 0 ? `${16 + h * 376}px` : "";
|
|
35
|
+
let g = null, m = null, b = null;
|
|
36
|
+
const L = () => {
|
|
37
|
+
const o = t.getContextSnapshot()?.entries ?? {};
|
|
38
|
+
return Object.fromEntries(Object.entries(o).map(([n, { name: p, data: k }]) => [n, {
|
|
39
|
+
name: p,
|
|
40
|
+
data: k
|
|
47
41
|
}]));
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
}, c = () => {
|
|
43
|
+
g && (g.textContent = JSON.stringify(L(), null, 2));
|
|
44
|
+
}, v = (o, n) => {
|
|
45
|
+
E(m, o, n);
|
|
46
|
+
};
|
|
47
|
+
_();
|
|
48
|
+
const y = typeof d == "string" ? document.querySelector(d) : d instanceof Element ? d : document.body, S = (o) => {
|
|
49
|
+
o.dataset.agoDevSide = l, l === "left" ? (o.style.right = "auto", o.style.left = r || "16px") : r && (o.style.right = r);
|
|
50
|
+
}, s = document.createElement("aside");
|
|
51
|
+
s.id = "ago-dev-panel", s.className = "ago-dev-card", S(s), (y ?? document.body).appendChild(s);
|
|
52
|
+
const w = (t.getRegisteredFunctions?.() ?? []).map((o) => o.name).join(", ") || "—";
|
|
53
|
+
s.innerHTML = `
|
|
51
54
|
<div class="dev-head">
|
|
52
55
|
<span class="dev-badge">DEV</span>
|
|
53
|
-
<span class="dev-title"
|
|
56
|
+
<span class="dev-title">${a ? `DEV TOOLS · ${a}` : "DEV TOOLS · client-side function state — not for production"}</span>
|
|
54
57
|
<button type="button" class="dev-toggle" aria-label="Toggle dev tools">—</button>
|
|
55
58
|
</div>
|
|
56
59
|
<div class="dev-body">
|
|
57
|
-
<div class="dev-fns">Registered functions: <code>${
|
|
60
|
+
<div class="dev-fns">Registered functions: <code>${w}</code></div>
|
|
58
61
|
<div class="dev-section-label">JSON object (built by the agent)</div>
|
|
59
62
|
<pre class="dev-state" id="ago-dev-state"></pre>
|
|
60
63
|
<div class="dev-section-label">Function calls</div>
|
|
61
64
|
<div class="dev-log" id="ago-dev-log"></div>
|
|
62
65
|
</div>
|
|
63
|
-
`,
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
+
`, g = s.querySelector(".dev-state"), m = s.querySelector(".dev-log"), $(s, T + x, "dev tools");
|
|
67
|
+
const i = document.createElement("aside");
|
|
68
|
+
i.id = "ago-dev-events", i.className = "ago-dev-card", S(i), (y ?? document.body).appendChild(i), i.innerHTML = `
|
|
66
69
|
<div class="dev-head">
|
|
67
70
|
<span class="dev-badge">SSE</span>
|
|
68
|
-
<span class="dev-title"
|
|
71
|
+
<span class="dev-title">${a ? `SSE EVENT LOG · ${a}` : "SSE EVENT LOG · raw stream messages"}</span>
|
|
69
72
|
<button type="button" class="dev-toggle" aria-label="Toggle SSE event log">—</button>
|
|
70
73
|
</div>
|
|
71
74
|
<div class="dev-body">
|
|
72
75
|
<div class="dev-log" id="ago-dev-event-log"></div>
|
|
73
76
|
</div>
|
|
74
|
-
`,
|
|
75
|
-
|
|
76
|
-
}), t.on("function:invoke", ({ functionName:
|
|
77
|
-
|
|
78
|
-
}), t.on("function:result", ({ result:
|
|
79
|
-
|
|
80
|
-
}), t.on("context:changed",
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
}),
|
|
77
|
+
`, b = i.querySelector(".dev-log"), $(i, N + x, "SSE event log"), t.on("stream:message", (o) => {
|
|
78
|
+
E(b, O(o), "event");
|
|
79
|
+
}), t.on("function:invoke", ({ functionName: o, arguments: n }) => {
|
|
80
|
+
v(`→ ${o}(${JSON.stringify(n ?? {})})`, "invoke");
|
|
81
|
+
}), t.on("function:result", ({ result: o, error: n }) => {
|
|
82
|
+
v(n ? `✗ error: ${n}` : `← ${JSON.stringify(o)}`, n ? "error" : "result"), c();
|
|
83
|
+
}), t.on("context:changed", c), t.on("conversation:loaded", (o) => {
|
|
84
|
+
const n = (o.messages ?? []).flatMap((p) => p.toolCalls ?? []);
|
|
85
|
+
v(`⟳ hydrated "${o.title || o.id}" — replayed ${n.length} tool call${n.length === 1 ? "" : "s"}`, "hydrate"), c();
|
|
86
|
+
}), c();
|
|
84
87
|
}
|
|
85
|
-
var
|
|
86
|
-
function
|
|
87
|
-
if (document.getElementById(
|
|
88
|
+
var C = "ago-dev-panel-styles";
|
|
89
|
+
function _() {
|
|
90
|
+
if (document.getElementById(C)) return;
|
|
88
91
|
const e = document.createElement("style");
|
|
89
|
-
e.id =
|
|
92
|
+
e.id = C, e.textContent = q, document.head.appendChild(e);
|
|
90
93
|
}
|
|
91
|
-
var
|
|
94
|
+
var q = `
|
|
92
95
|
.ago-dev-card {
|
|
93
96
|
position: fixed;
|
|
94
97
|
right: 16px;
|
|
@@ -190,5 +193,5 @@ var w = `
|
|
|
190
193
|
.ago-dev-card .dev-log-event { color: #7c8a99; }
|
|
191
194
|
`;
|
|
192
195
|
export {
|
|
193
|
-
|
|
196
|
+
z as initDevPanel
|
|
194
197
|
};
|
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Fe=require("./AgoClient-B3-WGVne.cjs"),ze=require("./createFormCollector-BI3DXaew.cjs"),pt=require("./createConversationSession-C0diFTUk.cjs");var ft={"&":"&","<":"<",">":">",'"':""","'":"'"};function j(r){return r.replace(/[&<>"']/g,o=>ft[o])}function He(r){const o=r.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var Xe='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',ee="";function H(r){const o=[],a=g=>(o.push(g),`${ee}${o.length-1}${ee}`);let t=r;return t=t.replace(/`([^`]+)`/g,(g,s)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Xe}">${j(s)}</code>`)),t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(g,s,u)=>{const l=He(u);return l?a(`<img alt="${j(s)}" src="${j(l)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):g}),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(g,s,u)=>{const l=He(u);return l?a(`<a href="${j(l)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${H(s)}</a>`):g}),t=j(t),t=t.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>"),t=t.replace(new RegExp(`${ee}(\\d+)${ee}`,"g"),(g,s)=>o[Number(s)]),t}function k(r,o,a){const t=document.createElement(r);return Object.assign(t.style,o),a!==void 0&&(t.innerHTML=a),t}var Ke=/^ {0,3}([-*_])( *\1){2,} *$/,Ve=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Qe=/^ {0,3}(```+|~~~+)/,ne=/^ {0,3}>\s?/,q=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,ut=["20px","18px","16px","15px","14px","13px"],ye=r=>r.match(/^\s*/)?.[0].length??0;function gt(r){return r.trim()===""||Ke.test(r)||Ve.test(r)||Qe.test(r)||ne.test(r)||q.test(r)}function Ye(r){const o=r[0].match(q),a=o[1].length,t=/\d/.test(o[2]),g=k(t?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:t?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<r.length;){const u=r[s].match(q),l=[];for(s++;s<r.length&&ye(r[s])>a;)l.push(r[s]),s++;const p=k("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=u[3].match(/^\[([ xX])\]\s+(.*)$/);c?(p.style.listStyleType="none",p.style.marginLeft="-20px",p.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${H(c[2])}`):p.innerHTML=H(u[3]),l.filter(x=>q.test(x)).length>0&&p.appendChild(Ye(l.filter(x=>x.trim()!==""))),g.appendChild(p)}return g}function mt(r){const o=l=>l.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(p=>p.trim()),a=k("div",{overflowX:"auto",margin:"0 0 8px 0"}),t=k("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),g=document.createElement("thead"),s=document.createElement("tr");for(const l of o(r[0]))s.appendChild(k("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},H(l)));g.appendChild(s),t.appendChild(g);const u=document.createElement("tbody");for(const l of r.slice(2)){const p=document.createElement("tr");for(const c of o(l))p.appendChild(k("td",{border:"1px solid #dee3e8",padding:"6px 10px"},H(c)));u.appendChild(p)}return t.appendChild(u),a.appendChild(t),a}var ht=r=>!!r&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);function re(r){const o=document.createDocumentFragment(),a=r.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let t=0;for(;t<a.length;){const s=a[t];if(s.trim()===""){t++;continue}const
|
|
4
|
-
`)))),o.appendChild(
|
|
5
|
-
`))),o.appendChild(h);continue}if(s.includes("|")&&ct(a[t+1])){const c=[s,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;o.appendChild(dt(c));continue}if(W.test(s)){const c=[],h=he(s);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||he(a[t])>h)c.push(a[t]),t++;else break;o.appendChild(je(c));continue}const p=[s];for(t++;t<a.length&&!lt(a[t]);)p.push(a[t]),t++;o.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>M(c)).join("<br>")))}const u=o.lastElementChild;return u&&(u.style.marginBottom="0"),o}var xe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Me={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",agentBubbleBg:"--ago-agent-bubble-background"},be="var(--ago-brand-color, #03182f)",Ce="var(--ago-brand-text-color, #fff)",pt="var(--ago-header-background, var(--ago-brand-color, #03182f))",Fe="var(--ago-header-text-color, #e8f0fe)",X="var(--ago-panel-background, #fff)",ft="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",ut="var(--ago-muted-text-color, #6b6d6f)",A="var(--ago-border-color, #dee3e8)",ge="var(--ago-accent-color, #1b5fc4)",gt="var(--ago-agent-bubble-background, #f1f3f5)",mt="var(--ago-radius, 16px)",me="var(--ago-message-radius, 16px)";function ht(r,o){if(o)for(const a of Object.keys(Me)){const t=o[a];t!=null&&r.style.setProperty(Me[a],t)}}function E(r,o){Object.assign(r.style,o)}function b(r={}){const o=document.createElement("div");return E(o,r),o}var ze="Form submitted.";function xt(r){if(typeof r=="string")return r||null;if(!r||typeof r!="object")return null;const o=r;if(typeof o.message=="string"&&o.message)return o.message;const a=o.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const t=a.message;if(typeof t=="string"&&t)return t}return null}var He="ago-chat-widget-keyframes";function bt(){if(typeof document>"u"||document.getElementById(He))return;const r=document.createElement("style");r.id=He,r.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(r)}function Ct(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function yt(r,o){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:s=!1,height:f=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:h,showAgentName:N=!1,agentBubble:g=!1,showHeader:I=!0,theme:K,loadThreads:P=!1,forms:T,formSubmittedMessage:G=ze,onFollowUpClick:j,onMessageSent:qe,onMessageReceived:Xe,onFormSubmitted:ne,onFormError:oe}=o;if(!o.client&&!o.config?.baseUrl)throw new Oe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const m=o.client??new Oe.AgoClient(o.config),ye=Ct(r),F=l==="left"||l==="right",Ke=F&&(o.launcher??!0);let z=F?c:!0;const re=o.persistConversation,V=re?at.createConversationSession(re===!0?{}:re):void 0;let _=o.conversationId??V?.getLastActiveThread()??void 0,d=[],L=!1,q=null;const ve=[];function Ve(e){if(typeof G=="function"){const i=G(e);if(typeof i=="string"&&i)return i}const n=xt(e);return n||(typeof G=="string"?G:ze)}const Q=[],H=b({display:"flex",flexDirection:"column",height:F?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${A}`,borderRadius:mt,overflow:"hidden",backgroundColor:X,fontFamily:xe,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",ht(H,K);let O;if(I){if(O=b({padding:"14px 16px",borderBottom:`1px solid ${A}`,backgroundColor:pt,color:Fe,display:"flex",alignItems:"center",gap:"10px"}),O.className="ago-chat-widget__header",h){const n=document.createElement("img");n.src=h,n.alt="Logo",E(n,{height:"24px",width:"auto"}),O.appendChild(n)}const e=document.createElement("h3");if(e.textContent=a,E(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),O.appendChild(e),F){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",E(n,{marginLeft:"auto",background:"transparent",border:"none",color:Fe,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>fe()),O.appendChild(n)}}const $=b({flex:"1",overflow:"auto",padding:"16px",backgroundColor:ft});$.className="ago-chat-widget__messages";const{inputRow:Qe,setDisabled:Ye,focus:ae}=vt({placeholder:u,allowFiles:s,onSend:(e,n)=>{le(e,n)}});bt(),H.append(...O?[O]:[],$,Qe);let Y=H,D,S;const ie=l==="left"?"left":"right";if(F&&(D=b({position:"fixed",top:"0",bottom:"0",[ie]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),D.className="ago-chat-widget-panel",E(H,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ie==="left"?"borderRight":"borderLeft"]:`1px solid ${A}`}),D.appendChild(H),Y=D),Ke){if(S=document.createElement("button"),S.type="button",S.className="ago-chat-widget-launcher",S.setAttribute("aria-label",`Open ${a}`),E(S,{position:"fixed",bottom:"20px",[ie]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:be,color:Ce,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:xe}),h){const e=document.createElement("img");e.src=h,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(ot());S.addEventListener("click",()=>pe())}ye.appendChild(Y),S&&ye.appendChild(S),ce();const Ee=j!==!1,we=j===!1?void 0:j??(e=>{le(e)});function Ze(e,n){const i=e.role==="user",x=b({display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"});if(x.className=`ago-message ago-message--${e.role}`,!i&&N&&e.agent){const C=b({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,x.appendChild(C)}if(!i&&e.sources&&e.sources.length>0){const C=b({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((y,w)=>{const B=y.url?document.createElement("a"):document.createElement("div");y.url&&B instanceof HTMLAnchorElement&&(B.href=y.url,B.target="_blank",B.rel="noopener noreferrer"),E(B,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${A}`,borderRadius:"8px",backgroundColor:X,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const Le=b({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${ge}`,color:ge,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Le.textContent=String(w+1);const ue=b({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ue.textContent=y.title,ue.title=y.title,B.append(Le,ue),C.appendChild(B)}),x.appendChild(C)}const v=b({maxWidth:i?"75%":g?"85%":"100%",padding:i||g?"10px 14px":"2px 8px",borderRadius:i||g?me:"0",backgroundColor:i?be:g?gt:"transparent",color:i?Ce:J,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(te(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(rt()),x.appendChild(v),n&&e.followUpReplies&&e.followUpReplies.length>0){const C=b({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const y of e.followUpReplies){const w=document.createElement("button");w.type="button",w.className="ago-message__followup-btn",w.textContent=y,w.disabled=!Ee,E(w,{padding:"6px 14px",fontSize:"14px",borderRadius:me,border:`1px solid ${A}`,backgroundColor:X,color:J,cursor:Ee?"pointer":"default",transition:"border-color 0.15s"}),we&&w.addEventListener("click",()=>we(y)),w.addEventListener("mouseenter",()=>{w.style.borderColor=ge}),w.addEventListener("mouseleave",()=>{w.style.borderColor=A}),C.appendChild(w)}x.appendChild(C)}return x}function Je(e){const n=b({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:me,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});n.className="ago-form-notice",n.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),E(i,{fontWeight:"700"});const x=document.createElement("span");return x.textContent=e,n.append(i,x),n}function k(){if($.replaceChildren(),d.length===0){const n=b({textAlign:"center",color:ut,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(te(t)),$.appendChild(n)}else d.forEach((n,i)=>{$.appendChild(Ze(n,i===d.length-1))});for(const n of ve)$.appendChild(Je(n));if(q){const n=b({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.textContent=q,$.appendChild(n)}$.scrollTop=$.scrollHeight;const e=d[d.length-1];Ye(L&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function et(){for(let e=d.length-1;e>=0;e--){const n=d[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Se=e=>{_||(_=e.conversationId)},Re=e=>{const n=et();n&&(n.content+=e.content,k())},_e=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),k(),ae()},ke=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),L=!1,k(),e.status==="DONE"&&Xe?.({id:e.id,content:e.content})},Ae=e=>{q=e.error,L=!1,d=d.filter(n=>!n.id.startsWith("temp-")),k()};m.on("message:start",Se),m.on("message:chunk",Re),m.on("message:answer-complete",_e),m.on("message:complete",ke),m.on("message:error",Ae);const Ie=e=>ne?.(e),$e=e=>oe?.(e);ne&&m.on("form:submitted",Ie),oe&&m.on("form:error",$e);const se=[];let Ne=!1;const Te=e=>{if(Ne)return;se.push(e.install(m));let n=e.store.get().submitted;const i=e.store.subscribe(x=>{x.submitted&&!n&&(ve.push(Ve(x.submitResult)),k()),n=x.submitted});se.push(i)};for(const e of T??[])e.schema!=null?Te(De.createFormCollector(e)):De.loadFormCollector(m,e).then(n=>Te(n)).catch(()=>{});async function le(e,n){const i=e.trim();if(!i&&!n?.length||L)return;qe?.(i),L=!0,q=null;const x=Date.now();d.push({id:`temp-user-${x}`,conversationId:_||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${x}`,conversationId:_||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const v=await m.sendMessage(i,{conversationId:_,files:n});v.conversationId&&(_||(_=v.conversationId),V?.setActiveThread(v.conversationId,v.createdAt));const C=d.find(y=>y.id===`temp-user-${x}`);if(C&&(C.id=`user-${x}`,C.conversationId=v.conversationId),!d.some(y=>y.id===v.id)){const y=d.findIndex(w=>w.id===`temp-assistant-${x}`);y>=0?d[y]=v:d.push(v)}d=d.filter(y=>!y.id.startsWith("temp-")),L=!1,k(),P&&de()}catch(v){q=v instanceof Error?v.message:"Failed to send message",L=!1,d=d.filter(C=>!C.id.startsWith("temp-")),k()}}async function de(){try{const e=await m.getConversations();Q.splice(0,Q.length,...e)}catch{}return Q}async function tt(e){try{const n=(await m.getConversation(e))?.messages??[];n.length>0&&d.length===0&&(d=n,k())}catch{d.length===0&&(V?.clear(),_=void 0)}}return k(),ae(),_&&tt(_),P&&de(),{client:m,element:Y,sendMessage:le,...F?{open:pe,close:fe,toggle:nt}:{},session:V,threads:Q,refreshThreads:de,destroy(){m.off("message:start",Se),m.off("message:chunk",Re),m.off("message:answer-complete",_e),m.off("message:complete",ke),m.off("message:error",Ae),ne&&m.off("form:submitted",Ie),oe&&m.off("form:error",$e),Ne=!0,se.forEach(e=>e()),Y.remove(),S?.remove(),o.client||m.destroy()}};function ce(){if(!D)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";D.style.transform=z?"translateX(0)":e,D.setAttribute("aria-hidden",z?"false":"true"),S&&(S.style.display=z?"none":"flex")}function pe(){z=!0,ce(),ae()}function fe(){z=!1,ce()}function nt(){z?fe():pe()}function ot(){const e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("width","26"),n.setAttribute("height","26"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none");const i=document.createElementNS(e,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),n.appendChild(i),n}function rt(){const e=b({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const i=b({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${n*.2}s`});e.appendChild(i)}return e}}function vt(r){let o=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${A}`,backgroundColor:X}),a.className="ago-chat-input";const t=b({display:"flex",flexWrap:"wrap",gap:"6px"}),u=b({display:"flex",gap:"8px",alignItems:"flex-end"}),s=document.createElement("textarea");s.placeholder=r.placeholder,s.rows=1,E(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",fontSize:"16px",fontFamily:xe,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",E(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:be,color:Ce,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;r.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,E(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",E(p,{padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",backgroundColor:X,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{o=[...o,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),o.forEach((g,I)=>{const K=b({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${A}`,borderRadius:"8px",fontSize:"12px"}),P=document.createElement("span");P.textContent=g.name;const T=document.createElement("button");T.type="button",T.textContent="×",E(T,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),T.addEventListener("click",()=>{o=o.filter((G,j)=>j!==I),c()}),K.append(P,T),t.appendChild(K)})}const h=()=>{const g=s.value,I=o;return s.value="",o=[],c(),{content:g,files:I}},N=()=>{const{content:g,files:I}=h();(g.trim()||I.length>0)&&r.onSend(g.trim(),I.length>0?I:void 0)};return a.addEventListener("submit",g=>{g.preventDefault(),N()}),s.addEventListener("keydown",g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),N())}),p&&u.appendChild(p),u.append(s,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:h,setDisabled:g=>{s.disabled=g,f.disabled=g,f.style.opacity=g?"0.6":"1",f.style.cursor=g?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=yt;exports.renderMarkdown=te;
|
|
3
|
+
`);let t=0;for(;t<a.length;){const s=a[t];if(s.trim()===""){t++;continue}const u=s.match(Qe);if(u){const c=u[1][0],x=[];for(t++;t<a.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[t]);)x.push(a[t]),t++;t++;const B=k("pre",{margin:"0 0 8px 0"});B.appendChild(k("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Xe,whiteSpace:"pre"},j(x.join(`
|
|
4
|
+
`)))),o.appendChild(B);continue}if(Ke.test(s)){o.appendChild(k("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),t++;continue}const l=s.match(Ve);if(l){const c=l[1].length;o.appendChild(k(`h${c}`,{margin:"16px 0 8px 0",fontSize:ut[c-1],fontWeight:"600",lineHeight:"1.3"},H(l[2]))),t++;continue}if(ne.test(s)){const c=[];for(;t<a.length&&ne.test(a[t]);)c.push(a[t].replace(ne,"")),t++;const x=k("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});x.appendChild(re(c.join(`
|
|
5
|
+
`))),o.appendChild(x);continue}if(s.includes("|")&&ht(a[t+1])){const c=[s,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;o.appendChild(mt(c));continue}if(q.test(s)){const c=[],x=ye(s);for(;t<a.length&&a[t].trim()!=="";)if(q.test(a[t])||ye(a[t])>x)c.push(a[t]),t++;else break;o.appendChild(Ye(c));continue}const p=[s];for(t++;t<a.length&&!gt(a[t]);)p.push(a[t]),t++;o.appendChild(k("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>H(c)).join("<br>")))}const g=o.lastElementChild;return g&&(g.style.marginBottom="0"),o}var ve='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Ue={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",agentBubbleBg:"--ago-agent-bubble-background"},oe="var(--ago-brand-color, #03182f)",Ee="var(--ago-brand-text-color, #fff)",xt="var(--ago-header-background, var(--ago-brand-color, #03182f))",We="var(--ago-header-text-color, #e8f0fe)",K="var(--ago-panel-background, #fff)",Pe="var(--ago-messages-background, #fbfbfb)",te="var(--ago-text-color, #30373e)",bt="var(--ago-muted-text-color, #6b6d6f)",N="var(--ago-border-color, #dee3e8)",be="var(--ago-accent-color, #1b5fc4)",Ge="var(--ago-agent-bubble-background, #f1f3f5)",Ct="var(--ago-radius, 16px)",Ce="var(--ago-message-radius, 16px)";function yt(r,o){if(o)for(const a of Object.keys(Ue)){const t=o[a];t!=null&&r.style.setProperty(Ue[a],t)}}function v(r,o){Object.assign(r.style,o)}function h(r={}){const o=document.createElement("div");return v(o,r),o}var je="Form submitted.";function vt(r){if(typeof r=="string")return r||null;if(!r||typeof r!="object")return null;const o=r;if(typeof o.message=="string"&&o.message)return o.message;const a=o.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const t=a.message;if(typeof t=="string"&&t)return t}return null}var qe="ago-chat-widget-keyframes";function Et(){if(typeof document>"u"||document.getElementById(qe))return;const r=document.createElement("style");r.id=qe,r.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(r)}function wt(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function St(r,o){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:g="Type a message...",allowFiles:s=!1,height:u=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:x,showAgentName:B=!1,agentBubble:b=!1,bubbleStyle:L="default",showHeader:V=!0,theme:Q,loadThreads:O=!1,forms:we,formSubmittedMessage:U=je,onFollowUpClick:ae,onMessageSent:Ze,onMessageReceived:Je,onFormSubmitted:se,onFormError:ie}=o;if(!o.client&&!o.config?.baseUrl)throw new Fe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const m=o.client??new Fe.AgoClient(o.config),Se=wt(r),W=l==="left"||l==="right",et=W&&(o.launcher??!0);let P=W?c:!0;const le=o.persistConversation,Y=le?pt.createConversationSession(le===!0?{}:le):void 0;let A=o.conversationId??Y?.getLastActiveThread()??void 0,d=[],D=!1,X=null;const Re=[];function tt(e){if(typeof U=="function"){const i=U(e);if(typeof i=="string"&&i)return i}const n=vt(e);return n||(typeof U=="string"?U:je)}const Z=[],G=h({display:"flex",flexDirection:"column",height:W?"100%":typeof u=="number"?`${u}px`:u,border:`1px solid ${N}`,borderRadius:Ct,overflow:"hidden",backgroundColor:K,fontFamily:ve,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});G.className="ago-chat-widget",yt(G,Q);let M;if(V){if(M=h({padding:"14px 16px",borderBottom:`1px solid ${N}`,backgroundColor:xt,color:We,display:"flex",alignItems:"center",gap:"10px"}),M.className="ago-chat-widget__header",x){const n=document.createElement("img");n.src=x,n.alt="Logo",v(n,{height:"24px",width:"auto"}),M.appendChild(n)}const e=document.createElement("h3");if(e.textContent=a,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),M.appendChild(e),W){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",v(n,{marginLeft:"auto",background:"transparent",border:"none",color:We,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>he()),M.appendChild(n)}}const T=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:Pe});T.className="ago-chat-widget__messages";const{inputRow:nt,setDisabled:ot,focus:de}=Rt({placeholder:g,allowFiles:s,onSend:(e,n)=>{fe(e,n)}});Et(),G.append(...M?[M]:[],T,nt);let J=G,F,w;const ce=l==="left"?"left":"right";if(W&&(F=h({position:"fixed",top:"0",bottom:"0",[ce]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),F.className="ago-chat-widget-panel",v(G,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ce==="left"?"borderRight":"borderLeft"]:`1px solid ${N}`}),F.appendChild(G),J=F),et){if(w=document.createElement("button"),w.type="button",w.className="ago-chat-widget-launcher",w.setAttribute("aria-label",`Open ${a}`),v(w,{position:"fixed",bottom:"20px",[ce]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:oe,color:Ee,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:ve}),x){const e=document.createElement("img");e.src=x,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),w.appendChild(e)}else w.appendChild(dt());w.addEventListener("click",()=>me())}Se.appendChild(J),w&&Se.appendChild(w),ge();const _e=ae!==!1,ke=ae===!1?void 0:ae??(e=>{fe(e)});function rt(e,n,i=!0){const f=e.role==="user",y=L==="imessage",_=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:y&&!i?"2px":"16px"});if(_.className=`ago-message ago-message--${e.role}`,!f&&B&&e.agent){const C=h({fontSize:"13px",fontWeight:"500",color:te,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,_.appendChild(C)}if(!f&&e.sources&&e.sources.length>0){const C=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((E,R)=>{const z=E.url?document.createElement("a"):document.createElement("div");E.url&&z instanceof HTMLAnchorElement&&(z.href=E.url,z.target="_blank",z.rel="noopener noreferrer"),v(z,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${N}`,borderRadius:"8px",backgroundColor:K,textDecoration:"none",color:te,fontSize:"12px",overflow:"hidden"});const Me=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${be}`,color:be,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Me.textContent=String(R+1);const xe=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});xe.textContent=E.title,xe.title=E.title,z.append(Me,xe),C.appendChild(z)}),_.appendChild(C)}const S=f||b||y,$=h({maxWidth:y||f?"75%":S?"85%":"100%",padding:S?"10px 14px":"2px 8px",borderRadius:S?Ce:"0",backgroundColor:f?oe:S?Ge:"transparent",color:f?Ee:te,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if($.className="ago-message__content",y&&i){$.style.position="relative",f?$.style.borderBottomRightRadius="4px":$.style.borderBottomLeftRadius="4px";const C=h({position:"absolute",zIndex:"0",bottom:"0",width:"20px",height:"20px",background:f?oe:Ge});C.className="ago-message__tail";const E=h({position:"absolute",zIndex:"1",bottom:"0",width:"10px",height:"20px",background:Pe});E.className="ago-message__tail-mask",f?(C.style.right="-8px",C.style.borderBottomLeftRadius="15px",E.style.right="-10px",E.style.borderBottomLeftRadius="10px"):(C.style.left="-7px",C.style.borderBottomRightRadius="15px",E.style.left="-10px",E.style.borderBottomRightRadius="10px"),$.append(C,E)}if(e.content?$.appendChild(re(e.content)):e.status==="IN_PROGRESS"&&$.appendChild(ct()),_.appendChild($),n&&e.followUpReplies&&e.followUpReplies.length>0){const C=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const E of e.followUpReplies){const R=document.createElement("button");R.type="button",R.className="ago-message__followup-btn",R.textContent=E,R.disabled=!_e,v(R,{padding:"6px 14px",fontSize:"14px",borderRadius:Ce,border:`1px solid ${N}`,backgroundColor:K,color:te,cursor:_e?"pointer":"default",transition:"border-color 0.15s"}),ke&&R.addEventListener("click",()=>ke(E)),R.addEventListener("mouseenter",()=>{R.style.borderColor=be}),R.addEventListener("mouseleave",()=>{R.style.borderColor=N}),C.appendChild(R)}_.appendChild(C)}return _}function at(e){const n=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:Ce,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});n.className="ago-form-notice",n.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const f=document.createElement("span");return f.textContent=e,n.append(i,f),n}function I(){if(T.replaceChildren(),d.length===0){const n=h({textAlign:"center",color:bt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(re(t)),T.appendChild(n)}else d.forEach((n,i)=>{const f=i===d.length-1||d[i+1].role!==n.role;T.appendChild(rt(n,i===d.length-1,f))});for(const n of Re)T.appendChild(at(n));if(X){const n=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.textContent=X,T.appendChild(n)}T.scrollTop=T.scrollHeight;const e=d[d.length-1];ot(D&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function st(){for(let e=d.length-1;e>=0;e--){const n=d[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Ae=e=>{A||(A=e.conversationId)},Ie=e=>{const n=st();n&&(n.content+=e.content,I())},$e=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),I(),de()},Ne=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),D=!1,I(),e.status==="DONE"&&Je?.({id:e.id,content:e.content})},Le=e=>{X=e.error,D=!1,d=d.filter(n=>!n.id.startsWith("temp-")),I()};m.on("message:start",Ae),m.on("message:chunk",Ie),m.on("message:answer-complete",$e),m.on("message:complete",Ne),m.on("message:error",Le);const Te=e=>se?.(e),Oe=e=>ie?.(e);se&&m.on("form:submitted",Te),ie&&m.on("form:error",Oe);const pe=[];let Be=!1;const De=e=>{if(Be)return;pe.push(e.install(m));let n=e.store.get().submitted;const i=e.store.subscribe(f=>{f.submitted&&!n&&(Re.push(tt(f.submitResult)),I()),n=f.submitted});pe.push(i)};for(const e of we??[])e.schema!=null?De(ze.createFormCollector(e)):ze.loadFormCollector(m,e).then(n=>De(n)).catch(()=>{});async function fe(e,n){const i=e.trim();if(!i&&!n?.length||D)return;Ze?.(i),D=!0,X=null;const f=Date.now();d.push({id:`temp-user-${f}`,conversationId:A||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${f}`,conversationId:A||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),I();try{const y=await m.sendMessage(i,{conversationId:A,files:n});y.conversationId&&(A||(A=y.conversationId),Y?.setActiveThread(y.conversationId,y.createdAt));const _=d.find(S=>S.id===`temp-user-${f}`);if(_&&(_.id=`user-${f}`,_.conversationId=y.conversationId),!d.some(S=>S.id===y.id)){const S=d.findIndex($=>$.id===`temp-assistant-${f}`);S>=0?d[S]=y:d.push(y)}d=d.filter(S=>!S.id.startsWith("temp-")),D=!1,I(),O&&ue()}catch(y){X=y instanceof Error?y.message:"Failed to send message",D=!1,d=d.filter(_=>!_.id.startsWith("temp-")),I()}}async function ue(){try{const e=await m.getConversations();Z.splice(0,Z.length,...e)}catch{}return Z}async function it(e){try{const n=(await m.getConversation(e))?.messages??[];n.length>0&&d.length===0&&(d=n,I())}catch{d.length===0&&(Y?.clear(),A=void 0)}}return I(),de(),A&&it(A),O&&ue(),{client:m,element:J,sendMessage:fe,...W?{open:me,close:he,toggle:lt}:{},session:Y,threads:Z,refreshThreads:ue,destroy(){m.off("message:start",Ae),m.off("message:chunk",Ie),m.off("message:answer-complete",$e),m.off("message:complete",Ne),m.off("message:error",Le),se&&m.off("form:submitted",Te),ie&&m.off("form:error",Oe),Be=!0,pe.forEach(e=>e()),J.remove(),w?.remove(),o.client||m.destroy()}};function ge(){if(!F)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";F.style.transform=P?"translateX(0)":e,F.setAttribute("aria-hidden",P?"false":"true"),w&&(w.style.display=P?"none":"flex")}function me(){P=!0,ge(),de()}function he(){P=!1,ge()}function lt(){P?he():me()}function dt(){const e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("width","26"),n.setAttribute("height","26"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none");const i=document.createElementNS(e,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),n.appendChild(i),n}function ct(){const e=h({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${n*.2}s`});e.appendChild(i)}return e}}function Rt(r){let o=[];const a=document.createElement("form");v(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${N}`,backgroundColor:K}),a.className="ago-chat-input";const t=h({display:"flex",flexWrap:"wrap",gap:"6px"}),g=h({display:"flex",gap:"8px",alignItems:"flex-end"}),s=document.createElement("textarea");s.placeholder=r.placeholder,s.rows=1,v(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",fontSize:"16px",fontFamily:ve,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const u=document.createElement("button");u.type="submit",u.textContent="Send",v(u,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:oe,color:Ee,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;r.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,v(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",v(p,{padding:"10px 12px",border:`1px solid ${N}`,borderRadius:"12px",backgroundColor:K,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{o=[...o,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),o.forEach((b,L)=>{const V=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${N}`,borderRadius:"8px",fontSize:"12px"}),Q=document.createElement("span");Q.textContent=b.name;const O=document.createElement("button");O.type="button",O.textContent="×",v(O,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),O.addEventListener("click",()=>{o=o.filter((we,U)=>U!==L),c()}),V.append(Q,O),t.appendChild(V)})}const x=()=>{const b=s.value,L=o;return s.value="",o=[],c(),{content:b,files:L}},B=()=>{const{content:b,files:L}=x();(b.trim()||L.length>0)&&r.onSend(b.trim(),L.length>0?L:void 0)};return a.addEventListener("submit",b=>{b.preventDefault(),B()}),s.addEventListener("keydown",b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),B())}),p&&g.appendChild(p),g.append(s,u),l&&a.appendChild(l),a.append(t,g),{inputRow:a,getValueAndClear:x,setDisabled:b=>{s.disabled=b,u.disabled=b,u.style.opacity=b?"0.6":"1",u.style.cursor=b?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=St;exports.renderMarkdown=re;
|
package/dist/widget.d.cts
CHANGED
|
@@ -819,6 +819,14 @@ export declare interface MountChatWidgetOptions {
|
|
|
819
819
|
showAgentName?: boolean;
|
|
820
820
|
/** Render assistant messages inside a filled bubble (themed via `agentBubbleBg`). Defaults to `false`. */
|
|
821
821
|
agentBubble?: boolean;
|
|
822
|
+
/**
|
|
823
|
+
* Bubble shape preset. `"imessage"` bubbles both sides (assistant messages get
|
|
824
|
+
* the filled `agentBubbleBg` bubble too) and draws the iMessage "tail" curl on
|
|
825
|
+
* the last bubble of each same-sender run. Defaults to `"default"` (current
|
|
826
|
+
* look). Colors stay themed: user bubble `brand`, assistant bubble
|
|
827
|
+
* `agentBubbleBg`, and the tail mask follows `messagesBg`.
|
|
828
|
+
*/
|
|
829
|
+
bubbleStyle?: "default" | "imessage";
|
|
822
830
|
/**
|
|
823
831
|
* Show the header bar (title, logo, and the side-panel close "×"). Set `false`
|
|
824
832
|
* to drop it, e.g. when the host page already frames the widget. Defaults to
|
package/dist/widget.d.ts
CHANGED
|
@@ -819,6 +819,14 @@ export declare interface MountChatWidgetOptions {
|
|
|
819
819
|
showAgentName?: boolean;
|
|
820
820
|
/** Render assistant messages inside a filled bubble (themed via `agentBubbleBg`). Defaults to `false`. */
|
|
821
821
|
agentBubble?: boolean;
|
|
822
|
+
/**
|
|
823
|
+
* Bubble shape preset. `"imessage"` bubbles both sides (assistant messages get
|
|
824
|
+
* the filled `agentBubbleBg` bubble too) and draws the iMessage "tail" curl on
|
|
825
|
+
* the last bubble of each same-sender run. Defaults to `"default"` (current
|
|
826
|
+
* look). Colors stay themed: user bubble `brand`, assistant bubble
|
|
827
|
+
* `agentBubbleBg`, and the tail mask follows `messagesBg`.
|
|
828
|
+
*/
|
|
829
|
+
bubbleStyle?: "default" | "imessage";
|
|
822
830
|
/**
|
|
823
831
|
* Show the header bar (title, logo, and the side-panel close "×"). Set `false`
|
|
824
832
|
* to drop it, e.g. when the host page already frames the widget. Defaults to
|