@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 +7 -7
- package/dist/devtools.d.cts +11 -0
- package/dist/devtools.d.ts +11 -0
- package/dist/devtools.js +57 -54
- package/dist/react.cjs +3 -3
- package/dist/react.js +363 -341
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +33 -2
- package/dist/widget.d.ts +33 -2
- package/dist/widget.js +473 -403
- 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/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
|
|
2
|
-
`)?(0,
|
|
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
|
-
`})]}),
|
|
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;
|