@useago/sdk 1.0.9 → 1.0.11

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 CHANGED
@@ -1,26 +1,26 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v,x,p,h=()=>({});function s(){v&&(v.textContent=JSON.stringify(h(),null,2))}function m(e,t,d){if(!e)return;const n=document.createElement("div");n.className=`dev-log-line dev-log-${d}`,n.textContent=`${new Date().toLocaleTimeString()} ${t}`,e.appendChild(n),e.scrollTop=e.scrollHeight}function c(e,t){m(x,e,t)}function y(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 S="ago_dev_panel_collapsed",E="ago_dev_events_collapsed";function g(e,t,d,n){e.classList.toggle("collapsed",t);const o=e.querySelector(".dev-toggle");o&&(o.textContent=t?"▢":"—",o.title=t?`Expand ${n}`:`Collapse ${n}`,o.setAttribute("aria-expanded",String(!t)));try{localStorage.setItem(d,t?"1":"0")}catch{}}function u(e,t,d){e.querySelector(".dev-toggle")?.addEventListener("click",o=>{o.stopPropagation(),g(e,!e.classList.contains("collapsed"),t,d)}),e.addEventListener("click",()=>{e.classList.contains("collapsed")&&g(e,!1,t,d)});let n=!1;try{n=localStorage.getItem(t)==="1"}catch{}g(e,n,t,d)}function C(e){const{client:t,target:d}=e;h=()=>{const a=t.getContextSnapshot()?.entries??{};return Object.fromEntries(Object.entries(a).map(([l,{name:r,data:b}])=>[l,{name:r,data:b}]))},w();const n=typeof d=="string"?document.querySelector(d):d instanceof Element?d:document.body,o=document.createElement("aside");o.id="ago-dev-panel",o.className="ago-dev-card",(n??document.body).appendChild(o),o.innerHTML=`
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">DEV TOOLS · client-side function state — not for production</span>
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>${(t.getRegisteredFunctions?.()??[]).map(a=>a.name).join(", ")||"—"}</code></div>
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
- `,v=o.querySelector("#ago-dev-state"),x=o.querySelector("#ago-dev-log"),u(o,S,"dev tools");const i=document.createElement("aside");i.id="ago-dev-events",i.className="ago-dev-card",(n??document.body).appendChild(i),i.innerHTML=`
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">SSE EVENT LOG · raw stream messages</span>
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
- `,p=i.querySelector("#ago-dev-event-log"),u(i,E,"SSE event log"),t.on("stream:message",a=>{m(p,y(a),"event")}),t.on("function:invoke",({functionName:a,arguments:l})=>{c(`→ ${a}(${JSON.stringify(l??{})})`,"invoke")}),t.on("function:result",({result:a,error:l})=>{c(l?`✗ error: ${l}`:`← ${JSON.stringify(a)}`,l?"error":"result"),s()}),t.on("context:changed",s),t.on("conversation:loaded",a=>{const l=(a.messages??[]).flatMap(r=>r.toolCalls??[]);c(`⟳ hydrated "${a.title||a.id}" — replayed ${l.length} tool call${l.length===1?"":"s"}`,"hydrate"),s()}),s()}var f="ago-dev-panel-styles";function w(){if(document.getElementById(f))return;const e=document.createElement("style");e.id=f,e.textContent=L,document.head.appendChild(e)}var L=`
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=C;
123
+ `;exports.initDevPanel=_;
@@ -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
  /**
@@ -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
- var v, x, p, h = () => ({});
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 n = document.createElement("div");
8
- n.className = `dev-log-line dev-log-${d}`, n.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${t}`, e.appendChild(n), e.scrollTop = e.scrollHeight;
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 y(e) {
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 S = "ago_dev_panel_collapsed", E = "ago_dev_events_collapsed";
18
- function g(e, t, d, n) {
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 o = e.querySelector(".dev-toggle");
21
- o && (o.textContent = t ? "▢" : "—", o.title = t ? `Expand ${n}` : `Collapse ${n}`, o.setAttribute("aria-expanded", String(!t)));
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 u(e, t, d) {
28
- e.querySelector(".dev-toggle")?.addEventListener("click", (o) => {
29
- o.stopPropagation(), g(e, !e.classList.contains("collapsed"), t, d);
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") && g(e, !1, t, d);
24
+ e.classList.contains("collapsed") && u(e, !1, t, d);
32
25
  });
33
- let n = !1;
26
+ let a = !1;
34
27
  try {
35
- n = localStorage.getItem(t) === "1";
28
+ a = localStorage.getItem(t) === "1";
36
29
  } catch {
37
30
  }
38
- g(e, n, t, d);
31
+ u(e, a, t, d);
39
32
  }
40
- function L(e) {
41
- const { client: t, target: d } = e;
42
- h = () => {
43
- const a = t.getContextSnapshot()?.entries ?? {};
44
- return Object.fromEntries(Object.entries(a).map(([l, { name: r, data: b }]) => [l, {
45
- name: r,
46
- data: b
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
- }, C();
49
- const n = typeof d == "string" ? document.querySelector(d) : d instanceof Element ? d : document.body, o = document.createElement("aside");
50
- o.id = "ago-dev-panel", o.className = "ago-dev-card", (n ?? document.body).appendChild(o), o.innerHTML = `
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">DEV TOOLS · client-side function state — not for production</span>
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>${(t.getRegisteredFunctions?.() ?? []).map((a) => a.name).join(", ") || "—"}</code></div>
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
- `, v = o.querySelector("#ago-dev-state"), x = o.querySelector("#ago-dev-log"), u(o, S, "dev tools");
64
- const s = document.createElement("aside");
65
- s.id = "ago-dev-events", s.className = "ago-dev-card", (n ?? document.body).appendChild(s), s.innerHTML = `
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">SSE EVENT LOG · raw stream messages</span>
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
- `, p = s.querySelector("#ago-dev-event-log"), u(s, E, "SSE event log"), t.on("stream:message", (a) => {
75
- m(p, y(a), "event");
76
- }), t.on("function:invoke", ({ functionName: a, arguments: l }) => {
77
- c(`→ ${a}(${JSON.stringify(l ?? {})})`, "invoke");
78
- }), t.on("function:result", ({ result: a, error: l }) => {
79
- c(l ? `✗ error: ${l}` : `← ${JSON.stringify(a)}`, l ? "error" : "result"), i();
80
- }), t.on("context:changed", i), t.on("conversation:loaded", (a) => {
81
- const l = (a.messages ?? []).flatMap((r) => r.toolCalls ?? []);
82
- c(`⟳ hydrated "${a.title || a.id}" — replayed ${l.length} tool call${l.length === 1 ? "" : "s"}`, "hydrate"), i();
83
- }), i();
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 f = "ago-dev-panel-styles";
86
- function C() {
87
- if (document.getElementById(f)) return;
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 = f, e.textContent = w, document.head.appendChild(e);
92
+ e.id = C, e.textContent = q, document.head.appendChild(e);
90
93
  }
91
- var w = `
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
- L as initDevPanel
196
+ z as initDevPanel
194
197
  };
package/dist/react.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BI3DXaew.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"16px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>e!==void 0||String(t).includes(`
2
- `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:X,p:Y,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[N.default],z=({content:e})=>(0,o.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const s=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),r={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:s}):(0,o.jsx)("div",{style:r,children:s})},fe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BI3DXaew.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let s=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function D(e){const[t,o]=(0,n.useState)(!1),r=(0,n.useRef)(null),l=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const i=new J.AgoClient(e);return r.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(o(!0),()=>{r.current?.destroy(),r.current=null}),[l]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:l,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:o,helpers:r,pageContext:l,...i})=>{const{client:f}=D(t?null:i),c=t||f;return(0,n.useEffect)(()=>{if(!(!o||o.length===0)){for(const p of o)c.register(p);return()=>{for(const p of o)c.unregisterFunction(p.name)}}},[c,o]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(u=>u.functions_exports).then(u=>{for(const[b,m]of Object.entries(r)){const S=u[b];if(!S){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const x=m===!0?S:{...S,handler:m};c.register(x),p.push(x.name)}}),()=>{for(const u of p)c.unregisterFunction(u)}},[c,r]),(0,n.useEffect)(()=>{l==="auto"&&c.enableAutoPageContext()},[c,l]),(0,s.jsx)(T.Provider,{value:c,children:e})};function R(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function A(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const o=A(),r=e||o;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[l,i]=(0,n.useState)([]),[f,c]=(0,n.useState)(t),[p,u]=(0,n.useState)(!1),[b,m]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==f&&(c(t),S(t))},[t]);const S=async x=>{try{i(await r.getMessages(x))}catch(v){m(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const x=g=>{f||c(g.conversationId)},v=g=>{i(d=>{const h=d[d.length-1];return h&&h.id===g.messageId?[...d.slice(0,-1),{...h,content:h.content+g.content}]:d})},C=g=>{i(d=>{let h=-1;for(let k=d.length-1;k>=0;k--)if(d[k].role==="assistant"&&d[k].status==="IN_PROGRESS"){h=k;break}return h<0?d:[...d.slice(0,h),{...d[h],...g},...d.slice(h+1)]})},w=g=>{i(d=>{const h=d.findIndex(k=>k.id===g.id);return h>=0?[...d.slice(0,h),g,...d.slice(h+1)]:[...d,g]}),u(!1)},a=g=>{m(new Error(g.error)),u(!1)};return r.on("message:start",x),r.on("message:chunk",v),r.on("message:answer-complete",C),r.on("message:complete",w),r.on("message:error",a),()=>{r.off("message:start",x),r.off("message:chunk",v),r.off("message:answer-complete",C),r.off("message:complete",w),r.off("message:error",a)}},[r,f]),{messages:l,isLoading:p,error:b,sendMessage:(0,n.useCallback)(async(x,v)=>{u(!0),m(null);const C={id:`temp-${Date.now()}`,conversationId:f||"",content:x,role:"user",status:"DONE",createdAt:new Date},w={id:`temp-assistant-${Date.now()}`,conversationId:f||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(a=>[...a,C,w]);try{const a=await r.sendMessage(x,{conversationId:f,files:v});return a.conversationId&&!f&&c(a.conversationId),i(g=>{const d=g.filter(k=>!k.id.startsWith("temp-")),h={...C,id:C.id.replace("temp-","user-"),conversationId:a.conversationId};return d.some(k=>k.id===a.id)?[...d,h].sort((k,_)=>new Date(k.createdAt).getTime()-new Date(_.createdAt).getTime()):[...d,h,a]}),a}catch(a){return m(a instanceof Error?a:new Error("Failed to send message")),u(!1),i(g=>g.filter(d=>!d.id.startsWith("temp-"))),null}},[r,f]),clearMessages:(0,n.useCallback)(()=>{i([]),c(void 0),m(null)},[]),conversationId:f}}var H=({onSend:e,disabled:t=!1,placeholder:o="Type a message...",allowFiles:r=!1,className:l=""})=>{const[i,f]=(0,n.useState)(""),[c,p]=(0,n.useState)([]),u=(0,n.useRef)(null),b=(0,n.useRef)(null),m=(0,n.useCallback)(()=>{const a=b.current;if(!a)return;const g=110;a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight+2,g)}px`,a.style.overflowY=a.scrollHeight+2>g?"auto":"hidden"},[]),S=(0,n.useCallback)(a=>{a.preventDefault(),(i.trim()||c.length>0)&&(e(i.trim(),c.length>0?c:void 0),f(""),p([]),requestAnimationFrame(m))},[i,c,e,m]),x=(0,n.useCallback)(a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),S(a))},[S]),v=(0,n.useCallback)(a=>{const g=Array.from(a.target.files||[]);p(d=>[...d,...g])},[]),C=(0,n.useCallback)(a=>{p(g=>g.filter((d,h)=>h!==a))},[]),w=i.trim()||c.length>0;return(0,s.jsxs)("form",{onSubmit:S,className:`ago-chat-input ${l}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,s.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((a,g)=>(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,s.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,s.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${a.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,s.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",onClick:()=>u.current?.click(),disabled:t,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,s.jsx)("input",{ref:u,type:"file",multiple:!0,onChange:v,style:{display:"none"}})]}),(0,s.jsx)("textarea",{ref:b,value:i,onChange:a=>{f(a.target.value),m()},onKeyDown:x,placeholder:o,"aria-label":o,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onBlur:a=>{a.currentTarget.style.borderColor="#dee3e8"}}),(0,s.jsx)("button",{type:"submit",disabled:t||!w,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!w?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!w?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},Y=({href:e,children:t,...o})=>(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...o,children:t}),X=({children:e,...t})=>(0,s.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const o=({children:r,...l})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...l},r);return o.displayName=`MarkdownHeading${e}`,o},Q=({children:e,...t})=>(0,s.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,s.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,s.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...o})=>e!==void 0||String(t).includes(`
2
+ `)?(0,s.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}):(0,s.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...o,children:t}),re=({children:e,...t})=>(0,s.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,s.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,s.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,s.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,s.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,s.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,s.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,s.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:Y,p:X,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[N.default],z=({content:e})=>(0,s.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const o=(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,s.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,s.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),r={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,s.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:l=>{l.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:l=>{l.currentTarget.style.borderColor="#dee3e8"},children:o}):(0,s.jsx)("div",{style:r,children:o})},fe=()=>(0,s.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,s.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,s.jsx)("style",{children:`
3
3
  @keyframes ago-pulse {
4
4
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
5
5
  40% { opacity: 1; transform: scale(1); }
6
6
  }
7
- `})]}),O=({message:e,className:t="",showAgentName:s=!1,isLast:r=!1,onFollowUpClick:a})=>{const l=e.role==="user",u=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&s&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((i,p)=>(0,o.jsx)(ue,{source:i,index:p},i.id))}),(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(z,{content:e.content}):u&&(0,o.jsx)(fe,{})}),r&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((i,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(i):void 0,style:{padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:i},p))})]})},ge=({client:e,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:u=500,logoUrl:i,showAgentName:p=!1,forms:d,onFollowUpClick:h,className:C="",onMessageSent:k,onMessageReceived:m})=>{const v=(0,n.useRef)(null),c=R(),y=e??c,{messages:g,isLoading:x,error:f,sendMessage:w}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!y||!d||d.length===0)return;let b=!1;const j=[];return Promise.all(d.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(y,E))).then(E=>{if(!b)for(const U of E)j.push(U.install(y))}).catch(()=>{}),()=>{b=!0,j.forEach(E=>E())}},[y,d?JSON.stringify(d.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[g]),(0,n.useEffect)(()=>{const b=g[g.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&m&&m({id:b.id,content:b.content})},[g,m]);const S=async(b,j)=>{k?.(b),await w(b,j)},_=g[g.length-1],B=x&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=h===!1?void 0:h??(b=>S(b));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[i&&(0,o.jsx)("img",{src:i,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[g.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):g.map((b,j)=>(0,o.jsx)(O,{message:b,showAgentName:p,isLast:j===g.length-1,onFollowUpClick:K},b.id)),f&&(0,o.jsx)("div",{style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:v})]}),(0,o.jsx)(W,{onSend:S,disabled:B,placeholder:a,allowFiles:l})]})};function H({client:e,autoLoad:t=!0}={}){const s=R(),r=e||s;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(null),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null),k=(0,n.useCallback)(async()=>{d(!0),C(null);try{l(await r.getConversations())}catch(c){C(c instanceof Error?c:new Error("Failed to load conversations"))}finally{d(!1)}},[r]),m=(0,n.useCallback)(async c=>{d(!0),C(null);try{i(await r.getConversation(c))}catch(y){C(y instanceof Error?y:new Error("Failed to load conversation"))}finally{d(!1)}},[r]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{t&&k()},[t,k]),{conversations:a,currentConversation:u,isLoading:p,error:h,selectConversation:m,startNewConversation:v,refreshConversations:k}}function pe(e={}){const t=R(),s=e.client||t;if(!s)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:s,conversationId:e.conversationId}),a=H({client:s,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||a.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function xe(e,t){const s=A(),{name:r,description:a,parameters:l,handler:u}=typeof e=="string"?{name:e,...t}:e,i=(0,n.useRef)(u);i.current=u,(0,n.useEffect)(()=>{const p=d=>i.current(d);return s.registerFunction(r,p,{description:a,parameters:l}),()=>{s.unregisterFunction(r)}},[s,r,a,l])}function me(e,t){const s=A(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(s.registerNavigationFunction(a=>r.current(a),t),()=>{s.unregisterFunction("navigateToPage")}),[s,t])}function he(e,t){const s=A(),r=(0,n.useId)(),a=t??r,l=(0,n.useRef)(e);l.current=e;const u=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return s.addDynamicContext(a,i),()=>{s.removeDynamicContext(a)}}return s.setContext(a,l.current),()=>{s.removeContext(a)}},[s,a,u,u?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function ye(e){const t=A(),s=e.schema!=null,r=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",u=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>s?M.createFormCollector(e):null,[s,e.name,r,l,u,e.autoSubmit]),[p,d]=(0,n.useState)({collector:null,loading:!s,error:null});(0,n.useEffect)(()=>{if(s)return;let x=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{x||d({collector:f,loading:!1,error:null})}).catch(f=>{x||d({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{x=!0}},[t,s,e.name,l,u,e.autoSubmit]);const h=s?i:p.collector,C=s?!1:p.loading,k=s?null:p.error;(0,n.useEffect)(()=>{if(h)return h.install(t)},[t,h]);const m=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[u]),v=$(h?.store??m),c=(0,n.useMemo)(()=>h?.getStatus()??D,[v,h]),y=(0,n.useMemo)(()=>({...v,...c}),[v,c]),g=(0,n.useMemo)(()=>({name:e.name,store:m,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>m.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,m]);return{...h??g,state:y,loading:C,error:k}}exports.AgoProvider=G;exports.ChatInput=W;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=O;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=q;exports.useAgoClient=A;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=H;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=R;
7
+ `})]}),W=({message:e,className:t="",showAgentName:o=!1,isLast:r=!1,onFollowUpClick:l})=>{const i=e.role==="user",f=e.status==="IN_PROGRESS";return(0,s.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&o&&e.agent&&(0,s.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!i&&e.sources&&e.sources.length>0&&(0,s.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,s.jsx)(ue,{source:c,index:p},c.id))}),(0,s.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,s.jsx)(z,{content:e.content}):f&&(0,s.jsx)(fe,{})}),r&&e.followUpReplies&&e.followUpReplies.length>0&&(0,s.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,s.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!l,onClick:l?()=>l(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:l?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},ge=({client:e,conversationId:t,title:o="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:l="Type a message...",allowFiles:i=!1,height:f=500,logoUrl:c,showAgentName:p=!1,forms:u,onFollowUpClick:b,className:m="",onMessageSent:S,onMessageReceived:x})=>{const v=(0,n.useRef)(null),C=A(),w=e??C,{messages:a,isLoading:g,error:d,sendMessage:h}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!w||!u||u.length===0)return;let y=!1;const j=[];return Promise.all(u.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(w,E))).then(E=>{if(!y)for(const U of E)j.push(U.install(w))}).catch(()=>{}),()=>{y=!0,j.forEach(E=>E())}},[w,u?JSON.stringify(u.map(y=>[y.name,y.schema??null,y.submit??!1,y.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[a]),(0,n.useEffect)(()=>{const y=a[a.length-1];y&&y.role==="assistant"&&y.status==="DONE"&&x&&x({id:y.id,content:y.content})},[a,x]);const k=async(y,j)=>{S?.(y),await h(y,j)},_=a[a.length-1],B=g&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=b===!1?void 0:b??(y=>k(y));return(0,s.jsxs)("div",{className:`ago-chat-widget ${m}`,style:{display:"flex",flexDirection:"column",height:typeof f=="number"?`${f}px`:f,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,s.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,s.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,s.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),(0,s.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[a.length===0?(0,s.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):a.map((y,j)=>(0,s.jsx)(W,{message:y,showAgentName:p,isLast:j===a.length-1,onFollowUpClick:K},y.id)),d&&(0,s.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:d.message}),(0,s.jsx)("div",{ref:v})]}),(0,s.jsx)(H,{onSend:k,disabled:B,placeholder:l,allowFiles:i})]})};function O({client:e,autoLoad:t=!0}={}){const o=A(),r=e||o;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[l,i]=(0,n.useState)([]),[f,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(!1),[b,m]=(0,n.useState)(null),S=(0,n.useCallback)(async()=>{u(!0),m(null);try{i(await r.getConversations())}catch(C){m(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[r]),x=(0,n.useCallback)(async C=>{u(!0),m(null);try{c(await r.getConversation(C))}catch(w){m(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[r]),v=(0,n.useCallback)(()=>{c(null)},[]);return(0,n.useEffect)(()=>{t&&S()},[t,S]),{conversations:l,currentConversation:f,isLoading:p,error:b,selectConversation:x,startNewConversation:v,refreshConversations:S}}function pe(e={}){const t=A(),o=e.client||t;if(!o)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:o,conversationId:e.conversationId}),l=O({client:o,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||l.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:l.conversations,currentConversation:l.currentConversation,isConversationsLoading:l.isLoading,selectConversation:l.selectConversation,startNewConversation:l.startNewConversation,refreshConversations:l.refreshConversations}}function xe(e,t){const o=R(),{name:r,description:l,parameters:i,handler:f}=typeof e=="string"?{name:e,...t}:e,c=(0,n.useRef)(f);c.current=f,(0,n.useEffect)(()=>{const p=u=>c.current(u);return o.registerFunction(r,p,{description:l,parameters:i}),()=>{o.unregisterFunction(r)}},[o,r,l,i])}function me(e,t){const o=R(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(o.registerNavigationFunction(l=>r.current(l),t),()=>{o.unregisterFunction("navigateToPage")}),[o,t])}function he(e,t){const o=R(),r=(0,n.useId)(),l=t??r,i=(0,n.useRef)(e);i.current=e;const f=typeof e=="function";(0,n.useEffect)(()=>{if(typeof i.current=="function"){const c=()=>i.current();return o.addDynamicContext(l,c),()=>{o.removeDynamicContext(l)}}return o.setContext(l,i.current),()=>{o.removeContext(l)}},[o,l,f,f?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var q={missing:[],complete:!1};function ye(e){const t=R(),o=e.schema!=null,r=JSON.stringify(e.schema??null),l=e.submit,i=l?typeof l=="string"?`client:${l}`:l.via==="backend"?"backend":"handler"in l?"client:handler":`client:${l.url}`:"none",f=JSON.stringify(e.initialValues??null),c=(0,n.useMemo)(()=>o?M.createFormCollector(e):null,[o,e.name,r,i,f,e.autoSubmit]),[p,u]=(0,n.useState)({collector:null,loading:!o,error:null});(0,n.useEffect)(()=>{if(o)return;let g=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(d=>{g||u({collector:d,loading:!1,error:null})}).catch(d=>{g||u({collector:null,loading:!1,error:d instanceof Error?d:new Error(String(d))})}),()=>{g=!0}},[t,o,e.name,i,f,e.autoSubmit]);const b=o?c:p.collector,m=o?!1:p.loading,S=o?null:p.error;(0,n.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const x=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[f]),v=$(b?.store??x),C=(0,n.useMemo)(()=>b?.getStatus()??q,[v,b]),w=(0,n.useMemo)(()=>({...v,...C}),[v,C]),a=(0,n.useMemo)(()=>({name:e.name,store:x,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>q}),[e.name,x]);return{...b??a,state:w,loading:m,error:S}}exports.AgoProvider=G;exports.ChatInput=H;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=W;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=D;exports.useAgoClient=R;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=O;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=A;