@useago/sdk 1.0.6 → 1.0.8

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.
@@ -176,6 +176,7 @@ declare class AgoClient {
176
176
  * call it when their store updates so observers like the dev panel stay live.
177
177
  */
178
178
  notifyContextChanged(): void;
179
+ /* Excluded from this release type: emitFormEvent */
179
180
  /**
180
181
  * Enable automatic capture of the current browser page (URL + title).
181
182
  * Injected as a dynamic context entry named `browser-page`.
@@ -290,6 +291,27 @@ declare interface AgoClientEvents {
290
291
  result: unknown;
291
292
  error?: string;
292
293
  };
294
+ /**
295
+ * A form collector submitted successfully. `result` is the raw submit response
296
+ * (POST body / handler return value / backend relay result) — the third-party
297
+ * API's answer. `values` is the submitted field set, `name` the collector name.
298
+ */
299
+ "form:submitted": {
300
+ name: string;
301
+ values: Record<string, unknown>;
302
+ result: unknown;
303
+ };
304
+ /**
305
+ * A form collector submit was attempted and failed at the network/server level
306
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
307
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
308
+ * not fire this — they are returned to the caller as `{ ok: false }`.
309
+ */
310
+ "form:error": {
311
+ name: string;
312
+ values: Record<string, unknown>;
313
+ error: string;
314
+ };
293
315
  "connection:status": {
294
316
  connected: boolean;
295
317
  };
@@ -467,6 +489,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
467
489
  schema: FormCollectorSchema;
468
490
  /** Server-stored submit target, if any. Absent means collect-only. */
469
491
  submit?: SubmitConfig<V>;
492
+ /** Server-stored default for auto-submitting once the form is complete. */
493
+ autoSubmit?: boolean;
470
494
  }
471
495
 
472
496
  /**
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./AgoClient--y10UXUV.cjs"),m=require("./createFormCollector-CSG5ioym.cjs"),p=require("./createConversationSession-lJWANT6T.cjs"),w=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-Djnq-JAo.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function v(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function b(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function F(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*M(e,o,l){const a=[];let r=null,s=!1;const c=i=>{a.push(i),r?.()},f=i=>c({type:"start",data:i}),t=i=>c({type:"chunk",data:i}),u=i=>{c({type:"complete",data:i}),s=!0,r?.()},d=i=>{c({type:"error",data:i}),s=!0,r?.()},C=i=>c({type:"toolCall",data:i});e.on("message:start",f),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{s=!0,r?.()});try{for(;!s||a.length>0;)a.length>0?yield a.shift():(await new Promise(i=>{r=i}),r=null)}finally{e.off("message:start",f),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function A(e){let o,l,a,r,s,c;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,a=t.agent||t.defaultAgent,r=t.permission,s=t.email,c=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),a=a||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),s=s||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,s=s||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,r=e?.permission||r,s=e?.userEmail||s,c=e?.userJwt||c;const f=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:r,userEmail:s,userJwt:c,debug:f}:null}function k(e){const o=A(e);if(!o)throw new n.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new n.AgoClient(o)}function q(e,o){return{...e,handler:o}}exports.AgoApiError=n.AgoApiError;exports.AgoClient=n.AgoClient;exports.AgoError=n.AgoError;exports.AgoFunctionError=n.AgoFunctionError;exports.AgoNetworkError=n.AgoNetworkError;exports.AgoStreamError=n.AgoStreamError;exports.ClientContextRegistry=n.ClientContextRegistry;exports.EventEmitter=n.EventEmitter;exports.FunctionRegistry=n.FunctionRegistry;exports.SSEHandler=n.SSEHandler;exports.autoDetectConfig=A;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=k;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=m.createFormCollector;exports.createMessageStream=M;exports.createMockClient=w.createMockClient;exports.createStore=m.createStore;exports.defineFunction=h;exports.deriveFormStatus=m.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=n.isStreamNetworkError;exports.loadFormCollector=m.loadFormCollector;exports.logger=n.logger;exports.onFunctionInvoke=F;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=v;exports.onMessageStart=y;exports.onToolCall=b;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=n.validateConfig;exports.withHandler=q;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./AgoClient-B3-WGVne.cjs"),f=require("./createFormCollector-BHHEW6uX.cjs"),p=require("./createConversationSession-BwYNMZWq.cjs"),w=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-Djnq-JAo.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function F(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function v(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function M(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function q(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const a=[];let r=null,s=!1;const m=i=>{a.push(i),r?.()},c=i=>m({type:"start",data:i}),t=i=>m({type:"chunk",data:i}),u=i=>{m({type:"complete",data:i}),s=!0,r?.()},d=i=>{m({type:"error",data:i}),s=!0,r?.()},C=i=>m({type:"toolCall",data:i});e.on("message:start",c),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{s=!0,r?.()});try{for(;!s||a.length>0;)a.length>0?yield a.shift():(await new Promise(i=>{r=i}),r=null)}finally{e.off("message:start",c),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function A(e){let o,l,a,r,s,m;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,a=t.agent||t.defaultAgent,r=t.permission,s=t.email,m=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),a=a||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),s=s||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,s=s||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,r=e?.permission||r,s=e?.userEmail||s,m=e?.userJwt||m;const c=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:r,userEmail:s,userJwt:m,debug:c}:null}function T(e){const o=A(e);if(!o)throw new n.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new n.AgoClient(o)}function _(e,o){return{...e,handler:o}}exports.AgoApiError=n.AgoApiError;exports.AgoClient=n.AgoClient;exports.AgoError=n.AgoError;exports.AgoFunctionError=n.AgoFunctionError;exports.AgoNetworkError=n.AgoNetworkError;exports.AgoStreamError=n.AgoStreamError;exports.ClientContextRegistry=n.ClientContextRegistry;exports.EventEmitter=n.EventEmitter;exports.FunctionRegistry=n.FunctionRegistry;exports.SSEHandler=n.SSEHandler;exports.autoDetectConfig=A;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=T;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=k;exports.createMockClient=w.createMockClient;exports.createStore=f.createStore;exports.defineFunction=h;exports.deriveFormStatus=f.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=n.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=n.logger;exports.onFormError=M;exports.onFormSubmitted=v;exports.onFunctionInvoke=q;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=F;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=n.validateConfig;exports.withHandler=_;
package/dist/index.d.cts CHANGED
@@ -187,6 +187,7 @@ export declare class AgoClient {
187
187
  * call it when their store updates so observers like the dev panel stay live.
188
188
  */
189
189
  notifyContextChanged(): void;
190
+ /* Excluded from this release type: emitFormEvent */
190
191
  /**
191
192
  * Enable automatic capture of the current browser page (URL + title).
192
193
  * Injected as a dynamic context entry named `browser-page`.
@@ -301,6 +302,27 @@ export declare interface AgoClientEvents {
301
302
  result: unknown;
302
303
  error?: string;
303
304
  };
305
+ /**
306
+ * A form collector submitted successfully. `result` is the raw submit response
307
+ * (POST body / handler return value / backend relay result) — the third-party
308
+ * API's answer. `values` is the submitted field set, `name` the collector name.
309
+ */
310
+ "form:submitted": {
311
+ name: string;
312
+ values: Record<string, unknown>;
313
+ result: unknown;
314
+ };
315
+ /**
316
+ * A form collector submit was attempted and failed at the network/server level
317
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
318
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
319
+ * not fire this — they are returned to the caller as `{ ok: false }`.
320
+ */
321
+ "form:error": {
322
+ name: string;
323
+ values: Record<string, unknown>;
324
+ error: string;
325
+ };
304
326
  "connection:status": {
305
327
  connected: boolean;
306
328
  };
@@ -742,6 +764,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
742
764
  submit?: SubmitConfig<V>;
743
765
  /** Pre-filled values. */
744
766
  initialValues?: Partial<V>;
767
+ /**
768
+ * Submit on its own as soon as every required field is filled, without waiting
769
+ * for the agent or a UI button. The form submits at most once. Defaults to
770
+ * `true` whenever a `submit` target is set: when on, no `submit_<name>` function
771
+ * is exposed, the form submits itself, and the agent never confirms a submit.
772
+ * Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
773
+ * submit only on an explicit call). Has no effect on a collect-only form (no
774
+ * `submit` target); setting it `true` there is ignored with a warning.
775
+ */
776
+ autoSubmit?: boolean;
745
777
  }
746
778
 
747
779
  /**
@@ -897,6 +929,8 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
897
929
  schema: FormCollectorSchema;
898
930
  /** Server-stored submit target, if any. Absent means collect-only. */
899
931
  submit?: SubmitConfig<V>;
932
+ /** Server-stored default for auto-submitting once the form is complete. */
933
+ autoSubmit?: boolean;
900
934
  }
901
935
 
902
936
  /**
@@ -915,6 +949,13 @@ export declare interface FormCollectorState<V = Record<string, unknown>> {
915
949
  values: Partial<V>;
916
950
  /** True once a submit succeeded. */
917
951
  submitted: boolean;
952
+ /**
953
+ * The submit response, set once `submitted` is true: the resolved value of the
954
+ * client `handler`, the parsed JSON of a client `url` POST, or the backend
955
+ * relay result. Lets a UI surface a server-returned message. Undefined until
956
+ * a submit succeeds (and after `reset()`).
957
+ */
958
+ submitResult?: unknown;
918
959
  }
919
960
 
920
961
  /** Completeness status derived from values + schema — computed on read, never stored. */
@@ -1143,6 +1184,23 @@ export declare interface MockAgoClientOptions {
1143
1184
 
1144
1185
  declare type MockFn = (...args: any[]) => any;
1145
1186
 
1187
+ /**
1188
+ * Subscribe to failed form collector submissions (network/server failures).
1189
+ */
1190
+ export declare function onFormError(client: AgoClient, callback: (data: AgoClientEvents["form:error"]) => void): () => void;
1191
+
1192
+ /**
1193
+ * Subscribe to successful form collector submissions. `result` is the submit
1194
+ * response (the third-party API's answer). Returns an unsubscribe function.
1195
+ *
1196
+ * ```ts
1197
+ * const unsub = onFormSubmitted(client, ({ name, result }) => {
1198
+ * console.log(name, "submitted", result);
1199
+ * });
1200
+ * ```
1201
+ */
1202
+ export declare function onFormSubmitted(client: AgoClient, callback: (data: AgoClientEvents["form:submitted"]) => void): () => void;
1203
+
1146
1204
  /**
1147
1205
  * Subscribe to client function invocations.
1148
1206
  */
package/dist/index.d.ts CHANGED
@@ -187,6 +187,7 @@ export declare class AgoClient {
187
187
  * call it when their store updates so observers like the dev panel stay live.
188
188
  */
189
189
  notifyContextChanged(): void;
190
+ /* Excluded from this release type: emitFormEvent */
190
191
  /**
191
192
  * Enable automatic capture of the current browser page (URL + title).
192
193
  * Injected as a dynamic context entry named `browser-page`.
@@ -301,6 +302,27 @@ export declare interface AgoClientEvents {
301
302
  result: unknown;
302
303
  error?: string;
303
304
  };
305
+ /**
306
+ * A form collector submitted successfully. `result` is the raw submit response
307
+ * (POST body / handler return value / backend relay result) — the third-party
308
+ * API's answer. `values` is the submitted field set, `name` the collector name.
309
+ */
310
+ "form:submitted": {
311
+ name: string;
312
+ values: Record<string, unknown>;
313
+ result: unknown;
314
+ };
315
+ /**
316
+ * A form collector submit was attempted and failed at the network/server level
317
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
318
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
319
+ * not fire this — they are returned to the caller as `{ ok: false }`.
320
+ */
321
+ "form:error": {
322
+ name: string;
323
+ values: Record<string, unknown>;
324
+ error: string;
325
+ };
304
326
  "connection:status": {
305
327
  connected: boolean;
306
328
  };
@@ -742,6 +764,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
742
764
  submit?: SubmitConfig<V>;
743
765
  /** Pre-filled values. */
744
766
  initialValues?: Partial<V>;
767
+ /**
768
+ * Submit on its own as soon as every required field is filled, without waiting
769
+ * for the agent or a UI button. The form submits at most once. Defaults to
770
+ * `true` whenever a `submit` target is set: when on, no `submit_<name>` function
771
+ * is exposed, the form submits itself, and the agent never confirms a submit.
772
+ * Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
773
+ * submit only on an explicit call). Has no effect on a collect-only form (no
774
+ * `submit` target); setting it `true` there is ignored with a warning.
775
+ */
776
+ autoSubmit?: boolean;
745
777
  }
746
778
 
747
779
  /**
@@ -897,6 +929,8 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
897
929
  schema: FormCollectorSchema;
898
930
  /** Server-stored submit target, if any. Absent means collect-only. */
899
931
  submit?: SubmitConfig<V>;
932
+ /** Server-stored default for auto-submitting once the form is complete. */
933
+ autoSubmit?: boolean;
900
934
  }
901
935
 
902
936
  /**
@@ -915,6 +949,13 @@ export declare interface FormCollectorState<V = Record<string, unknown>> {
915
949
  values: Partial<V>;
916
950
  /** True once a submit succeeded. */
917
951
  submitted: boolean;
952
+ /**
953
+ * The submit response, set once `submitted` is true: the resolved value of the
954
+ * client `handler`, the parsed JSON of a client `url` POST, or the backend
955
+ * relay result. Lets a UI surface a server-returned message. Undefined until
956
+ * a submit succeeds (and after `reset()`).
957
+ */
958
+ submitResult?: unknown;
918
959
  }
919
960
 
920
961
  /** Completeness status derived from values + schema — computed on read, never stored. */
@@ -1143,6 +1184,23 @@ export declare interface MockAgoClientOptions {
1143
1184
 
1144
1185
  declare type MockFn = (...args: any[]) => any;
1145
1186
 
1187
+ /**
1188
+ * Subscribe to failed form collector submissions (network/server failures).
1189
+ */
1190
+ export declare function onFormError(client: AgoClient, callback: (data: AgoClientEvents["form:error"]) => void): () => void;
1191
+
1192
+ /**
1193
+ * Subscribe to successful form collector submissions. `result` is the submit
1194
+ * response (the third-party API's answer). Returns an unsubscribe function.
1195
+ *
1196
+ * ```ts
1197
+ * const unsub = onFormSubmitted(client, ({ name, result }) => {
1198
+ * console.log(name, "submitted", result);
1199
+ * });
1200
+ * ```
1201
+ */
1202
+ export declare function onFormSubmitted(client: AgoClient, callback: (data: AgoClientEvents["form:submitted"]) => void): () => void;
1203
+
1146
1204
  /**
1147
1205
  * Subscribe to client function invocations.
1148
1206
  */
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { a as h, c as A, d as y, f as C, i as E, l as b, m as S, o as v, p as k, r as F, s as M, t as T, u as I } from "./functions-CApuQZ2b.js";
2
- import { a as G, c as O, d as q, f as x, i as L, l as N, n as _, o as D, p as H, r as J, s as R, t as d, u as c } from "./AgoClient-DYdIe_R4.js";
3
- import { i as B, n as P, r as $, t as z } from "./createFormCollector-BUqSA2Qw.js";
4
- import { t as Q } from "./createConversationSession-Boi0PjDU.js";
1
+ import { a as h, c as A, d as y, f as C, i as E, l as b, m as S, o as v, p as F, r as M, s as k, t as T, u as I } from "./functions-CApuQZ2b.js";
2
+ import { a as G, c as O, d as q, f as x, i as L, l as N, n as _, o as D, p as H, r as J, s as R, t as d, u as c } from "./AgoClient-QcTtrN7u.js";
3
+ import { i as B, n as P, r as $, t as z } from "./createFormCollector-QyojCH_-.js";
4
+ import { t as Q } from "./createConversationSession-DrCMdwkV.js";
5
5
  import { t as W } from "./createMockClient-DwdxNwEn.js";
6
6
  import "./testing.js";
7
7
  function Y(e) {
@@ -19,81 +19,87 @@ function oe(e, o) {
19
19
  function te(e, o) {
20
20
  return e.on("message:error", o), () => e.off("message:error", o);
21
21
  }
22
- function ae(e, o) {
22
+ function re(e, o) {
23
23
  return e.on("toolCall:received", o), () => e.off("toolCall:received", o);
24
24
  }
25
- function re(e, o) {
25
+ function ne(e, o) {
26
+ return e.on("form:submitted", o), () => e.off("form:submitted", o);
27
+ }
28
+ function ae(e, o) {
29
+ return e.on("form:error", o), () => e.off("form:error", o);
30
+ }
31
+ function se(e, o) {
26
32
  return e.on("function:invoke", o), () => e.off("function:invoke", o);
27
33
  }
28
- async function* ne(e, o, g) {
29
- const r = [];
30
- let a = null, n = !1;
31
- const u = (s) => {
32
- r.push(s), a?.();
33
- }, f = (s) => u({
34
+ async function* ie(e, o, u) {
35
+ const n = [];
36
+ let r = null, a = !1;
37
+ const g = (s) => {
38
+ n.push(s), r?.();
39
+ }, f = (s) => g({
34
40
  type: "start",
35
41
  data: s
36
- }), t = (s) => u({
42
+ }), t = (s) => g({
37
43
  type: "chunk",
38
44
  data: s
39
45
  }), i = (s) => {
40
- u({
46
+ g({
41
47
  type: "complete",
42
48
  data: s
43
- }), n = !0, a?.();
44
- }, l = (s) => {
45
- u({
49
+ }), a = !0, r?.();
50
+ }, m = (s) => {
51
+ g({
46
52
  type: "error",
47
53
  data: s
48
- }), n = !0, a?.();
49
- }, m = (s) => u({
54
+ }), a = !0, r?.();
55
+ }, l = (s) => g({
50
56
  type: "toolCall",
51
57
  data: s
52
58
  });
53
- e.on("message:start", f), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error", l), e.on("toolCall:received", m), e.sendMessage(o, g).catch(() => {
54
- n = !0, a?.();
59
+ e.on("message:start", f), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(o, u).catch(() => {
60
+ a = !0, r?.();
55
61
  });
56
62
  try {
57
- for (; !n || r.length > 0; ) r.length > 0 ? yield r.shift() : (await new Promise((s) => {
58
- a = s;
59
- }), a = null);
63
+ for (; !a || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
64
+ r = s;
65
+ }), r = null);
60
66
  } finally {
61
- e.off("message:start", f), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error", l), e.off("toolCall:received", m);
67
+ e.off("message:start", f), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error", m), e.off("toolCall:received", l);
62
68
  }
63
69
  }
64
70
  function p(e) {
65
- let o, g, r, a, n, u;
71
+ let o, u, n, r, a, g;
66
72
  if (typeof window < "u" && window.AGO) {
67
73
  const t = window.AGO;
68
- o = t.basepath, g = t.widgetId, r = t.agent || t.defaultAgent, a = t.permission, n = t.email, u = t.jwt;
74
+ o = t.basepath, u = t.widgetId, n = t.agent || t.defaultAgent, r = t.permission, a = t.email, g = t.jwt;
69
75
  }
70
76
  if (typeof document < "u") {
71
77
  const t = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
72
- o = o || t("ago-base-url"), g = g || t("ago-widget-id"), r = r || t("ago-agent") || t("ago-agent-id"), a = a || t("ago-permission"), n = n || t("ago-user-email");
78
+ o = o || t("ago-base-url"), u = u || t("ago-widget-id"), n = n || t("ago-agent") || t("ago-agent-id"), r = r || t("ago-permission"), a = a || t("ago-user-email");
73
79
  }
74
80
  if (typeof document < "u") {
75
81
  const t = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
76
82
  for (const i of t)
77
- i && (o = o || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, r = r || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, a = a || i.getAttribute("data-ago-permission") || void 0, n = n || i.getAttribute("data-ago-user-email") || void 0);
83
+ i && (o = o || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, n = n || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, a = a || i.getAttribute("data-ago-user-email") || void 0);
78
84
  }
79
- o = e?.baseUrl || o, g = e?.widgetId || g, r = e?.agent || e?.defaultAgentId || r, a = e?.permission || a, n = e?.userEmail || n, u = e?.userJwt || u;
85
+ o = e?.baseUrl || o, u = e?.widgetId || u, n = e?.agent || e?.defaultAgentId || n, r = e?.permission || r, a = e?.userEmail || a, g = e?.userJwt || g;
80
86
  const f = e?.debug;
81
87
  return o ? {
82
88
  baseUrl: o,
83
- widgetId: g,
84
- agent: r,
85
- permission: a,
86
- userEmail: n,
87
- userJwt: u,
89
+ widgetId: u,
90
+ agent: n,
91
+ permission: r,
92
+ userEmail: a,
93
+ userJwt: g,
88
94
  debug: f
89
95
  } : null;
90
96
  }
91
- function se(e) {
97
+ function ue(e) {
92
98
  const o = p(e);
93
99
  if (!o) throw new c('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
94
100
  return new d(o);
95
101
  }
96
- function ie(e, o) {
102
+ function ge(e, o) {
97
103
  return {
98
104
  ...e,
99
105
  handler: o
@@ -112,35 +118,37 @@ export {
112
118
  L as SSEHandler,
113
119
  p as autoDetectConfig,
114
120
  T as copyToClipboard,
115
- se as createAgo,
121
+ ue as createAgo,
116
122
  Q as createConversationSession,
117
123
  z as createFormCollector,
118
- ne as createMessageStream,
124
+ ie as createMessageStream,
119
125
  W as createMockClient,
120
126
  B as createStore,
121
127
  Y as defineFunction,
122
128
  P as deriveFormStatus,
123
- F as getLocalStorage,
129
+ M as getLocalStorage,
124
130
  E as getUserLocation,
125
131
  h as highlightElement,
126
132
  G as isStreamNetworkError,
127
133
  $ as loadFormCollector,
128
134
  O as logger,
129
- re as onFunctionInvoke,
135
+ ae as onFormError,
136
+ ne as onFormSubmitted,
137
+ se as onFunctionInvoke,
130
138
  Z as onMessage,
131
139
  ee as onMessageChunk,
132
140
  te as onMessageError,
133
141
  oe as onMessageStart,
134
- ae as onToolCall,
142
+ re as onToolCall,
135
143
  v as openUrl,
136
- M as scrollToElement,
144
+ k as scrollToElement,
137
145
  A as setLocalStorage,
138
146
  b as setTheme,
139
147
  I as showConfirmDialog,
140
148
  y as showNotification,
141
149
  C as showToast,
142
- k as submitForm,
150
+ F as submitForm,
143
151
  S as trackEvent,
144
152
  _ as validateConfig,
145
- ie as withHandler
153
+ ge as withHandler
146
154
  };
package/dist/react.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient--y10UXUV.cjs"),M=require("./createFormCollector-CSG5ioym.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"14px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"14px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>e!==void 0||String(t).includes(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BHHEW6uX.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"16px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>e!==void 0||String(t).includes(`
2
2
  `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:X,p:Y,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[N.default],z=({content:e})=>(0,o.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const s=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),r={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:s}):(0,o.jsx)("div",{style:r,children:s})},fe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
3
3
  @keyframes ago-pulse {
4
4
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
5
5
  40% { opacity: 1; transform: scale(1); }
6
6
  }
7
- `})]}),O=({message:e,className:t="",showAgentName:s=!1,isLast:r=!1,onFollowUpClick:a})=>{const l=e.role==="user",u=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&s&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((i,p)=>(0,o.jsx)(ue,{source:i,index:p},i.id))}),(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(z,{content:e.content}):u&&(0,o.jsx)(fe,{})}),r&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((i,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(i):void 0,style:{padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:i},p))})]})},ge=({client:e,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:u=500,logoUrl:i,showAgentName:p=!1,forms:d,onFollowUpClick:h,className:C="",onMessageSent:k,onMessageReceived:m})=>{const v=(0,n.useRef)(null),c=R(),y=e??c,{messages:g,isLoading:x,error:f,sendMessage:w}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!y||!d||d.length===0)return;let b=!1;const j=[];return Promise.all(d.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(y,E))).then(E=>{if(!b)for(const U of E)j.push(U.install(y))}).catch(()=>{}),()=>{b=!0,j.forEach(E=>E())}},[y,d?JSON.stringify(d.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[g]),(0,n.useEffect)(()=>{const b=g[g.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&m&&m({id:b.id,content:b.content})},[g,m]);const S=async(b,j)=>{k?.(b),await w(b,j)},_=g[g.length-1],B=x&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=h===!1?void 0:h??(b=>S(b));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[i&&(0,o.jsx)("img",{src:i,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[g.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"},children:r}):g.map((b,j)=>(0,o.jsx)(O,{message:b,showAgentName:p,isLast:j===g.length-1,onFollowUpClick:K},b.id)),f&&(0,o.jsx)("div",{style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:v})]}),(0,o.jsx)(W,{onSend:S,disabled:B,placeholder:a,allowFiles:l})]})};function H({client:e,autoLoad:t=!0}={}){const s=R(),r=e||s;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(null),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null),k=(0,n.useCallback)(async()=>{d(!0),C(null);try{l(await r.getConversations())}catch(c){C(c instanceof Error?c:new Error("Failed to load conversations"))}finally{d(!1)}},[r]),m=(0,n.useCallback)(async c=>{d(!0),C(null);try{i(await r.getConversation(c))}catch(y){C(y instanceof Error?y:new Error("Failed to load conversation"))}finally{d(!1)}},[r]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{t&&k()},[t,k]),{conversations:a,currentConversation:u,isLoading:p,error:h,selectConversation:m,startNewConversation:v,refreshConversations:k}}function pe(e={}){const t=R(),s=e.client||t;if(!s)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:s,conversationId:e.conversationId}),a=H({client:s,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||a.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function xe(e,t){const s=A(),{name:r,description:a,parameters:l,handler:u}=typeof e=="string"?{name:e,...t}:e,i=(0,n.useRef)(u);i.current=u,(0,n.useEffect)(()=>{const p=d=>i.current(d);return s.registerFunction(r,p,{description:a,parameters:l}),()=>{s.unregisterFunction(r)}},[s,r,a,l])}function me(e,t){const s=A(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(s.registerNavigationFunction(a=>r.current(a),t),()=>{s.unregisterFunction("navigateToPage")}),[s,t])}function he(e,t){const s=A(),r=(0,n.useId)(),a=t??r,l=(0,n.useRef)(e);l.current=e;const u=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return s.addDynamicContext(a,i),()=>{s.removeDynamicContext(a)}}return s.setContext(a,l.current),()=>{s.removeContext(a)}},[s,a,u,u?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function ye(e){const t=A(),s=e.schema!=null,r=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",u=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>s?M.createFormCollector(e):null,[s,e.name,r,l,u]),[p,d]=(0,n.useState)({collector:null,loading:!s,error:null});(0,n.useEffect)(()=>{if(s)return;let x=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{x||d({collector:f,loading:!1,error:null})}).catch(f=>{x||d({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{x=!0}},[t,s,e.name,l,u]);const h=s?i:p.collector,C=s?!1:p.loading,k=s?null:p.error;(0,n.useEffect)(()=>{if(h)return h.install(t)},[t,h]);const m=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[u]),v=$(h?.store??m),c=(0,n.useMemo)(()=>h?.getStatus()??D,[v,h]),y=(0,n.useMemo)(()=>({...v,...c}),[v,c]),g=(0,n.useMemo)(()=>({name:e.name,store:m,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>m.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,m]);return{...h??g,state:y,loading:C,error:k}}exports.AgoProvider=G;exports.ChatInput=W;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=O;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=q;exports.useAgoClient=A;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=H;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=R;
7
+ `})]}),O=({message:e,className:t="",showAgentName:s=!1,isLast:r=!1,onFollowUpClick:a})=>{const l=e.role==="user",u=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&s&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((i,p)=>(0,o.jsx)(ue,{source:i,index:p},i.id))}),(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(z,{content:e.content}):u&&(0,o.jsx)(fe,{})}),r&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((i,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(i):void 0,style:{padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:i},p))})]})},ge=({client:e,conversationId:t,title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:u=500,logoUrl:i,showAgentName:p=!1,forms:d,onFollowUpClick:h,className:C="",onMessageSent:k,onMessageReceived:m})=>{const v=(0,n.useRef)(null),c=R(),y=e??c,{messages:g,isLoading:x,error:f,sendMessage:w}=L({client:e,conversationId:t});(0,n.useEffect)(()=>{if(!y||!d||d.length===0)return;let b=!1;const j=[];return Promise.all(d.map(E=>E.schema!=null?Promise.resolve(M.createFormCollector(E)):M.loadFormCollector(y,E))).then(E=>{if(!b)for(const U of E)j.push(U.install(y))}).catch(()=>{}),()=>{b=!0,j.forEach(E=>E())}},[y,d?JSON.stringify(d.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,n.useEffect)(()=>{v.current?.scrollIntoView({behavior:"smooth"})},[g]),(0,n.useEffect)(()=>{const b=g[g.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&m&&m({id:b.id,content:b.content})},[g,m]);const S=async(b,j)=>{k?.(b),await w(b,j)},_=g[g.length-1],B=x&&_?.role==="assistant"&&_.status==="IN_PROGRESS",K=h===!1?void 0:h??(b=>S(b));return(0,o.jsxs)("div",{className:`ago-chat-widget ${C}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[i&&(0,o.jsx)("img",{src:i,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:s})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[g.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:r}):g.map((b,j)=>(0,o.jsx)(O,{message:b,showAgentName:p,isLast:j===g.length-1,onFollowUpClick:K},b.id)),f&&(0,o.jsx)("div",{style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:v})]}),(0,o.jsx)(W,{onSend:S,disabled:B,placeholder:a,allowFiles:l})]})};function H({client:e,autoLoad:t=!0}={}){const s=R(),r=e||s;if(!r)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(null),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null),k=(0,n.useCallback)(async()=>{d(!0),C(null);try{l(await r.getConversations())}catch(c){C(c instanceof Error?c:new Error("Failed to load conversations"))}finally{d(!1)}},[r]),m=(0,n.useCallback)(async c=>{d(!0),C(null);try{i(await r.getConversation(c))}catch(y){C(y instanceof Error?y:new Error("Failed to load conversation"))}finally{d(!1)}},[r]),v=(0,n.useCallback)(()=>{i(null)},[]);return(0,n.useEffect)(()=>{t&&k()},[t,k]),{conversations:a,currentConversation:u,isLoading:p,error:h,selectConversation:m,startNewConversation:v,refreshConversations:k}}function pe(e={}){const t=R(),s=e.client||t;if(!s)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const r=L({client:s,conversationId:e.conversationId}),a=H({client:s,autoLoad:e.autoLoad});return{messages:r.messages,isLoading:r.isLoading,error:r.error||a.error,sendMessage:r.sendMessage,clearMessages:r.clearMessages,conversationId:r.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function xe(e,t){const s=A(),{name:r,description:a,parameters:l,handler:u}=typeof e=="string"?{name:e,...t}:e,i=(0,n.useRef)(u);i.current=u,(0,n.useEffect)(()=>{const p=d=>i.current(d);return s.registerFunction(r,p,{description:a,parameters:l}),()=>{s.unregisterFunction(r)}},[s,r,a,l])}function me(e,t){const s=A(),r=(0,n.useRef)(e);r.current=e,(0,n.useEffect)(()=>(s.registerNavigationFunction(a=>r.current(a),t),()=>{s.unregisterFunction("navigateToPage")}),[s,t])}function he(e,t){const s=A(),r=(0,n.useId)(),a=t??r,l=(0,n.useRef)(e);l.current=e;const u=typeof e=="function";(0,n.useEffect)(()=>{if(typeof l.current=="function"){const i=()=>l.current();return s.addDynamicContext(a,i),()=>{s.removeDynamicContext(a)}}return s.setContext(a,l.current),()=>{s.removeContext(a)}},[s,a,u,u?"":JSON.stringify(e)])}function $(e){return(0,n.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function ye(e){const t=A(),s=e.schema!=null,r=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",u=JSON.stringify(e.initialValues??null),i=(0,n.useMemo)(()=>s?M.createFormCollector(e):null,[s,e.name,r,l,u,e.autoSubmit]),[p,d]=(0,n.useState)({collector:null,loading:!s,error:null});(0,n.useEffect)(()=>{if(s)return;let x=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{x||d({collector:f,loading:!1,error:null})}).catch(f=>{x||d({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{x=!0}},[t,s,e.name,l,u,e.autoSubmit]);const h=s?i:p.collector,C=s?!1:p.loading,k=s?null:p.error;(0,n.useEffect)(()=>{if(h)return h.install(t)},[t,h]);const m=(0,n.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[u]),v=$(h?.store??m),c=(0,n.useMemo)(()=>h?.getStatus()??D,[v,h]),y=(0,n.useMemo)(()=>({...v,...c}),[v,c]),g=(0,n.useMemo)(()=>({name:e.name,store:m,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>m.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,m]);return{...h??g,state:y,loading:C,error:k}}exports.AgoProvider=G;exports.ChatInput=W;exports.ChatWidget=ge;exports.Markdown=z;exports.Message=O;exports.createFormCollector=M.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=q;exports.useAgoClient=A;exports.useAgoContext=he;exports.useAgoFunction=xe;exports.useAgoNavigation=me;exports.useAgoStore=$;exports.useChat=pe;exports.useConversation=H;exports.useFormCollector=ye;exports.useMessages=L;exports.useOptionalAgoClient=R;
package/dist/react.d.cts CHANGED
@@ -178,6 +178,7 @@ declare class AgoClient {
178
178
  * call it when their store updates so observers like the dev panel stay live.
179
179
  */
180
180
  notifyContextChanged(): void;
181
+ /* Excluded from this release type: emitFormEvent */
181
182
  /**
182
183
  * Enable automatic capture of the current browser page (URL + title).
183
184
  * Injected as a dynamic context entry named `browser-page`.
@@ -292,6 +293,27 @@ declare interface AgoClientEvents {
292
293
  result: unknown;
293
294
  error?: string;
294
295
  };
296
+ /**
297
+ * A form collector submitted successfully. `result` is the raw submit response
298
+ * (POST body / handler return value / backend relay result) — the third-party
299
+ * API's answer. `values` is the submitted field set, `name` the collector name.
300
+ */
301
+ "form:submitted": {
302
+ name: string;
303
+ values: Record<string, unknown>;
304
+ result: unknown;
305
+ };
306
+ /**
307
+ * A form collector submit was attempted and failed at the network/server level
308
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
309
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
310
+ * not fire this — they are returned to the caller as `{ ok: false }`.
311
+ */
312
+ "form:error": {
313
+ name: string;
314
+ values: Record<string, unknown>;
315
+ error: string;
316
+ };
295
317
  "connection:status": {
296
318
  connected: boolean;
297
319
  };
@@ -591,6 +613,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
591
613
  submit?: SubmitConfig<V>;
592
614
  /** Pre-filled values. */
593
615
  initialValues?: Partial<V>;
616
+ /**
617
+ * Submit on its own as soon as every required field is filled, without waiting
618
+ * for the agent or a UI button. The form submits at most once. Defaults to
619
+ * `true` whenever a `submit` target is set: when on, no `submit_<name>` function
620
+ * is exposed, the form submits itself, and the agent never confirms a submit.
621
+ * Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
622
+ * submit only on an explicit call). Has no effect on a collect-only form (no
623
+ * `submit` target); setting it `true` there is ignored with a warning.
624
+ */
625
+ autoSubmit?: boolean;
594
626
  }
595
627
 
596
628
  /**
@@ -667,6 +699,8 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
667
699
  schema: FormCollectorSchema;
668
700
  /** Server-stored submit target, if any. Absent means collect-only. */
669
701
  submit?: SubmitConfig<V>;
702
+ /** Server-stored default for auto-submitting once the form is complete. */
703
+ autoSubmit?: boolean;
670
704
  }
671
705
 
672
706
  /**
@@ -685,6 +719,13 @@ export declare interface FormCollectorState<V = Record<string, unknown>> {
685
719
  values: Partial<V>;
686
720
  /** True once a submit succeeded. */
687
721
  submitted: boolean;
722
+ /**
723
+ * The submit response, set once `submitted` is true: the resolved value of the
724
+ * client `handler`, the parsed JSON of a client `url` POST, or the backend
725
+ * relay result. Lets a UI surface a server-returned message. Undefined until
726
+ * a submit succeeds (and after `reset()`).
727
+ */
728
+ submitResult?: unknown;
688
729
  }
689
730
 
690
731
  /** Completeness status derived from values + schema — computed on read, never stored. */