@useago/sdk 1.13.0 → 1.13.1

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/angular.cjs +1 -1
  3. package/dist/angular.d.cts +43 -10
  4. package/dist/angular.d.ts +43 -10
  5. package/dist/angular.js +4 -4
  6. package/dist/autoContinue-C3UsCvT5.cjs +1 -0
  7. package/dist/{autoContinue-CC8K9mBU.js → autoContinue-Cb4_iEbO.js} +1 -1
  8. package/dist/{createConversationSession-BfJg0WyA.js → createConversationSession-D0vks-8C.js} +1 -1
  9. package/dist/{createConversationSession-CiOXKWl0.cjs → createConversationSession-Ri3EKIJU.cjs} +1 -1
  10. package/dist/{createFormCollector-DN1xjAv5.js → createFormCollector-BMN-blXs.js} +1 -1
  11. package/dist/{createFormCollector-DnQl77Ko.cjs → createFormCollector-BNCMIUw2.cjs} +1 -1
  12. package/dist/devtools.d.cts +34 -5
  13. package/dist/devtools.d.ts +34 -5
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.d.cts +34 -5
  16. package/dist/index.d.ts +34 -5
  17. package/dist/index.js +4 -4
  18. package/dist/react.cjs +3 -3
  19. package/dist/react.d.cts +40 -6
  20. package/dist/react.d.ts +40 -6
  21. package/dist/react.js +290 -284
  22. package/dist/testing.d.cts +34 -5
  23. package/dist/testing.d.ts +34 -5
  24. package/dist/types-Ck3iZG0K.cjs +10 -0
  25. package/dist/{types-Q7t1peH-.js → types-fX-VoHfa.js} +860 -753
  26. package/dist/vue.cjs +1 -1
  27. package/dist/vue.d.cts +38 -7
  28. package/dist/vue.d.ts +38 -7
  29. package/dist/vue.js +57 -57
  30. package/dist/widget.cjs +6 -6
  31. package/dist/widget.d.cts +34 -5
  32. package/dist/widget.d.ts +34 -5
  33. package/dist/widget.js +136 -136
  34. package/llms-full.txt +37 -0
  35. package/package.json +1 -1
  36. package/dist/autoContinue-CP9pJR-V.cjs +0 -1
  37. package/dist/types-a7teDBnC.cjs +0 -10
package/dist/index.d.cts CHANGED
@@ -97,6 +97,8 @@ export declare class AgoClient {
97
97
  private config;
98
98
  /** Conversations already warned about an empty reply (one warning each). */
99
99
  private warnedEmptyConversations;
100
+ /** Client functions the backend has accepted from a WebMCP call report. */
101
+ private declaredExternally;
100
102
  /** Whether the placeholder-mode page-data warning has already been logged. */
101
103
  private warnedPageDataPlaceholder;
102
104
  /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
@@ -133,6 +135,8 @@ export declare class AgoClient {
133
135
  proactive: ProactiveController | null;
134
136
  /** Removes the mirrored WebMCP tools; `null` when the bridge is off. */
135
137
  private detachWebMCP;
138
+ /** The `listPages` companion is live. */
139
+ private listPagesRegistered;
136
140
  constructor(config: AgoConfig);
137
141
  private attachWebMCPBridge;
138
142
  /**
@@ -247,6 +251,11 @@ export declare class AgoClient {
247
251
  */
248
252
  rejectFunction(invocationId: string): Promise<void>;
249
253
  /* Excluded from this release type: runExternalFunction */
254
+ /**
255
+ * Best-effort analytics for one WebMCP call. No agent: the caller is someone
256
+ * else's agent and cannot be known from `execute`.
257
+ */
258
+ private reportExternalCall;
250
259
  /**
251
260
  * Get a page of conversations, newest-first. `pageSize` is capped at 100 by
252
261
  * the backend (default 50). Returns the `{ data, has_more, total }` envelope
@@ -441,14 +450,15 @@ export declare class AgoClient {
441
450
  * page of an entity. Flat arguments only: nested object parameters are not
442
451
  * reliably rendered to the model, so placeholders must not be named `page`.
443
452
  *
453
+ * For a large table, `{ catalogue: "onDemand" }` moves the route descriptions
454
+ * into a read-only `listPages` companion, leaving only the page names in the
455
+ * per-message schema. Routes may carry a `section` to group that companion.
456
+ *
444
457
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
445
458
  * @param routes - Map of route names to paths, with descriptions for the LLM
459
+ * @param opts - Where the catalogue lives; `"inline"` by default
446
460
  */
447
- registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
448
- name: string;
449
- path: string;
450
- description: string;
451
- }>): void;
461
+ registerNavigationFunction(navigate: (path: string) => void, routes: NavRoute[], opts?: AgoNavigationOptions): void;
452
462
  /**
453
463
  * Unregister the navigation function and its `current-page` context provider.
454
464
  */
@@ -967,6 +977,16 @@ export declare interface AgoMessage {
967
977
  createdAt: Date;
968
978
  }
969
979
 
980
+ /**
981
+ * Where the route catalogue lives: `"inline"` (default) in `navigateToPage`'s
982
+ * description, or `"onDemand"` in a `listPages` companion's result.
983
+ */
984
+ export declare type AgoNavigationOptions = {
985
+ catalogue?: "inline";
986
+ } | {
987
+ catalogue: "onDemand";
988
+ };
989
+
970
990
  /**
971
991
  * Network/connection error
972
992
  */
@@ -2329,6 +2349,15 @@ export declare interface MockAgoClientOptions {
2329
2349
 
2330
2350
  declare type MockFn = (...args: any[]) => any;
2331
2351
 
2352
+ /** A navigable page. `path` may carry `:param` placeholders. */
2353
+ export declare interface NavRoute {
2354
+ name: string;
2355
+ path: string;
2356
+ description: string;
2357
+ /** Only read under `catalogue: "onDemand"`. */
2358
+ section?: string;
2359
+ }
2360
+
2332
2361
  /**
2333
2362
  * Optional action attached to a nudge. Accepting a `functionName` action
2334
2363
  * executes the registered client function (same `FunctionRegistry` path as
package/dist/index.d.ts CHANGED
@@ -97,6 +97,8 @@ export declare class AgoClient {
97
97
  private config;
98
98
  /** Conversations already warned about an empty reply (one warning each). */
99
99
  private warnedEmptyConversations;
100
+ /** Client functions the backend has accepted from a WebMCP call report. */
101
+ private declaredExternally;
100
102
  /** Whether the placeholder-mode page-data warning has already been logged. */
101
103
  private warnedPageDataPlaceholder;
102
104
  /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
@@ -133,6 +135,8 @@ export declare class AgoClient {
133
135
  proactive: ProactiveController | null;
134
136
  /** Removes the mirrored WebMCP tools; `null` when the bridge is off. */
135
137
  private detachWebMCP;
138
+ /** The `listPages` companion is live. */
139
+ private listPagesRegistered;
136
140
  constructor(config: AgoConfig);
137
141
  private attachWebMCPBridge;
138
142
  /**
@@ -247,6 +251,11 @@ export declare class AgoClient {
247
251
  */
248
252
  rejectFunction(invocationId: string): Promise<void>;
249
253
  /* Excluded from this release type: runExternalFunction */
254
+ /**
255
+ * Best-effort analytics for one WebMCP call. No agent: the caller is someone
256
+ * else's agent and cannot be known from `execute`.
257
+ */
258
+ private reportExternalCall;
250
259
  /**
251
260
  * Get a page of conversations, newest-first. `pageSize` is capped at 100 by
252
261
  * the backend (default 50). Returns the `{ data, has_more, total }` envelope
@@ -441,14 +450,15 @@ export declare class AgoClient {
441
450
  * page of an entity. Flat arguments only: nested object parameters are not
442
451
  * reliably rendered to the model, so placeholders must not be named `page`.
443
452
  *
453
+ * For a large table, `{ catalogue: "onDemand" }` moves the route descriptions
454
+ * into a read-only `listPages` companion, leaving only the page names in the
455
+ * per-message schema. Routes may carry a `section` to group that companion.
456
+ *
444
457
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
445
458
  * @param routes - Map of route names to paths, with descriptions for the LLM
459
+ * @param opts - Where the catalogue lives; `"inline"` by default
446
460
  */
447
- registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
448
- name: string;
449
- path: string;
450
- description: string;
451
- }>): void;
461
+ registerNavigationFunction(navigate: (path: string) => void, routes: NavRoute[], opts?: AgoNavigationOptions): void;
452
462
  /**
453
463
  * Unregister the navigation function and its `current-page` context provider.
454
464
  */
@@ -967,6 +977,16 @@ export declare interface AgoMessage {
967
977
  createdAt: Date;
968
978
  }
969
979
 
980
+ /**
981
+ * Where the route catalogue lives: `"inline"` (default) in `navigateToPage`'s
982
+ * description, or `"onDemand"` in a `listPages` companion's result.
983
+ */
984
+ export declare type AgoNavigationOptions = {
985
+ catalogue?: "inline";
986
+ } | {
987
+ catalogue: "onDemand";
988
+ };
989
+
970
990
  /**
971
991
  * Network/connection error
972
992
  */
@@ -2329,6 +2349,15 @@ export declare interface MockAgoClientOptions {
2329
2349
 
2330
2350
  declare type MockFn = (...args: any[]) => any;
2331
2351
 
2352
+ /** A navigable page. `path` may carry `:param` placeholders. */
2353
+ export declare interface NavRoute {
2354
+ name: string;
2355
+ path: string;
2356
+ description: string;
2357
+ /** Only read under `catalogue: "onDemand"`. */
2358
+ section?: string;
2359
+ }
2360
+
2332
2361
  /**
2333
2362
  * Optional action attached to a nudge. Accepting a `functionName` action
2334
2363
  * executes the registered client function (same `FunctionRegistry` path as
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { a as w, c as E, d as C, f as S, i as y, l as b, m as F, o as v, p as _, r as M, s as T, t as R, u as I } from "./functions-tzyOZNp6.js";
2
- import { C as D, S as L, _ as O, b as k, c as N, d as G, f as x, g as q, h as P, i as X, l as B, m as H, n as c, o as J, p as W, r as j, s as z, t as K, u as V, v as Y, w as $, x as Q, y as Z } from "./types-Q7t1peH-.js";
2
+ import { C as D, S as L, _ as O, b as k, c as N, d as G, f as x, g as q, h as P, i as X, l as B, m as H, n as c, o as J, p as W, r as j, s as z, t as K, u as V, v as Y, w as $, x as Q, y as Z } from "./types-fX-VoHfa.js";
3
3
  import { a as te, i as oe, n as p, r as ae, t as re } from "./errors-BLfjXnLB.js";
4
- import { t as se } from "./autoContinue-CC8K9mBU.js";
5
- import { t as ge } from "./createConversationSession-BfJg0WyA.js";
6
- import { n as me, r as fe, t as le } from "./createFormCollector-DN1xjAv5.js";
4
+ import { t as se } from "./autoContinue-Cb4_iEbO.js";
5
+ import { t as ge } from "./createConversationSession-D0vks-8C.js";
6
+ import { n as me, r as fe, t as le } from "./createFormCollector-BMN-blXs.js";
7
7
  import { t as ce } from "./createMockClient-YoYr3pQr.js";
8
8
  import "./testing.js";
9
9
  function Ae(e) {
package/dist/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $e=Object.create,Y=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyNames,Ge=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty,Ve=(e,r)=>{let t={};for(var s in e)Y(t,s,{get:e[s],enumerable:!0});return r||Y(t,Symbol.toStringTag,{value:"Module"}),t},Xe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(var o=Ue(r),l=0,c=o.length,i;l<c;l++)i=o[l],!Je.call(e,i)&&i!==t&&Y(e,i,{get:(x=>r[x]).bind(null,i),enumerable:!(s=Ke(r,i))||s.enumerable});return e},oe=(e,r,t)=>(t=e!=null?$e(Ge(e)):{},Xe(r||!e||!e.__esModule?Y(t,"default",{value:e,enumerable:!0}):t,e));const L=require("./types-a7teDBnC.cjs"),Z=require("./errors-o1IB5fEu.cjs"),Ye=require("./autoContinue-CP9pJR-V.cjs"),z=require("./createFormCollector-DnQl77Ko.cjs"),Ze=require("./createMockClient-BPt1gSve.cjs"),G=require("./speechToText-ZciRyyJE.cjs");let n=require("react");n=oe(n,1);let a=require("react/jsx-runtime"),te=require("react-markdown");te=oe(te,1);let ne=require("remark-gfm");ne=oe(ne,1);function ye(e){const[r,t]=(0,n.useState)(!1),s=(0,n.useRef)(null),o=(0,n.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const l=new L.AgoClient(e);return s.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(o&&s.current===null&&(s.current=o,o.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[o]),(0,n.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,language:e.language??null,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.language,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:o,isReady:r}}var se=(0,n.createContext)(null),Qe=({children:e,client:r,tools:t,helpers:s,pageContext:o,...l})=>{const{client:c}=ye(r?null:l),i=r||c;return(0,n.useEffect)(()=>{if(!(!t||t.length===0)){for(const x of t)i.register(x);return()=>{for(const x of t)i.unregisterFunction(x.name)}}},[i,t]),(0,n.useEffect)(()=>{if(!s)return;const x=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[g,b]of Object.entries(s)){const m=d[g];if(!m){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const f=b===!0?m:{...m,handler:b};i.register(f),x.push(f.name)}}),()=>{for(const d of x)i.unregisterFunction(d)}},[i,s]),(0,n.useEffect)(()=>{o==="auto"&&i.enableAutoPageContext()},[i,o]),(0,a.jsx)(se.Provider,{value:i,children:e})};function B(){const e=(0,n.useContext)(se);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function D(){return(0,n.useContext)(se)}var et=new Set(["awaiting-approval"]);function ve(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function tt(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":ve(e.type)}function ge(e,r){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(r==="confirmation"||r==="form")?"awaiting-approval":"running"}function xe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,r=>r.toUpperCase()).trim()}function nt(e){switch(e.kind){case"navigation":return`Navigating to ${xe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||xe(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function Ce(e={}){const{includeReasoning:r=!1,labelFor:t}=e,s=D(),o=e.client||s;if(!o)throw new Z.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[l,c]=(0,n.useState)([]),i=(0,n.useRef)(new Set),x=(0,n.useRef)(void 0),d=(0,n.useRef)(t);d.current=t;const g=(0,n.useCallback)((p,S)=>{c(y=>{const N=y.findIndex(v=>v.id===p),_={...N>=0?y[N]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...S};return _.label=d.current?.(_)??nt(_),N>=0?[...y.slice(0,N),_,...y.slice(N+1)]:[...y,_]})},[]);(0,n.useEffect)(()=>{const p=h=>{x.current=h.messageId},S=h=>{const I=ve(h.type);I==="reasoning"&&!r||g(h.id,{kind:I,status:ge(h.status,I),messageId:x.current,toolName:h.toolName,toolDisplayName:h.toolDisplayName,message:h.message,data:h.data,formSchema:h.formSchema,requiresApproval:I==="confirmation"||I==="form"})},y=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:x.current,functionName:h.functionName,arguments:h.arguments})},N=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:x.current,functionName:h.functionName,arguments:h.arguments,requiresApproval:!0})},_=h=>{if(!h.invocationId)return;const I=h.result,u=typeof h.result=="object"&&I!==null&&I.approved===!1&&I.reason==="user_rejected";g(h.invocationId,{status:h.error?"error":u?"rejected":"done",requiresApproval:!1})},v=h=>{for(const I of h.messages??[])if(I.role==="assistant")for(const u of I.toolCalls??[]){const A=tt(u);A==="reasoning"&&!r||/waiting/i.test(u.status??"")||g(u.id,{kind:A,status:ge(u.status,A),messageId:I.id,toolName:u.toolName,toolDisplayName:u.toolDisplayName,functionName:u.functionName,arguments:u.arguments,message:u.message,data:u.data,formSchema:u.formSchema,requiresApproval:A==="confirmation"||A==="form"})}},k=h=>{c(I=>I.map(u=>u.status==="running"||u.status==="awaiting-approval"?{...u,status:h}:u))},j=()=>k("done"),E=()=>k("error");return o.on("message:start",p),o.on("toolCall:received",S),o.on("function:invoke",y),o.on("function:awaiting-approval",N),o.on("function:result",_),o.on("conversation:loaded",v),o.on("message:complete",j),o.on("message:error",E),()=>{o.off("message:start",p),o.off("toolCall:received",S),o.off("function:invoke",y),o.off("function:awaiting-approval",N),o.off("function:result",_),o.off("conversation:loaded",v),o.off("message:complete",j),o.off("message:error",E)}},[o,r,g]);const b=(0,n.useCallback)(async p=>{const S=l.find(y=>y.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||S.kind!=="form"&&(i.current.add(p),g(p,{status:"running",requiresApproval:!1}),S.functionName?await o.approveFunction(p):await o.confirmToolCall(p))},[o,l,g]),m=(0,n.useCallback)(async p=>{const S=l.find(y=>y.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||(i.current.add(p),g(p,{status:"rejected",requiresApproval:!1}),S.functionName?await o.rejectFunction(p):await o.rejectToolCall(p))},[o,l,g]),f=(0,n.useCallback)(async(p,S)=>{g(p,{status:"running",requiresApproval:!1}),await o.submitToolCallForm(p,S),g(p,{status:"done"})},[o,g]),C=(0,n.useCallback)(()=>{i.current.clear(),c([])},[]);return{items:l,latest:l.length>0?l[l.length-1]:void 0,isAwaitingApproval:l.some(p=>et.has(p.status)),approve:b,reject:m,submitForm:f,clear:C}}function ae({client:e,conversationId:r}={}){const t=D(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(r),[x,d]=(0,n.useState)(!1),[g,b]=(0,n.useState)(null);(0,n.useEffect)(()=>{r&&r!==c&&(i(r),m(r))},[r]);const m=async f=>{try{l((await s.getMessages(f)).filter(C=>!C.hidden))}catch(C){b(C instanceof Error?C:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const f=v=>v==="IN_PROGRESS"||v==="WAITING_CLIENT",C=v=>{c||i(v.conversationId),d(!0),l(k=>{const j=k.findIndex(E=>E.id===v.messageId);return j>=0?k.map((E,h)=>h===j?{...E,status:"IN_PROGRESS"}:E):k.some(E=>E.role==="assistant"&&f(E.status))?k:[...k,{id:v.messageId,conversationId:v.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},p=v=>{l(k=>{const j=k.findIndex(E=>E.id===v.messageId);return j<0?k:k.map((E,h)=>h===j?{...E,content:E.content+v.content}:E)})},S=v=>{l(k=>{let j=-1;for(let E=k.length-1;E>=0;E--)if(k[E].role==="assistant"&&f(k[E].status)){j=E;break}return j<0?k:[...k.slice(0,j),{...k[j],...v},...k.slice(j+1)]})},y=v=>{l(k=>{const j=k.findIndex(E=>E.id===v.id);return j>=0?[...k.slice(0,j),v,...k.slice(j+1)]:[...k,v]}),d(!1)},N=v=>{b(new Error(v.error)),d(!1)},_=()=>{l(v=>{let k=-1;for(let j=v.length-1;j>=0;j--)if(v[j].role==="assistant"&&f(v[j].status)){k=j;break}return k<0?v:v[k].content?v.map((j,E)=>E===k?{...j,status:"CANCELED"}:j):v.filter((j,E)=>E!==k)}),d(!1)};return s.on("message:start",C),s.on("message:chunk",p),s.on("message:answer-complete",S),s.on("message:complete",y),s.on("message:error",N),s.on("message:stopped",_),()=>{s.off("message:start",C),s.off("message:chunk",p),s.off("message:answer-complete",S),s.off("message:complete",y),s.off("message:error",N),s.off("message:stopped",_)}},[s,c]),{messages:o,isLoading:x,error:g,sendMessage:(0,n.useCallback)(async(f,C)=>{d(!0),b(null);const p={id:`temp-${Date.now()}`,conversationId:c||"",content:f,role:"user",status:"DONE",attachments:C&&C.length>0?L.attachmentsFromFiles(C):void 0,createdAt:new Date},S={id:`temp-assistant-${Date.now()}`,conversationId:c||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(y=>[...y,p,S]);try{const y=await s.sendMessage(f,{conversationId:c,files:C});return y.conversationId&&!c&&i(y.conversationId),l(N=>{const _=N.filter(k=>!k.id.startsWith("temp-")),v={...p,id:p.id.replace("temp-","user-"),conversationId:y.conversationId};return _.some(k=>k.id===y.id)?[..._,v].sort((k,j)=>new Date(k.createdAt).getTime()-new Date(j.createdAt).getTime()):[..._,v,y]}),y}catch(y){return b(y instanceof Error?y:new Error("Failed to send message")),d(!1),l(N=>N.filter(_=>!_.id.startsWith("temp-"))),null}},[s,c]),stop:(0,n.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),b(null)},[]),conversationId:c}}var me={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},rt={tabindex:"tabIndex"};function ot(e){const r={};for(const[t,s]of Object.entries(e))r[rt[t]??t]=s;return r}function we(e){const r=e!==!1,t=r?e??{}:void 0,s=(0,n.useRef)(t?.onStateChange);s.current=t?.onStateChange;const o=(0,n.useMemo)(()=>{if(r)return G.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(c,i)=>s.current?.(c,i)})},[r,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),l=(0,n.useSyncExternalStore)((0,n.useCallback)(c=>o?.subscribe(c)??(()=>{}),[o]),(0,n.useCallback)(()=>o?.getSnapshot()??me,[o]),(0,n.useCallback)(()=>o?.getServerSnapshot()??me,[o]));return{sheet:(0,n.useMemo)(()=>({...l,surface:{...l.surface,attrs:ot(l.surface.attrs)}}),[l]),expand:(0,n.useCallback)(c=>o?.expand(c),[o]),collapse:(0,n.useCallback)(c=>o?.collapse(c),[o]),toggle:(0,n.useCallback)(c=>o?.toggle(c),[o])}}var st=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Se(e){const r=e.split(st);return r.length===1?e:r.map((t,s)=>s%2===0||!t?t:t.startsWith("`")?(0,a.jsx)("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",padding:"0 3px",borderRadius:"3px",backgroundColor:"rgba(0, 0, 0, 0.06)"},children:t.slice(1,-1)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var at=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $e=Object.create,Y=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyNames,Ge=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty,Ve=(e,r)=>{let t={};for(var s in e)Y(t,s,{get:e[s],enumerable:!0});return r||Y(t,Symbol.toStringTag,{value:"Module"}),t},Xe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(var o=Ue(r),l=0,c=o.length,i;l<c;l++)i=o[l],!Je.call(e,i)&&i!==t&&Y(e,i,{get:(x=>r[x]).bind(null,i),enumerable:!(s=Ke(r,i))||s.enumerable});return e},oe=(e,r,t)=>(t=e!=null?$e(Ge(e)):{},Xe(r||!e||!e.__esModule?Y(t,"default",{value:e,enumerable:!0}):t,e));const L=require("./types-Ck3iZG0K.cjs"),Z=require("./errors-o1IB5fEu.cjs"),Ye=require("./autoContinue-C3UsCvT5.cjs"),z=require("./createFormCollector-BNCMIUw2.cjs"),Ze=require("./createMockClient-BPt1gSve.cjs"),G=require("./speechToText-ZciRyyJE.cjs");let n=require("react");n=oe(n,1);let a=require("react/jsx-runtime"),te=require("react-markdown");te=oe(te,1);let ne=require("remark-gfm");ne=oe(ne,1);function ye(e){const[r,t]=(0,n.useState)(!1),s=(0,n.useRef)(null),o=(0,n.useMemo)(()=>{if(s.current&&(s.current.destroy(),s.current=null),!e)return null;const l=new L.AgoClient(e);return s.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(o&&s.current===null&&(s.current=o,o.reviveAfterDestroy()),t(!0),()=>{s.current?.destroy(),s.current=null}),[o]),(0,n.useEffect)(()=>{s.current&&e&&s.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,language:e.language??null,userEmail:e.userEmail,userJwt:e.userJwt,metadata:e.metadata??null,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.language,e?.userEmail,e?.userJwt,e?.metadata,e?.debug,e?.warnOnEmptyReply]),{client:o,isReady:r}}var se=(0,n.createContext)(null),Qe=({children:e,client:r,tools:t,helpers:s,pageContext:o,...l})=>{const{client:c}=ye(r?null:l),i=r||c;return(0,n.useEffect)(()=>{if(!(!t||t.length===0)){for(const x of t)i.register(x);return()=>{for(const x of t)i.unregisterFunction(x.name)}}},[i,t]),(0,n.useEffect)(()=>{if(!s)return;const x=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[g,w]of Object.entries(s)){const m=d[g];if(!m){console.warn(`[AGO] Unknown helper: "${g}"`);continue}const f=w===!0?m:{...m,handler:w};i.register(f),x.push(f.name)}}),()=>{for(const d of x)i.unregisterFunction(d)}},[i,s]),(0,n.useEffect)(()=>{o==="auto"&&i.enableAutoPageContext()},[i,o]),(0,a.jsx)(se.Provider,{value:i,children:e})};function B(){const e=(0,n.useContext)(se);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function D(){return(0,n.useContext)(se)}var et=new Set(["awaiting-approval"]);function ve(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function tt(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":ve(e.type)}function ge(e,r){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(r==="confirmation"||r==="form")?"awaiting-approval":"running"}function xe(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,r=>r.toUpperCase()).trim()}function nt(e){switch(e.kind){case"navigation":return`Navigating to ${xe(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||xe(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function Ce(e={}){const{includeReasoning:r=!1,labelFor:t}=e,s=D(),o=e.client||s;if(!o)throw new Z.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[l,c]=(0,n.useState)([]),i=(0,n.useRef)(new Set),x=(0,n.useRef)(void 0),d=(0,n.useRef)(t);d.current=t;const g=(0,n.useCallback)((p,S)=>{c(b=>{const N=b.findIndex(y=>y.id===p),_={...N>=0?b[N]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...S};return _.label=d.current?.(_)??nt(_),N>=0?[...b.slice(0,N),_,...b.slice(N+1)]:[...b,_]})},[]);(0,n.useEffect)(()=>{const p=h=>{x.current=h.messageId},S=h=>{const I=ve(h.type);I==="reasoning"&&!r||g(h.id,{kind:I,status:ge(h.status,I),messageId:x.current,toolName:h.toolName,toolDisplayName:h.toolDisplayName,message:h.message,data:h.data,formSchema:h.formSchema,requiresApproval:I==="confirmation"||I==="form"})},b=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:x.current,functionName:h.functionName,arguments:h.arguments})},N=h=>{h.invocationId&&g(h.invocationId,{kind:h.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:x.current,functionName:h.functionName,arguments:h.arguments,requiresApproval:!0})},_=h=>{if(!h.invocationId)return;const I=h.result,u=typeof h.result=="object"&&I!==null&&I.approved===!1&&I.reason==="user_rejected";g(h.invocationId,{status:h.error?"error":u?"rejected":"done",requiresApproval:!1})},y=h=>{for(const I of h.messages??[])if(I.role==="assistant")for(const u of I.toolCalls??[]){const A=tt(u);A==="reasoning"&&!r||/waiting/i.test(u.status??"")||g(u.id,{kind:A,status:ge(u.status,A),messageId:I.id,toolName:u.toolName,toolDisplayName:u.toolDisplayName,functionName:u.functionName,arguments:u.arguments,message:u.message,data:u.data,formSchema:u.formSchema,requiresApproval:A==="confirmation"||A==="form"})}},k=h=>{c(I=>I.map(u=>u.status==="running"||u.status==="awaiting-approval"?{...u,status:h}:u))},j=()=>k("done"),E=()=>k("error");return o.on("message:start",p),o.on("toolCall:received",S),o.on("function:invoke",b),o.on("function:awaiting-approval",N),o.on("function:result",_),o.on("conversation:loaded",y),o.on("message:complete",j),o.on("message:error",E),()=>{o.off("message:start",p),o.off("toolCall:received",S),o.off("function:invoke",b),o.off("function:awaiting-approval",N),o.off("function:result",_),o.off("conversation:loaded",y),o.off("message:complete",j),o.off("message:error",E)}},[o,r,g]);const w=(0,n.useCallback)(async p=>{const S=l.find(b=>b.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||S.kind!=="form"&&(i.current.add(p),g(p,{status:"running",requiresApproval:!1}),S.functionName?await o.approveFunction(p):await o.confirmToolCall(p))},[o,l,g]),m=(0,n.useCallback)(async p=>{const S=l.find(b=>b.id===p);!S||S.status!=="awaiting-approval"||i.current.has(p)||(i.current.add(p),g(p,{status:"rejected",requiresApproval:!1}),S.functionName?await o.rejectFunction(p):await o.rejectToolCall(p))},[o,l,g]),f=(0,n.useCallback)(async(p,S)=>{g(p,{status:"running",requiresApproval:!1}),await o.submitToolCallForm(p,S),g(p,{status:"done"})},[o,g]),v=(0,n.useCallback)(()=>{i.current.clear(),c([])},[]);return{items:l,latest:l.length>0?l[l.length-1]:void 0,isAwaitingApproval:l.some(p=>et.has(p.status)),approve:w,reject:m,submitForm:f,clear:v}}function ae({client:e,conversationId:r}={}){const t=D(),s=e||t;if(!s)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(r),[x,d]=(0,n.useState)(!1),[g,w]=(0,n.useState)(null);(0,n.useEffect)(()=>{r&&r!==c&&(i(r),m(r))},[r]);const m=async f=>{try{l((await s.getMessages(f)).filter(v=>!v.hidden))}catch(v){w(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const f=y=>y==="IN_PROGRESS"||y==="WAITING_CLIENT",v=y=>{c||i(y.conversationId),d(!0),l(k=>{const j=k.findIndex(E=>E.id===y.messageId);return j>=0?k.map((E,h)=>h===j?{...E,status:"IN_PROGRESS"}:E):k.some(E=>E.role==="assistant"&&f(E.status))?k:[...k,{id:y.messageId,conversationId:y.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},p=y=>{l(k=>{const j=k.findIndex(E=>E.id===y.messageId);return j<0?k:k.map((E,h)=>h===j?{...E,content:E.content+y.content}:E)})},S=y=>{l(k=>{let j=-1;for(let E=k.length-1;E>=0;E--)if(k[E].role==="assistant"&&f(k[E].status)){j=E;break}return j<0?k:[...k.slice(0,j),{...k[j],...y},...k.slice(j+1)]})},b=y=>{l(k=>{const j=k.findIndex(E=>E.id===y.id);return j>=0?[...k.slice(0,j),y,...k.slice(j+1)]:[...k,y]}),d(!1)},N=y=>{w(new Error(y.error)),d(!1)},_=()=>{l(y=>{let k=-1;for(let j=y.length-1;j>=0;j--)if(y[j].role==="assistant"&&f(y[j].status)){k=j;break}return k<0?y:y[k].content?y.map((j,E)=>E===k?{...j,status:"CANCELED"}:j):y.filter((j,E)=>E!==k)}),d(!1)};return s.on("message:start",v),s.on("message:chunk",p),s.on("message:answer-complete",S),s.on("message:complete",b),s.on("message:error",N),s.on("message:stopped",_),()=>{s.off("message:start",v),s.off("message:chunk",p),s.off("message:answer-complete",S),s.off("message:complete",b),s.off("message:error",N),s.off("message:stopped",_)}},[s,c]),{messages:o,isLoading:x,error:g,sendMessage:(0,n.useCallback)(async(f,v)=>{d(!0),w(null);const p={id:`temp-${Date.now()}`,conversationId:c||"",content:f,role:"user",status:"DONE",attachments:v&&v.length>0?L.attachmentsFromFiles(v):void 0,createdAt:new Date},S={id:`temp-assistant-${Date.now()}`,conversationId:c||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(b=>[...b,p,S]);try{const b=await s.sendMessage(f,{conversationId:c,files:v});return b.conversationId&&!c&&i(b.conversationId),l(N=>{const _=N.filter(k=>!k.id.startsWith("temp-")),y={...p,id:p.id.replace("temp-","user-"),conversationId:b.conversationId};return _.some(k=>k.id===b.id)?[..._,y].sort((k,j)=>new Date(k.createdAt).getTime()-new Date(j.createdAt).getTime()):[..._,y,b]}),b}catch(b){return w(b instanceof Error?b:new Error("Failed to send message")),d(!1),l(N=>N.filter(_=>!_.id.startsWith("temp-"))),null}},[s,c]),stop:(0,n.useCallback)(async()=>{await s.stop()},[s]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),w(null)},[]),conversationId:c}}var me={compact:!1,state:"peek",isModal:!1,surface:{style:{},attrs:{}}},rt={tabindex:"tabIndex"};function ot(e){const r={};for(const[t,s]of Object.entries(e))r[rt[t]??t]=s;return r}function we(e){const r=e!==!1,t=r?e??{}:void 0,s=(0,n.useRef)(t?.onStateChange);s.current=t?.onStateChange;const o=(0,n.useMemo)(()=>{if(r)return G.createSheetController({breakpoint:t?.breakpoint,initialState:t?.initialState,bottomOffset:t?.bottomOffset,peekHeight:t?.peekHeight,onStateChange:(c,i)=>s.current?.(c,i)})},[r,t?.breakpoint,t?.initialState,t?.bottomOffset,t?.peekHeight]),l=(0,n.useSyncExternalStore)((0,n.useCallback)(c=>o?.subscribe(c)??(()=>{}),[o]),(0,n.useCallback)(()=>o?.getSnapshot()??me,[o]),(0,n.useCallback)(()=>o?.getServerSnapshot()??me,[o]));return{sheet:(0,n.useMemo)(()=>({...l,surface:{...l.surface,attrs:ot(l.surface.attrs)}}),[l]),expand:(0,n.useCallback)(c=>o?.expand(c),[o]),collapse:(0,n.useCallback)(c=>o?.collapse(c),[o]),toggle:(0,n.useCallback)(c=>o?.toggle(c),[o])}}var st=/(`[^`\n]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|_[^_\n]+_)/g;function Se(e){const r=e.split(st);return r.length===1?e:r.map((t,s)=>s%2===0||!t?t:t.startsWith("`")?(0,a.jsx)("code",{style:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",padding:"0 3px",borderRadius:"3px",backgroundColor:"rgba(0, 0, 0, 0.06)"},children:t.slice(1,-1)},s):t.startsWith("**")?(0,a.jsx)("strong",{style:{fontWeight:600},children:t.slice(2,-2)},s):(0,a.jsx)("em",{children:t.slice(1,-1)},s))}var at=`
2
2
  @keyframes ago-activity-enter {
3
3
  from { opacity: 0; transform: translateY(4px); }
4
4
  to { opacity: 1; transform: none; }
@@ -35,10 +35,10 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $e=Object
35
35
  color: var(--ago-activity-color, #5b5d5f);
36
36
  }
37
37
  }
38
- `,it=({label:e})=>(0,a.jsxs)("div",{className:"ago-activity",role:"status","aria-live":"polite",style:{display:"block",margin:"4px 0 0",padding:"6px 12px",borderRadius:"999px",width:"fit-content",maxWidth:"100%",fontSize:"13px",lineHeight:1.5,color:"var(--ago-activity-color, #5b5d5f)",backgroundColor:"var(--ago-activity-bg, #f1f2f3)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,a.jsx)("span",{className:"ago-activity__label",children:Se(e)},e),(0,a.jsx)("style",{children:at})]}),U=typeof window>"u"?n.useEffect:n.useLayoutEffect;function ke(e){const r=D(),t=e.client??r,s=(0,n.useRef)(null),o=(0,n.useRef)(),l=(0,n.useRef)(e),[c,i]=(0,n.useState)(!1),[x,d]=(0,n.useState)(""),[g,b]=(0,n.useState)(!1);return U(()=>{l.current=e}),U(()=>{if(b(!1),i(!1),l.current.onBusyChange?.(!1),!t||!s.current)return;let m=!0;const f=G.createSpeechToText({transcribe:(C,p)=>t.transcribeAudio(C,p),onText:C=>{m&&l.current.onTranscript(C)},onBusy:C=>{m&&(i(C),C&&d(""),l.current.onBusyChange?.(C))},onError:C=>{m&&d(C)},labels:l.current.labels});return s.current.append(f.el),o.current=f,f.setDisabled(!!l.current.disabled),t.getConfig().then(({permissions:C})=>{if(!m)return;const p=C.some(S=>S.speechToTextEnabled)&&typeof MediaRecorder<"u"&&!!navigator.mediaDevices?.getUserMedia;f.setEnabled(p),b(p)}).catch(()=>{}),()=>{m=!1,f.destroy(),l.current.onBusyChange?.(!1),f.el.remove(),o.current=void 0}},[t]),U(()=>{o.current?.setDisabled(!!e.disabled)},[e.disabled]),U(()=>{o.current?.cancel()},[e.scopeKey,t]),U(()=>{o.current?.setLabels(e.labels)},[e.labels]),(0,a.jsxs)("div",{className:`ago-speech-to-text ${e.className??""}`,style:{display:g?"flex":"none",flexDirection:"column",minWidth:0,flex:c?1:void 0},children:[(0,a.jsx)("div",{ref:s}),x&&(0,a.jsx)("span",{role:"alert",style:{color:"var(--ago-muted-text-color, #6b6d6f)",fontSize:"13px"},children:x})]})}var Ae=({onSend:e,onStop:r,disabled:t=!1,placeholder:s="Type a message...",allowFiles:o=!1,speechToText:l=!1,client:c,scopeKey:i,className:x=""})=>{const[d,g]=(0,n.useState)(""),[b,m]=(0,n.useState)([]),[f,C]=(0,n.useState)(!1),p=(0,n.useRef)(null),S=(0,n.useRef)(null),y=!!l;(0,n.useEffect)(()=>{y||C(!1)},[y]);const N=(0,n.useCallback)(()=>{const u=S.current;if(!u)return;const A=110;u.style.height="auto",u.style.height=`${Math.min(u.scrollHeight+2,A)}px`,u.style.overflowY=u.scrollHeight+2>A?"auto":"hidden"},[]),_=(0,n.useRef)(!1);(0,n.useEffect)(()=>{_.current&&!f&&!t&&(N(),S.current?.focus()),_.current=f},[f,t,N]);const v=(0,n.useCallback)(async u=>{if(u.preventDefault(),t||f||!d.trim()&&b.length===0)return;const A=d.trim(),R=b.length>0?b:void 0;g(""),m([]),requestAnimationFrame(N),await e(A,R)===!1&&(g(P=>P.trim()?P:A),R&&m(P=>[...R,...P]),requestAnimationFrame(N))},[d,b,e,N,t,f]),k=(0,n.useCallback)(u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),v(u))},[v]),j=(0,n.useCallback)(u=>{const A=Array.from(u.target.files||[]);m(R=>[...R,...A])},[]),E=(0,n.useCallback)(u=>{m(A=>A.filter((R,P)=>P!==u))},[]),h=d.trim()||b.length>0,I=u=>{g(A=>`${A}${A&&!/\s$/.test(A)?" ":""}${u}`)};return(0,a.jsxs)("form",{onSubmit:u=>{v(u)},className:`ago-chat-input ${x}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[b.length>0&&!f&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:b.map((u,A)=>(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,a.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.name}),(0,a.jsx)("button",{type:"button",onClick:()=>E(A),"aria-label":`Remove ${u.name}`,style:{flexShrink:0,width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},A))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&!f&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>p.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,onChange:j,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:S,className:"ago-chat-input__field",value:d,onChange:u=>{g(u.target.value),N()},onKeyDown:k,placeholder:s,"aria-label":s,disabled:t||f,rows:1,style:{display:f?"none":void 0,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:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onBlur:u=>{u.currentTarget.style.borderColor="#dee3e8"}}),l&&(0,a.jsx)(ke,{client:c,disabled:t,scopeKey:i,labels:typeof l=="object"?l.labels:void 0,onTranscript:I,onBusyChange:C}),!f&&(t&&r?(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!h,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"}))]})]})},lt=({href:e,children:r,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:r}),ct=({children:e,...r})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...r,children:e}),q=(e,r)=>{const t=({children:s,...o})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:r,fontWeight:600,lineHeight:"1.3"},...o},s);return t.displayName=`MarkdownHeading${e}`,t},ut=({children:e,...r})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...r,children:e}),dt=({children:e,...r})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...r,children:e}),ft=({children:e,...r})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...r,children:e}),pt=({className:e,children:r,...t})=>e!==void 0||String(r).includes(`
38
+ `,it=({label:e})=>(0,a.jsxs)("div",{className:"ago-activity",role:"status","aria-live":"polite",style:{display:"block",margin:"4px 0 0",padding:"6px 12px",borderRadius:"999px",width:"fit-content",maxWidth:"100%",fontSize:"13px",lineHeight:1.5,color:"var(--ago-activity-color, #5b5d5f)",backgroundColor:"var(--ago-activity-bg, #f1f2f3)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[(0,a.jsx)("span",{className:"ago-activity__label",children:Se(e)},e),(0,a.jsx)("style",{children:at})]}),U=typeof window>"u"?n.useEffect:n.useLayoutEffect;function ke(e){const r=D(),t=e.client??r,s=(0,n.useRef)(null),o=(0,n.useRef)(),l=(0,n.useRef)(e),[c,i]=(0,n.useState)(!1),[x,d]=(0,n.useState)(""),[g,w]=(0,n.useState)(!1);return U(()=>{l.current=e}),U(()=>{if(w(!1),i(!1),l.current.onBusyChange?.(!1),!t||!s.current)return;let m=!0;const f=G.createSpeechToText({transcribe:(v,p)=>t.transcribeAudio(v,p),onText:v=>{m&&l.current.onTranscript(v)},onBusy:v=>{m&&(i(v),v&&d(""),l.current.onBusyChange?.(v))},onError:v=>{m&&d(v)},labels:l.current.labels});return s.current.append(f.el),o.current=f,f.setDisabled(!!l.current.disabled),t.getConfig().then(({permissions:v})=>{if(!m)return;const p=v.some(S=>S.speechToTextEnabled)&&typeof MediaRecorder<"u"&&!!navigator.mediaDevices?.getUserMedia;f.setEnabled(p),w(p)}).catch(()=>{}),()=>{m=!1,f.destroy(),l.current.onBusyChange?.(!1),f.el.remove(),o.current=void 0}},[t]),U(()=>{o.current?.setDisabled(!!e.disabled)},[e.disabled]),U(()=>{o.current?.cancel()},[e.scopeKey,t]),U(()=>{o.current?.setLabels(e.labels)},[e.labels]),(0,a.jsxs)("div",{className:`ago-speech-to-text ${e.className??""}`,style:{display:g?"flex":"none",flexDirection:"column",minWidth:0,flex:c?1:void 0},children:[(0,a.jsx)("div",{ref:s}),x&&(0,a.jsx)("span",{role:"alert",style:{color:"var(--ago-muted-text-color, #6b6d6f)",fontSize:"13px"},children:x})]})}var Ae=({onSend:e,onStop:r,disabled:t=!1,placeholder:s="Type a message...",allowFiles:o=!1,speechToText:l=!1,client:c,scopeKey:i,className:x=""})=>{const[d,g]=(0,n.useState)(""),[w,m]=(0,n.useState)([]),[f,v]=(0,n.useState)(!1),p=(0,n.useRef)(null),S=(0,n.useRef)(null),b=!!l;(0,n.useEffect)(()=>{b||v(!1)},[b]);const N=(0,n.useCallback)(()=>{const u=S.current;if(!u)return;const A=110;u.style.height="auto",u.style.height=`${Math.min(u.scrollHeight+2,A)}px`,u.style.overflowY=u.scrollHeight+2>A?"auto":"hidden"},[]),_=(0,n.useRef)(!1);(0,n.useEffect)(()=>{_.current&&!f&&!t&&(N(),S.current?.focus()),_.current=f},[f,t,N]);const y=(0,n.useCallback)(async u=>{if(u.preventDefault(),t||f||!d.trim())return;const A=d.trim(),R=w.length>0?w:void 0;g(""),m([]),requestAnimationFrame(N),await e(A,R)===!1&&(g(P=>P.trim()?P:A),R&&m(P=>[...R,...P]),requestAnimationFrame(N))},[d,w,e,N,t,f]),k=(0,n.useCallback)(u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),y(u))},[y]),j=(0,n.useCallback)(u=>{const A=Array.from(u.target.files||[]);m(R=>[...R,...A])},[]),E=(0,n.useCallback)(u=>{m(A=>A.filter((R,P)=>P!==u))},[]),h=d.trim().length>0,I=u=>{g(A=>`${A}${A&&!/\s$/.test(A)?" ":""}${u}`)};return(0,a.jsxs)("form",{onSubmit:u=>{y(u)},className:`ago-chat-input ${x}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[w.length>0&&!f&&(0,a.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.map((u,A)=>(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,a.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.name}),(0,a.jsx)("button",{type:"button",onClick:()=>E(A),"aria-label":`Remove ${u.name}`,style:{flexShrink:0,width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},A))}),(0,a.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&!f&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",onClick:()=>p.current?.click(),disabled:t,"aria-label":"Attach file",style:{flexShrink:0,minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,a.jsx)("input",{ref:p,type:"file",multiple:!0,onChange:j,style:{display:"none"}})]}),(0,a.jsx)("textarea",{ref:S,className:"ago-chat-input__field",value:d,onChange:u=>{g(u.target.value),N()},onKeyDown:k,placeholder:s,"aria-label":s,disabled:t||f,rows:1,style:{display:f?"none":void 0,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:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onBlur:u=>{u.currentTarget.style.borderColor="#dee3e8"}}),l&&(0,a.jsx)(ke,{client:c,disabled:t,scopeKey:i,labels:typeof l=="object"?l.labels:void 0,onTranscript:I,onBusyChange:v}),!f&&(t&&r?(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Stop generating",style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:"#03182f",color:"#fff",cursor:"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Stop"}):(0,a.jsx)("button",{type:"submit",disabled:t||!h,style:{minHeight:"44px",padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"}))]})]})},lt=({href:e,children:r,...t})=>(0,a.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:r}),ct=({children:e,...r})=>(0,a.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...r,children:e}),q=(e,r)=>{const t=({children:s,...o})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:r,fontWeight:600,lineHeight:"1.3"},...o},s);return t.displayName=`MarkdownHeading${e}`,t},ut=({children:e,...r})=>(0,a.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...r,children:e}),dt=({children:e,...r})=>(0,a.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...r,children:e}),ft=({children:e,...r})=>(0,a.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...r,children:e}),pt=({className:e,children:r,...t})=>e!==void 0||String(r).includes(`
39
39
  `)?(0,a.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:r}):(0,a.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:r}),gt=({children:e,...r})=>(0,a.jsx)("pre",{style:{margin:"0 0 8px 0"},...r,children:e}),xt=({children:e,...r})=>(0,a.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...r,children:e}),mt=({children:e,...r})=>(0,a.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,a.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...r,children:e})}),ht=({children:e,...r})=>(0,a.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...r,children:e}),bt=({children:e,...r})=>(0,a.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...r,children:e}),yt=({alt:e,...r})=>(0,a.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...r}),vt=e=>(0,a.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),Ct={a:lt,p:ct,h1:q(1,"20px"),h2:q(2,"18px"),h3:q(3,"16px"),h4:q(4,"15px"),h5:q(5,"14px"),h6:q(6,"13px"),ul:ut,ol:dt,li:ft,code:pt,pre:gt,blockquote:xt,table:mt,th:ht,td:bt,img:yt,hr:vt},wt=[ne.default],je=({content:e})=>(0,a.jsx)(te.default,{remarkPlugins:wt,components:Ct,children:e}),St=({attachment:e,isUser:r})=>{const t=L.safeAttachmentUrl(e.url);if(L.canInlineImage(e))return(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,a.jsx)("img",{src:t,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const s=L.formatFileSize(e.fileSize),o=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,a.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,a.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),s&&(0,a.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:s})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:r?"rgba(255,255,255,0.12)":"#fff",color:r?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,a.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:l,children:o}):(0,a.jsx)("div",{style:l,children:o})},kt=({source:e,index:r})=>{const t=(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,a.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:r+1}),(0,a.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),s={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,a.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:s,onMouseEnter:o=>{o.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:o=>{o.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,a.jsx)("div",{style:s,children:t})},Ee=()=>(0,a.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,a.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:.55,animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,a.jsx)("style",{children:`
40
40
  @keyframes ago-pulse {
41
41
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
42
42
  40% { opacity: 1; transform: scale(1); }
43
43
  }
44
- `})]}),_e=({message:e,className:r="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:o,showStreamingDots:l=!0,feedback:c})=>{const i=e.role==="user",x=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${r}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.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,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((d,g)=>(0,a.jsx)(kt,{source:d,index:g},d.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(d=>(0,a.jsx)(St,{attachment:d,isUser:i},d.id))}),(e.content||x&&l)&&(0,a.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,a.jsx)(je,{content:e.content}):x&&l&&(0,a.jsx)(Ee,{})}),!i&&c,s&&e.followUpReplies&&e.followUpReplies.length>0&&(0,a.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((d,g)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!o,onClick:o?()=>o(d):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:o?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:b=>{b.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:b=>{b.currentTarget.style.borderColor="#dee3e8"},children:d},g))})]})};function Re({client:e}={}){const r=D(),t=e||r;if(!t)throw new Z.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,o]=(0,n.useState)({}),[l,c]=(0,n.useState)(!1),[i,x]=(0,n.useState)(null),d=(0,n.useRef)(new Map),g=m=>{const f=(d.current.get(m)??0)+1;return d.current.set(m,f),f},b=(m,f)=>d.current.get(m)===f;return{ratings:s,submitFeedback:(0,n.useCallback)(async(m,f,C)=>{const p=g(m);c(!0),x(null);try{await t.submitFeedback(m,f,C),b(m,p)&&o(S=>({...S,[m]:f}))}catch(S){const y=S instanceof Error?S:new Error("Failed to submit feedback");throw x(y),y}finally{c(!1)}},[t]),submitConversationFeedback:(0,n.useCallback)(async(m,f,C)=>{const p=g(m);c(!0),x(null);try{const S=await t.submitConversationFeedback(m,f,C);return b(m,p)&&o(y=>({...y,[S]:f})),S}catch(S){const y=S instanceof Error?S:new Error("Failed to submit feedback");throw x(y),y}finally{c(!1)}},[t]),isSubmitting:l,error:i}}var re={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."},At={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:0,border:"none",borderRadius:"8px",background:"transparent",cursor:"pointer",lineHeight:1},Ne=({messageId:e,client:r,askWhy:t=!0,labels:s,onSubmit:o,onError:l,className:c=""})=>{const i={...re,...s,reasons:{...re.reasons,...s?.reasons}},{ratings:x,submitFeedback:d}=Re({client:r}),g=x[e],[b,m]=(0,n.useState)(!1),[f,C]=(0,n.useState)([]),[p,S]=(0,n.useState)(""),[y,N]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),k=async(u,A)=>{try{return await d(e,u,A),o?.({messageId:e,rating:u,reasons:A?.reasons??[],comment:A?.comment||void 0}),!0}catch(R){return l?.(R instanceof Error?R:new Error(String(R))),!1}},j=u=>{k(u),m(u==="negative"&&t&&!y)},E=u=>{C(A=>A.includes(u)?A.filter(R=>R!==u):[...A,u])},h=f.length>0||p.trim().length>0,I=()=>{!h||_||(v(!0),k(g??"negative",{reasons:f,comment:p.trim()}).then(u=>{v(!1),u&&(N(!0),m(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${c}`,style:{marginTop:"6px",width:"100%",maxWidth:"85%"},children:[(0,a.jsxs)("div",{className:"ago-feedback__actions",style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,a.jsx)(he,{direction:"up",label:i.helpful,selected:g==="positive",onClick:()=>j("positive")}),(0,a.jsx)(he,{direction:"down",label:i.notHelpful,selected:g==="negative",onClick:()=>j("negative")})]}),y&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:i.thanks}),b&&!y&&(0,a.jsxs)("div",{className:"ago-feedback__panel",role:"group","aria-label":i.whatWentWrong,style:{marginTop:"8px",padding:"12px",border:"1px solid #dee3e8",borderRadius:"16px",backgroundColor:"#fff"},children:[(0,a.jsx)("div",{style:{fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"8px"},children:i.whatWentWrong}),(0,a.jsx)("div",{className:"ago-feedback__reasons",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"},children:L.FEEDBACK_REASONS.map(u=>{const A=f.includes(u);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":A,onClick:()=>E(u),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${A?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:A?"#1b5fc4":"#30373e",cursor:"pointer"},children:i.reasons[u]},u)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:p,placeholder:i.commentPlaceholder,"aria-label":i.commentPlaceholder,onChange:u=>S(u.target.value),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:"#30373e",border:"1px solid #dee3e8",borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}}),(0,a.jsx)("button",{type:"button",className:"ago-feedback__send",onClick:I,disabled:!h||_,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:h?"#03182f":"#b5bfc8",color:"#fff",opacity:_?.6:1,cursor:h&&!_?"pointer":"default"},children:i.send})]})]})},he=({direction:e,label:r,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":r,"aria-pressed":t,title:r,onClick:s,style:{...At,color:t?"#1b5fc4":"#6b6d6f"},children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:e==="down"?{transform:"rotate(180deg)"}:void 0,children:[(0,a.jsx)("path",{d:"M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"})]})}),jt=(0,n.forwardRef)(function({client:r,conversationId:t,title:s="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:l="Type a message...",allowFiles:c=!1,speechToText:i=!1,allowStop:x=!0,height:d=500,logoUrl:g,showAgentName:b=!1,forms:m,feedback:f=!1,onFollowUpClick:C,className:p="",onMessageSent:S,onMessageReceived:y,sheet:N=!1,thinkingLabel:_="Thinking...",functionLabels:v,showReasoning:k=!0},j){const E=(0,n.useRef)(null),h=(0,n.useRef)(!0),[I,u]=(0,n.useState)(!0),A=(0,n.useRef)(null),{sheet:R,expand:P,collapse:$,toggle:ie}=we(N),[Fe,Q]=(0,n.useState)(!1),ee=R.compact&&R.state==="peek",Pe=D(),H=r??Pe,{messages:F,isLoading:De,error:le,sendMessage:We,stop:Le}=ae({client:r,conversationId:t});(0,n.useEffect)(()=>{if(!H||!m||m.length===0)return;let w=!1;const T=[];return Promise.all(m.map(M=>M.schema!=null?Promise.resolve(z.createFormCollector(M)):z.loadFormCollector(H,M))).then(M=>{if(!w)for(const W of M)T.push(W.install(H))}).catch(()=>{}),()=>{w=!0,T.forEach(M=>M())}},[H,m?JSON.stringify(m.map(w=>[w.name,w.schema??null,w.submit??!1,w.description??null])):""]),(0,n.useEffect)(()=>{const w=E.current;!w||!h.current||(w.scrollTop=w.scrollHeight)},[F]);const Oe=()=>{const w=E.current;w&&(h.current=!0,u(!0),w.scrollTop=w.scrollHeight)};(0,n.useEffect)(()=>{const w=F[F.length-1];w&&w.role==="assistant"&&w.status==="DONE"&&y&&y({id:w.id,content:w.content})},[F,y]),(0,n.useEffect)(()=>{Q(!!ee)},[F.length]),(0,n.useEffect)(()=>{const w=A.current;if(!R.compact||!w)return;const T=document.documentElement;if(R.state!=="peek")return;const M=()=>{T.style.setProperty("--ago-sheet-height",`${Math.round(w.getBoundingClientRect().height)}px`)};M();const W=typeof ResizeObserver=="function"?new ResizeObserver(M):null;return W?.observe(w),()=>W?.disconnect()},[R.compact,R.state]),(0,n.useEffect)(()=>{R.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[R.compact]),(0,n.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,n.useImperativeHandle)(j,()=>({expand:P,collapse:$,toggle:ie,state:R.state}),[P,$,ie,R.state]),(0,n.useEffect)(()=>{if(!R.isModal)return;const w=Symbol("ago-react-sheet");G.lockBackgroundScroll(w);const T=M=>{if(M.key==="Escape"){$("user");return}if(M.key!=="Tab")return;const W=A.current;if(!W)return;const V=Array.from(W.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(qe=>qe.getClientRects().length>0);if(V.length===0){M.preventDefault();return}const fe=V[0],pe=V[V.length-1],X=document.activeElement;M.shiftKey&&(X===fe||!W.contains(X))?(M.preventDefault(),pe.focus()):!M.shiftKey&&(X===pe||!W.contains(X))&&(M.preventDefault(),fe.focus())};return document.addEventListener("keydown",T),A.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",T),G.unlockBackgroundScroll(w)}},[R.isModal,$]);const ce=async(w,T)=>(h.current=!0,u(!0),S?.(w),await We(w,T)!==null),O=F[F.length-1],J=De&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),ze=(0,n.useCallback)(w=>{const T=w.functionName;if(!(!v||!T))return typeof v=="function"?v(T,w.arguments??{}):v[T]},[v]),{items:Be}=Ce({client:H??void 0,labelFor:ze,includeReasoning:k}),ue=Be.filter(w=>O?.id!==void 0&&w.messageId===O.id),K=v===!1?void 0:ue[ue.length-1]?.label,de=!!(J&&K),He=C===!1?void 0:C??(w=>ce(w));return(0,a.jsxs)("div",{ref:A,className:`ago-chat-widget ${p}`,...R.surface.attrs,"data-ago-sheet-state":R.compact?R.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,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",...R.surface.style},children:[!R.compact&&(0,a.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:[g&&(0,a.jsx)("img",{src:g,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),ee&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{Q(!1),P("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[s,Fe&&(0,a.jsx)("span",{"aria-label":"New message",style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),J&&!O?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!K&&(0,a.jsx)(Ee,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K?Se(K):_})]}):(0,a.jsx)("span",{style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"13px",lineHeight:1.5,color:"inherit",minHeight:"calc(2 * 1.5 * 13px)"},children:O?.content||o})]}),R.compact&&R.state==="full"&&(0,a.jsxs)("div",{className:"ago-chat-widget__sheet-header",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px 6px 18px",borderBottom:"1px solid rgba(128,128,128,0.25)",flexShrink:0},children:[(0,a.jsx)("span",{style:{fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:s}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>$("user"),style:{marginLeft:"auto",flexShrink:0,width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"inherit",cursor:"pointer"},children:(0,a.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M6 9l6 6 6-6"})})})]}),(0,a.jsxs)("div",{style:{position:"relative",flex:1,display:ee?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:E,className:"ago-chat-widget__messages",onScroll:w=>{const T=w.currentTarget,M=T.scrollHeight-T.scrollTop-T.clientHeight<=48;h.current=M,u(M)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":J,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[F.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):F.map((w,T)=>(0,a.jsx)(_e,{message:w,showAgentName:b,isLast:T===F.length-1,onFollowUpClick:He,showStreamingDots:!de,feedback:f&&w.role==="assistant"&&w.status==="DONE"&&w.content?(0,a.jsx)(Ne,{messageId:w.id,client:r,...f===!0?{}:f}):void 0},w.id)),de&&(0,a.jsx)(it,{label:K??""}),le&&(0,a.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:le.message}),(0,a.jsx)("div",{})]}),!I&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:Oe,style:{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #dee3e8",borderRadius:"50%",backgroundColor:"#fff",color:"#0b1b2b",boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:2},children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M12 5v14M19 12l-7 7-7-7"})})})]}),(0,a.jsx)(Ae,{onSend:ce,onStop:x?()=>{Le()}:void 0,disabled:J,placeholder:l,allowFiles:c,speechToText:i,client:H??void 0,scopeKey:`${t??F[0]?.conversationId??""}:${R.state}`})]})});function Ie(e={}){const r=D(),t=e.client??r;if(!t)throw new Z.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,o]=(0,n.useState)(null),l=(0,n.useRef)(s);l.current=s;const c=(0,n.useRef)(e.onExpand);return c.current=e.onExpand,(0,n.useEffect)(()=>{const i=d=>{o(d),t.proactive?.shown(d)},x=({nudge:d})=>{o(g=>g?.id===d.id?null:g)};return t.on("nudge:ready",i),t.on("nudge:accepted",x),t.on("nudge:dismissed",x),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",x),t.off("nudge:dismissed",x)}},[t]),{nudge:s,accept:(0,n.useCallback)(async()=>{const i=l.current;i&&(o(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&c.current?.(i))},[t]),dismiss:(0,n.useCallback)(()=>{const i=l.current;i&&(o(null),t.proactive?.dismiss(i))},[t])}}var Et=({client:e,onExpand:r,autoHideMs:t,position:s="bottom-right",openChatLabel:o="Open chat",className:l=""})=>{const{nudge:c,accept:i,dismiss:x}=Ie({client:e,onExpand:r});if((0,n.useEffect)(()=>{if(!c||!t)return;const g=setTimeout(()=>x(),t);return()=>clearTimeout(g)},[c,t,x]),!c)return null;const d=c.source==="agent"||!!c.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${l}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...s==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:x,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,a.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:c.message}),(c.action||d)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[c.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{i()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:c.action.label}),d&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{i()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:o})]})]})};function Me({client:e,autoLoad:r=!0}={}){const t=D(),s=e||t;if(!s)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(null),[x,d]=(0,n.useState)(!1),[g,b]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{d(!0),b(null);try{const{data:p}=await s.getConversations();l(p)}catch(p){b(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[s]),f=(0,n.useCallback)(async p=>{d(!0),b(null);try{i(await s.getConversation(p))}catch(S){b(S instanceof Error?S:new Error("Failed to load conversation"))}finally{d(!1)}},[s]),C=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{r&&m()},[r,m]),{conversations:o,currentConversation:c,isLoading:x,error:g,selectConversation:f,startNewConversation:C,refreshConversations:m}}function _t(e={}){const r=D(),t=e.client||r;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=ae({client:t,conversationId:e.conversationId}),o=Me({client:t,autoLoad:e.autoLoad});return{messages:s.messages,isLoading:s.isLoading,error:s.error||o.error,sendMessage:s.sendMessage,stop:s.stop,clearMessages:s.clearMessages,conversationId:s.conversationId,conversations:o.conversations,currentConversation:o.currentConversation,isConversationsLoading:o.isLoading,selectConversation:o.selectConversation,startNewConversation:o.startNewConversation,refreshConversations:o.refreshConversations}}function Rt(e,r){const t=B(),{name:s,description:o,parameters:l,handler:c,maxResultBytes:i,requiresApproval:x,webmcp:d}=typeof e=="string"?{name:e,...r}:e,g=(0,n.useRef)(c);g.current=c,(0,n.useEffect)(()=>{const b=m=>g.current(m);return t.registerFunction(s,b,{description:o,parameters:l,maxResultBytes:i,requiresApproval:x,webmcp:d}),()=>{t.unregisterFunction(s)}},[t,s,o,l,i,x,JSON.stringify(d??null)])}function Nt(e,r){const t=B(),s=(0,n.useRef)(e);s.current=e,(0,n.useEffect)(()=>(t.registerNavigationFunction(o=>s.current(o),r),()=>{t.unregisterNavigationFunction()}),[t,r])}function It(e,r){const t=B(),s=r?.functionName??"setPageState",o=r?.requiresApproval,l=r?.data!==void 0,c=r?.data?.description,i=r?.data?.maxResultBytes,x=r?.settleTimeoutMs,d=(0,n.useRef)(e);d.current=e;const g=(0,n.useRef)(r);g.current=r,(0,n.useEffect)(()=>{const b=d.current.map(f=>{const C=()=>d.current.find(p=>p.name===f.name)??f;return{name:f.name,description:f.description,schema:f.schema,clearable:f.clearable,get:f.get?()=>C().get?.():void 0,set:p=>C().set(p)}}),m=l?{description:c??"What the page is currently showing.",maxResultBytes:i,get:()=>g.current?.data?.get(),isLoading:()=>g.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(b,{functionName:s,requiresApproval:o,data:m,settleTimeoutMs:x}),()=>{t.unregisterPageStateFunction(s)}},[t,s,o,l,c,i,x,JSON.stringify(e.map(b=>({name:b.name,description:b.description,schema:b.schema,clearable:b.clearable})))])}function Mt(e){const r=B(),t=(0,n.useRef)(e);t.current=e,(0,n.useEffect)(()=>Ye.attachAutoContinueAfterNavigation(r,()=>t.current),[r])}function Tt(e={}){const r=D(),t=e.client||r;if(!t)throw new Z.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,o]=(0,n.useState)(()=>t.getRecentActivity());(0,n.useEffect)(()=>{o(t.getRecentActivity());const i=()=>o(t.getRecentActivity());return t.on("activity:recorded",i),()=>t.off("activity:recorded",i)},[t]);const l=(0,n.useCallback)(i=>t.recordActivity(i),[t]),c=(0,n.useCallback)(()=>{t.clearActivity(),o([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:l,clear:c}}function Ft(e,r){const t=B(),s=(0,n.useId)(),o=r??s,l=(0,n.useRef)(e);l.current=e;const c=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return t.addDynamicContext(o,i),()=>{t.removeDynamicContext(o)}}return t.setContext(o,l.current),()=>{t.removeContext(o)}},[t,o,c,c?"":JSON.stringify(e)])}function Te(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var be={missing:[],complete:!1};function Pt(e){const r=B(),t=e.schema!=null,s=JSON.stringify(e.schema??null),o=e.submit,l=o?typeof o=="string"?`client:${o}`:o.via==="backend"?"backend":"handler"in o?"client:handler":`client:${o.url}`:"none",c=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>t?z.createFormCollector(e):null,[t,e.name,s,l,c,e.autoSubmit]),[x,d]=(0,n.useState)({collector:null,loading:!t,error:null});(0,n.useEffect)(()=>{if(t)return;let N=!1;return d({collector:null,loading:!0,error:null}),z.loadFormCollector(r,e).then(_=>{N||d({collector:_,loading:!1,error:null})}).catch(_=>{N||d({collector:null,loading:!1,error:_ instanceof Error?_:new Error(String(_))})}),()=>{N=!0}},[r,t,e.name,l,c,e.autoSubmit]);const g=t?i:x.collector,b=t?!1:x.loading,m=t?null:x.error;(0,n.useEffect)(()=>{if(g)return g.install(r)},[r,g]);const f=(0,n.useMemo)(()=>L.createStore({values:e.initialValues??{},submitted:!1}),[c]),C=Te(g?.store??f),p=(0,n.useMemo)(()=>g?.getStatus()??be,[C,g]),S=(0,n.useMemo)(()=>({...C,...p}),[C,p]),y=(0,n.useMemo)(()=>({name:e.name,store:f,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>f.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>be}),[e.name,f]);return{...g??y,state:S,loading:b,error:m}}exports.AgoNudge=Et;exports.AgoProvider=Qe;exports.ChatInput=Ae;exports.ChatWidget=jt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=re;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=G.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.FEEDBACK_REASONS=L.FEEDBACK_REASONS;exports.Markdown=je;exports.Message=_e;exports.MessageFeedback=Ne;exports.SpeechToTextButton=ke;exports.__exportAll=Ve;exports.createFormCollector=z.createFormCollector;exports.createMockClient=Ze.createMockClient;exports.deriveFormStatus=z.deriveFormStatus;exports.loadFormCollector=z.loadFormCollector;exports.useAgo=ye;exports.useAgoActivity=Ce;exports.useAgoActivityLog=Tt;exports.useAgoAutoContinueAfterNavigation=Mt;exports.useAgoClient=B;exports.useAgoContext=Ft;exports.useAgoFunction=Rt;exports.useAgoNavigation=Nt;exports.useAgoPageState=It;exports.useAgoStore=Te;exports.useChat=_t;exports.useConversation=Me;exports.useFeedback=Re;exports.useFormCollector=Pt;exports.useMessages=ae;exports.useOptionalAgoClient=D;exports.useProactiveNudge=Ie;exports.useSheet=we;
44
+ `})]}),_e=({message:e,className:r="",showAgentName:t=!1,isLast:s=!1,onFollowUpClick:o,showStreamingDots:l=!0,feedback:c})=>{const i=e.role==="user",x=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,a.jsxs)("div",{className:`ago-message ago-message--${e.role} ${r}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,a.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,a.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((d,g)=>(0,a.jsx)(kt,{source:d,index:g},d.id))}),e.attachments&&e.attachments.length>0&&(0,a.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(d=>(0,a.jsx)(St,{attachment:d,isUser:i},d.id))}),(e.content||x&&l)&&(0,a.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,a.jsx)(je,{content:e.content}):x&&l&&(0,a.jsx)(Ee,{})}),!i&&c,s&&e.followUpReplies&&e.followUpReplies.length>0&&(0,a.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((d,g)=>(0,a.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!o,onClick:o?()=>o(d):void 0,style:{minHeight:"44px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:o?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:w=>{w.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:w=>{w.currentTarget.style.borderColor="#dee3e8"},children:d},g))})]})};function Re({client:e}={}){const r=D(),t=e||r;if(!t)throw new Z.AgoError("useFeedback requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","missing_client");const[s,o]=(0,n.useState)({}),[l,c]=(0,n.useState)(!1),[i,x]=(0,n.useState)(null),d=(0,n.useRef)(new Map),g=m=>{const f=(d.current.get(m)??0)+1;return d.current.set(m,f),f},w=(m,f)=>d.current.get(m)===f;return{ratings:s,submitFeedback:(0,n.useCallback)(async(m,f,v)=>{const p=g(m);c(!0),x(null);try{await t.submitFeedback(m,f,v),w(m,p)&&o(S=>({...S,[m]:f}))}catch(S){const b=S instanceof Error?S:new Error("Failed to submit feedback");throw x(b),b}finally{c(!1)}},[t]),submitConversationFeedback:(0,n.useCallback)(async(m,f,v)=>{const p=g(m);c(!0),x(null);try{const S=await t.submitConversationFeedback(m,f,v);return w(m,p)&&o(b=>({...b,[S]:f})),S}catch(S){const b=S instanceof Error?S:new Error("Failed to submit feedback");throw x(b),b}finally{c(!1)}},[t]),isSubmitting:l,error:i}}var re={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."},At={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:0,border:"none",borderRadius:"8px",background:"transparent",cursor:"pointer",lineHeight:1},Ne=({messageId:e,client:r,askWhy:t=!0,labels:s,onSubmit:o,onError:l,className:c=""})=>{const i={...re,...s,reasons:{...re.reasons,...s?.reasons}},{ratings:x,submitFeedback:d}=Re({client:r}),g=x[e],[w,m]=(0,n.useState)(!1),[f,v]=(0,n.useState)([]),[p,S]=(0,n.useState)(""),[b,N]=(0,n.useState)(!1),[_,y]=(0,n.useState)(!1),k=async(u,A)=>{try{return await d(e,u,A),o?.({messageId:e,rating:u,reasons:A?.reasons??[],comment:A?.comment||void 0}),!0}catch(R){return l?.(R instanceof Error?R:new Error(String(R))),!1}},j=u=>{k(u),m(u==="negative"&&t&&!b)},E=u=>{v(A=>A.includes(u)?A.filter(R=>R!==u):[...A,u])},h=f.length>0||p.trim().length>0,I=()=>{!h||_||(y(!0),k(g??"negative",{reasons:f,comment:p.trim()}).then(u=>{y(!1),u&&(N(!0),m(!1))}))};return(0,a.jsxs)("div",{className:`ago-feedback ${c}`,style:{marginTop:"6px",width:"100%",maxWidth:"85%"},children:[(0,a.jsxs)("div",{className:"ago-feedback__actions",style:{display:"flex",alignItems:"center",gap:"2px"},children:[(0,a.jsx)(he,{direction:"up",label:i.helpful,selected:g==="positive",onClick:()=>j("positive")}),(0,a.jsx)(he,{direction:"down",label:i.notHelpful,selected:g==="negative",onClick:()=>j("negative")})]}),b&&(0,a.jsx)("div",{className:"ago-feedback__thanks",role:"status",style:{marginTop:"6px",fontSize:"13px",color:"#6b6d6f"},children:i.thanks}),w&&!b&&(0,a.jsxs)("div",{className:"ago-feedback__panel",role:"group","aria-label":i.whatWentWrong,style:{marginTop:"8px",padding:"12px",border:"1px solid #dee3e8",borderRadius:"16px",backgroundColor:"#fff"},children:[(0,a.jsx)("div",{style:{fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"8px"},children:i.whatWentWrong}),(0,a.jsx)("div",{className:"ago-feedback__reasons",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"},children:L.FEEDBACK_REASONS.map(u=>{const A=f.includes(u);return(0,a.jsx)("button",{type:"button",className:"ago-feedback__reason","aria-pressed":A,onClick:()=>E(u),style:{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${A?"#1b5fc4":"#dee3e8"}`,backgroundColor:"transparent",color:A?"#1b5fc4":"#30373e",cursor:"pointer"},children:i.reasons[u]},u)})}),(0,a.jsx)("textarea",{className:"ago-feedback__comment",rows:2,value:p,placeholder:i.commentPlaceholder,"aria-label":i.commentPlaceholder,onChange:u=>S(u.target.value),style:{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:"#30373e",border:"1px solid #dee3e8",borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}}),(0,a.jsx)("button",{type:"button",className:"ago-feedback__send",onClick:I,disabled:!h||_,style:{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:h?"#03182f":"#b5bfc8",color:"#fff",opacity:_?.6:1,cursor:h&&!_?"pointer":"default"},children:i.send})]})]})},he=({direction:e,label:r,selected:t,onClick:s})=>(0,a.jsx)("button",{type:"button",className:`ago-feedback__thumb ago-feedback__thumb--${e}`,"aria-label":r,"aria-pressed":t,title:r,onClick:s,style:{...At,color:t?"#1b5fc4":"#6b6d6f"},children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:e==="down"?{transform:"rotate(180deg)"}:void 0,children:[(0,a.jsx)("path",{d:"M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round"})]})}),jt=(0,n.forwardRef)(function({client:r,conversationId:t,title:s="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:l="Type a message...",allowFiles:c=!1,speechToText:i=!1,allowStop:x=!0,height:d=500,logoUrl:g,showAgentName:w=!1,forms:m,feedback:f=!1,onFollowUpClick:v,className:p="",onMessageSent:S,onMessageReceived:b,sheet:N=!1,thinkingLabel:_="Thinking...",functionLabels:y,showReasoning:k=!0},j){const E=(0,n.useRef)(null),h=(0,n.useRef)(!0),[I,u]=(0,n.useState)(!0),A=(0,n.useRef)(null),{sheet:R,expand:P,collapse:$,toggle:ie}=we(N),[Fe,Q]=(0,n.useState)(!1),ee=R.compact&&R.state==="peek",Pe=D(),H=r??Pe,{messages:F,isLoading:De,error:le,sendMessage:We,stop:Le}=ae({client:r,conversationId:t});(0,n.useEffect)(()=>{if(!H||!m||m.length===0)return;let C=!1;const T=[];return Promise.all(m.map(M=>M.schema!=null?Promise.resolve(z.createFormCollector(M)):z.loadFormCollector(H,M))).then(M=>{if(!C)for(const W of M)T.push(W.install(H))}).catch(()=>{}),()=>{C=!0,T.forEach(M=>M())}},[H,m?JSON.stringify(m.map(C=>[C.name,C.schema??null,C.submit??!1,C.description??null])):""]),(0,n.useEffect)(()=>{const C=E.current;!C||!h.current||(C.scrollTop=C.scrollHeight)},[F]);const Oe=()=>{const C=E.current;C&&(h.current=!0,u(!0),C.scrollTop=C.scrollHeight)};(0,n.useEffect)(()=>{const C=F[F.length-1];C&&C.role==="assistant"&&C.status==="DONE"&&b&&b({id:C.id,content:C.content})},[F,b]),(0,n.useEffect)(()=>{Q(!!ee)},[F.length]),(0,n.useEffect)(()=>{const C=A.current;if(!R.compact||!C)return;const T=document.documentElement;if(R.state!=="peek")return;const M=()=>{T.style.setProperty("--ago-sheet-height",`${Math.round(C.getBoundingClientRect().height)}px`)};M();const W=typeof ResizeObserver=="function"?new ResizeObserver(M):null;return W?.observe(C),()=>W?.disconnect()},[R.compact,R.state]),(0,n.useEffect)(()=>{R.compact||document.documentElement.style.removeProperty("--ago-sheet-height")},[R.compact]),(0,n.useEffect)(()=>()=>{document.documentElement.style.removeProperty("--ago-sheet-height")},[]),(0,n.useImperativeHandle)(j,()=>({expand:P,collapse:$,toggle:ie,state:R.state}),[P,$,ie,R.state]),(0,n.useEffect)(()=>{if(!R.isModal)return;const C=Symbol("ago-react-sheet");G.lockBackgroundScroll(C);const T=M=>{if(M.key==="Escape"){$("user");return}if(M.key!=="Tab")return;const W=A.current;if(!W)return;const V=Array.from(W.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(qe=>qe.getClientRects().length>0);if(V.length===0){M.preventDefault();return}const fe=V[0],pe=V[V.length-1],X=document.activeElement;M.shiftKey&&(X===fe||!W.contains(X))?(M.preventDefault(),pe.focus()):!M.shiftKey&&(X===pe||!W.contains(X))&&(M.preventDefault(),fe.focus())};return document.addEventListener("keydown",T),A.current?.focus({preventScroll:!0}),()=>{document.removeEventListener("keydown",T),G.unlockBackgroundScroll(C)}},[R.isModal,$]);const ce=async(C,T)=>(h.current=!0,u(!0),S?.(C),await We(C,T)!==null),O=F[F.length-1],J=De&&O?.role==="assistant"&&(O.status==="IN_PROGRESS"||O.status==="WAITING_CLIENT"),ze=(0,n.useCallback)(C=>{const T=C.functionName;if(!(!y||!T))return typeof y=="function"?y(T,C.arguments??{}):y[T]},[y]),{items:Be}=Ce({client:H??void 0,labelFor:ze,includeReasoning:k}),ue=Be.filter(C=>O?.id!==void 0&&C.messageId===O.id),K=y===!1?void 0:ue[ue.length-1]?.label,de=!!(J&&K),He=v===!1?void 0:v??(C=>ce(C));return(0,a.jsxs)("div",{ref:A,className:`ago-chat-widget ${p}`,...R.surface.attrs,"data-ago-sheet-state":R.compact?R.state:void 0,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,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",...R.surface.style},children:[!R.compact&&(0,a.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:[g&&(0,a.jsx)("img",{src:g,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,a.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),ee&&(0,a.jsxs)("button",{type:"button",className:"ago-chat-widget__peek","aria-expanded":!1,"aria-label":"Open the conversation",onClick:()=>{Q(!1),P("user")},style:{display:"flex",flexDirection:"column",alignItems:"stretch",gap:"8px",padding:"14px 18px 10px",border:"none",borderBottom:"1px solid currentColor",borderBottomColor:"rgba(128,128,128,0.25)",background:"transparent",textAlign:"left",cursor:"pointer",font:"inherit",color:"inherit"},children:[(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7},children:[s,Fe&&(0,a.jsx)("span",{"aria-label":"New message",style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#1b5fc4"}}),(0,a.jsx)("span",{style:{marginLeft:"auto",fontSize:"14px"},"aria-hidden":!0,children:"↑"})]}),J&&!O?.content?(0,a.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[!K&&(0,a.jsx)(Ee,{}),(0,a.jsx)("span",{style:{fontSize:"13px",opacity:.7,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:K?Se(K):_})]}):(0,a.jsx)("span",{style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"13px",lineHeight:1.5,color:"inherit",minHeight:"calc(2 * 1.5 * 13px)"},children:O?.content||o})]}),R.compact&&R.state==="full"&&(0,a.jsxs)("div",{className:"ago-chat-widget__sheet-header",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px 6px 18px",borderBottom:"1px solid rgba(128,128,128,0.25)",flexShrink:0},children:[(0,a.jsx)("span",{style:{fontSize:"12px",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"inherit",opacity:.7,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:s}),(0,a.jsx)("button",{type:"button","aria-label":"Collapse the conversation",onClick:()=>$("user"),style:{marginLeft:"auto",flexShrink:0,width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",color:"inherit",cursor:"pointer"},children:(0,a.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M6 9l6 6 6-6"})})})]}),(0,a.jsxs)("div",{style:{position:"relative",flex:1,display:ee?"none":"flex",minHeight:0},children:[(0,a.jsxs)("div",{ref:E,className:"ago-chat-widget__messages",onScroll:C=>{const T=C.currentTarget,M=T.scrollHeight-T.scrollTop-T.clientHeight<=48;h.current=M,u(M)},role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,"aria-busy":J,style:{flex:1,overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:"#fbfbfb"},children:[F.length===0?(0,a.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):F.map((C,T)=>(0,a.jsx)(_e,{message:C,showAgentName:w,isLast:T===F.length-1,onFollowUpClick:He,showStreamingDots:!de,feedback:f&&C.role==="assistant"&&C.status==="DONE"&&C.content?(0,a.jsx)(Ne,{messageId:C.id,client:r,...f===!0?{}:f}):void 0},C.id)),de&&(0,a.jsx)(it,{label:K??""}),le&&(0,a.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:le.message}),(0,a.jsx)("div",{})]}),!I&&(0,a.jsx)("button",{type:"button",className:"ago-chat-widget__jump","aria-label":"Jump to latest message",onClick:Oe,style:{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid #dee3e8",borderRadius:"50%",backgroundColor:"#fff",color:"#0b1b2b",boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:2},children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,a.jsx)("path",{d:"M12 5v14M19 12l-7 7-7-7"})})})]}),(0,a.jsx)(Ae,{onSend:ce,onStop:x?()=>{Le()}:void 0,disabled:J,placeholder:l,allowFiles:c,speechToText:i,client:H??void 0,scopeKey:`${t??F[0]?.conversationId??""}:${R.state}`})]})});function Ie(e={}){const r=D(),t=e.client??r;if(!t)throw new Z.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[s,o]=(0,n.useState)(null),l=(0,n.useRef)(s);l.current=s;const c=(0,n.useRef)(e.onExpand);return c.current=e.onExpand,(0,n.useEffect)(()=>{const i=d=>{o(d),t.proactive?.shown(d)},x=({nudge:d})=>{o(g=>g?.id===d.id?null:g)};return t.on("nudge:ready",i),t.on("nudge:accepted",x),t.on("nudge:dismissed",x),()=>{t.off("nudge:ready",i),t.off("nudge:accepted",x),t.off("nudge:dismissed",x)}},[t]),{nudge:s,accept:(0,n.useCallback)(async()=>{const i=l.current;i&&(o(null),await t.proactive?.accept(i),(i.source==="agent"||i.goal)&&c.current?.(i))},[t]),dismiss:(0,n.useCallback)(()=>{const i=l.current;i&&(o(null),t.proactive?.dismiss(i))},[t])}}var Et=({client:e,onExpand:r,autoHideMs:t,position:s="bottom-right",openChatLabel:o="Open chat",className:l=""})=>{const{nudge:c,accept:i,dismiss:x}=Ie({client:e,onExpand:r});if((0,n.useEffect)(()=>{if(!c||!t)return;const g=setTimeout(()=>x(),t);return()=>clearTimeout(g)},[c,t,x]),!c)return null;const d=c.source==="agent"||!!c.goal;return(0,a.jsxs)("div",{className:`ago-nudge ${l}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...s==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,a.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:x,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,a.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:c.message}),(c.action||d)&&(0,a.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[c.action&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{i()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:c.action.label}),d&&(0,a.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{i()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:o})]})]})};function Me({client:e,autoLoad:r=!0}={}){const t=D(),s=e||t;if(!s)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[o,l]=(0,n.useState)([]),[c,i]=(0,n.useState)(null),[x,d]=(0,n.useState)(!1),[g,w]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{d(!0),w(null);try{const{data:p}=await s.getConversations();l(p)}catch(p){w(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[s]),f=(0,n.useCallback)(async p=>{d(!0),w(null);try{i(await s.getConversation(p))}catch(S){w(S instanceof Error?S:new Error("Failed to load conversation"))}finally{d(!1)}},[s]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{r&&m()},[r,m]),{conversations:o,currentConversation:c,isLoading:x,error:g,selectConversation:f,startNewConversation:v,refreshConversations:m}}function _t(e={}){const r=D(),t=e.client||r;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const s=ae({client:t,conversationId:e.conversationId}),o=Me({client:t,autoLoad:e.autoLoad});return{messages:s.messages,isLoading:s.isLoading,error:s.error||o.error,sendMessage:s.sendMessage,stop:s.stop,clearMessages:s.clearMessages,conversationId:s.conversationId,conversations:o.conversations,currentConversation:o.currentConversation,isConversationsLoading:o.isLoading,selectConversation:o.selectConversation,startNewConversation:o.startNewConversation,refreshConversations:o.refreshConversations}}function Rt(e,r){const t=B(),{name:s,description:o,parameters:l,handler:c,maxResultBytes:i,requiresApproval:x,webmcp:d}=typeof e=="string"?{name:e,...r}:e,g=(0,n.useRef)(c);g.current=c,(0,n.useEffect)(()=>{const w=m=>g.current(m);return t.registerFunction(s,w,{description:o,parameters:l,maxResultBytes:i,requiresApproval:x,webmcp:d}),()=>{t.unregisterFunction(s)}},[t,s,o,JSON.stringify(l),i,x,JSON.stringify(d??null)])}function Nt(e,r,t){const s=B(),o=(0,n.useRef)(e);o.current=e;const l=t?.catalogue;(0,n.useEffect)(()=>(s.registerNavigationFunction(c=>o.current(c),r,{catalogue:l==="onDemand"?"onDemand":"inline"}),()=>{s.unregisterNavigationFunction()}),[s,r,l])}function It(e,r){const t=B(),s=r?.functionName??"setPageState",o=r?.requiresApproval,l=r?.data!==void 0,c=r?.data?.description,i=r?.data?.maxResultBytes,x=r?.settleTimeoutMs,d=(0,n.useRef)(e);d.current=e;const g=(0,n.useRef)(r);g.current=r,(0,n.useEffect)(()=>{const w=d.current.map(f=>{const v=()=>d.current.find(p=>p.name===f.name)??f;return{name:f.name,description:f.description,schema:f.schema,clearable:f.clearable,get:f.get?()=>v().get?.():void 0,set:p=>v().set(p)}}),m=l?{description:c??"What the page is currently showing.",maxResultBytes:i,get:()=>g.current?.data?.get(),isLoading:()=>g.current?.data?.isLoading?.()??!1}:void 0;return t.registerPageStateFunction(w,{functionName:s,requiresApproval:o,data:m,settleTimeoutMs:x}),()=>{t.unregisterPageStateFunction(s)}},[t,s,o,l,c,i,x,JSON.stringify(e.map(w=>({name:w.name,description:w.description,schema:w.schema,clearable:w.clearable})))])}function Mt(e){const r=B(),t=(0,n.useRef)(e);t.current=e,(0,n.useEffect)(()=>Ye.attachAutoContinueAfterNavigation(r,()=>t.current),[r])}function Tt(e={}){const r=D(),t=e.client||r;if(!t)throw new Z.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[s,o]=(0,n.useState)(()=>t.getRecentActivity());(0,n.useEffect)(()=>{o(t.getRecentActivity());const i=()=>o(t.getRecentActivity());return t.on("activity:recorded",i),()=>t.off("activity:recorded",i)},[t]);const l=(0,n.useCallback)(i=>t.recordActivity(i),[t]),c=(0,n.useCallback)(()=>{t.clearActivity(),o([])},[t]);return{entries:s,latest:s.length>0?s[s.length-1]:void 0,record:l,clear:c}}function Ft(e,r){const t=B(),s=(0,n.useId)(),o=r??s,l=(0,n.useRef)(e);l.current=e;const c=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return t.addDynamicContext(o,i),()=>{t.removeDynamicContext(o)}}return t.setContext(o,l.current),()=>{t.removeContext(o)}},[t,o,c,c?"":JSON.stringify(e)])}function Te(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var be={missing:[],complete:!1};function Pt(e){const r=B(),t=e.schema!=null,s=JSON.stringify(e.schema??null),o=e.submit,l=o?typeof o=="string"?`client:${o}`:o.via==="backend"?"backend":"handler"in o?"client:handler":`client:${o.url}`:"none",c=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>t?z.createFormCollector(e):null,[t,e.name,s,l,c,e.autoSubmit]),[x,d]=(0,n.useState)({collector:null,loading:!t,error:null});(0,n.useEffect)(()=>{if(t)return;let N=!1;return d({collector:null,loading:!0,error:null}),z.loadFormCollector(r,e).then(_=>{N||d({collector:_,loading:!1,error:null})}).catch(_=>{N||d({collector:null,loading:!1,error:_ instanceof Error?_:new Error(String(_))})}),()=>{N=!0}},[r,t,e.name,l,c,e.autoSubmit]);const g=t?i:x.collector,w=t?!1:x.loading,m=t?null:x.error;(0,n.useEffect)(()=>{if(g)return g.install(r)},[r,g]);const f=(0,n.useMemo)(()=>L.createStore({values:e.initialValues??{},submitted:!1}),[c]),v=Te(g?.store??f),p=(0,n.useMemo)(()=>g?.getStatus()??be,[v,g]),S=(0,n.useMemo)(()=>({...v,...p}),[v,p]),b=(0,n.useMemo)(()=>({name:e.name,store:f,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>f.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>be}),[e.name,f]);return{...g??b,state:S,loading:w,error:m}}exports.AgoNudge=Et;exports.AgoProvider=Qe;exports.ChatInput=Ae;exports.ChatWidget=jt;exports.DEFAULT_MESSAGE_FEEDBACK_LABELS=re;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=G.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.FEEDBACK_REASONS=L.FEEDBACK_REASONS;exports.Markdown=je;exports.Message=_e;exports.MessageFeedback=Ne;exports.SpeechToTextButton=ke;exports.__exportAll=Ve;exports.createFormCollector=z.createFormCollector;exports.createMockClient=Ze.createMockClient;exports.deriveFormStatus=z.deriveFormStatus;exports.loadFormCollector=z.loadFormCollector;exports.useAgo=ye;exports.useAgoActivity=Ce;exports.useAgoActivityLog=Tt;exports.useAgoAutoContinueAfterNavigation=Mt;exports.useAgoClient=B;exports.useAgoContext=Ft;exports.useAgoFunction=Rt;exports.useAgoNavigation=Nt;exports.useAgoPageState=It;exports.useAgoStore=Te;exports.useChat=_t;exports.useConversation=Me;exports.useFeedback=Re;exports.useFormCollector=Pt;exports.useMessages=ae;exports.useOptionalAgoClient=D;exports.useProactiveNudge=Ie;exports.useSheet=we;
package/dist/react.d.cts CHANGED
@@ -116,6 +116,8 @@ declare class AgoClient {
116
116
  private config;
117
117
  /** Conversations already warned about an empty reply (one warning each). */
118
118
  private warnedEmptyConversations;
119
+ /** Client functions the backend has accepted from a WebMCP call report. */
120
+ private declaredExternally;
119
121
  /** Whether the placeholder-mode page-data warning has already been logged. */
120
122
  private warnedPageDataPlaceholder;
121
123
  /** `readPageData` companions this SDK registered, so cleanup only removes its own. */
@@ -152,6 +154,8 @@ declare class AgoClient {
152
154
  proactive: ProactiveController | null;
153
155
  /** Removes the mirrored WebMCP tools; `null` when the bridge is off. */
154
156
  private detachWebMCP;
157
+ /** The `listPages` companion is live. */
158
+ private listPagesRegistered;
155
159
  constructor(config: AgoConfig);
156
160
  private attachWebMCPBridge;
157
161
  /**
@@ -266,6 +270,11 @@ declare class AgoClient {
266
270
  */
267
271
  rejectFunction(invocationId: string): Promise<void>;
268
272
  /* Excluded from this release type: runExternalFunction */
273
+ /**
274
+ * Best-effort analytics for one WebMCP call. No agent: the caller is someone
275
+ * else's agent and cannot be known from `execute`.
276
+ */
277
+ private reportExternalCall;
269
278
  /**
270
279
  * Get a page of conversations, newest-first. `pageSize` is capped at 100 by
271
280
  * the backend (default 50). Returns the `{ data, has_more, total }` envelope
@@ -460,14 +469,15 @@ declare class AgoClient {
460
469
  * page of an entity. Flat arguments only: nested object parameters are not
461
470
  * reliably rendered to the model, so placeholders must not be named `page`.
462
471
  *
472
+ * For a large table, `{ catalogue: "onDemand" }` moves the route descriptions
473
+ * into a read-only `listPages` companion, leaving only the page names in the
474
+ * per-message schema. Routes may carry a `section` to group that companion.
475
+ *
463
476
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
464
477
  * @param routes - Map of route names to paths, with descriptions for the LLM
478
+ * @param opts - Where the catalogue lives; `"inline"` by default
465
479
  */
466
- registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
467
- name: string;
468
- path: string;
469
- description: string;
470
- }>): void;
480
+ registerNavigationFunction(navigate: (path: string) => void, routes: NavRoute[], opts?: AgoNavigationOptions): void;
471
481
  /**
472
482
  * Unregister the navigation function and its `current-page` context provider.
473
483
  */
@@ -975,6 +985,16 @@ export declare interface AgoMessage {
975
985
  createdAt: Date;
976
986
  }
977
987
 
988
+ /**
989
+ * Where the route catalogue lives: `"inline"` (default) in `navigateToPage`'s
990
+ * description, or `"onDemand"` in a `listPages` companion's result.
991
+ */
992
+ export declare type AgoNavigationOptions = {
993
+ catalogue?: "inline";
994
+ } | {
995
+ catalogue: "onDemand";
996
+ };
997
+
978
998
  /**
979
999
  * Prebuilt proactive-nudge toast: a small, always-dismissable bubble anchored
980
1000
  * near the chat launcher. Never modal — it never blocks the page. Renders the
@@ -1148,6 +1168,8 @@ export declare interface AgoRoute {
1148
1168
  name: string;
1149
1169
  path: string;
1150
1170
  description: string;
1171
+ /** Groups this route for `catalogue: "onDemand"`. Unused otherwise. */
1172
+ section?: string;
1151
1173
  }
1152
1174
 
1153
1175
  /**
@@ -2050,6 +2072,15 @@ declare interface MockAgoClientOptions {
2050
2072
 
2051
2073
  declare type MockFn = (...args: any[]) => any;
2052
2074
 
2075
+ /** A navigable page. `path` may carry `:param` placeholders. */
2076
+ declare interface NavRoute {
2077
+ name: string;
2078
+ path: string;
2079
+ description: string;
2080
+ /** Only read under `catalogue: "onDemand"`. */
2081
+ section?: string;
2082
+ }
2083
+
2053
2084
  /**
2054
2085
  * Optional action attached to a nudge. Accepting a `functionName` action
2055
2086
  * executes the registered client function (same `FunctionRegistry` path as
@@ -2967,8 +2998,11 @@ export declare interface UseAgoFunctionOptions {
2967
2998
  * { name: "settings", path: "/settings", description: "User settings" },
2968
2999
  * ]);
2969
3000
  * ```
3001
+ *
3002
+ * For a large route table, `{ catalogue: "onDemand" }` keeps the descriptions
3003
+ * out of every message.
2970
3004
  */
2971
- export declare function useAgoNavigation(navigate: (path: string) => void, routes: AgoRoute[]): void;
3005
+ export declare function useAgoNavigation(navigate: (path: string) => void, routes: AgoRoute[], opts?: AgoNavigationOptions): void;
2972
3006
 
2973
3007
  export declare type UseAgoOptions = AgoConfig;
2974
3008