@useago/sdk 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/dist/angular.d.cts +2 -0
- package/dist/angular.d.ts +2 -0
- package/dist/{createConversationSession-lJWANT6T.cjs → createConversationSession-BuMXp0Ia.cjs} +1 -1
- package/dist/{createConversationSession-Boi0PjDU.js → createConversationSession-CCT1hCf8.js} +1 -1
- package/dist/createFormCollector-BwM7qTrp.js +276 -0
- package/dist/createFormCollector-DWzGKDwO.cjs +1 -0
- package/dist/devtools.d.cts +2 -0
- package/dist/devtools.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +2 -2
- package/dist/react.cjs +2 -2
- package/dist/react.d.cts +19 -0
- package/dist/react.d.ts +19 -0
- package/dist/react.js +42 -40
- package/dist/testing.d.cts +2 -0
- package/dist/testing.d.ts +2 -0
- package/dist/vue.d.cts +2 -0
- package/dist/vue.d.ts +2 -0
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +22 -0
- package/dist/widget.d.ts +22 -0
- package/dist/widget.js +347 -297
- package/package.json +1 -1
- package/dist/createFormCollector-BUqSA2Qw.js +0 -257
- package/dist/createFormCollector-CSG5ioym.cjs +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -591,6 +591,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
591
591
|
submit?: SubmitConfig<V>;
|
|
592
592
|
/** Pre-filled values. */
|
|
593
593
|
initialValues?: Partial<V>;
|
|
594
|
+
/**
|
|
595
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
596
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
597
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
598
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
599
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
600
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
601
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
602
|
+
*/
|
|
603
|
+
autoSubmit?: boolean;
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
/**
|
|
@@ -667,6 +677,8 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
667
677
|
schema: FormCollectorSchema;
|
|
668
678
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
669
679
|
submit?: SubmitConfig<V>;
|
|
680
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
681
|
+
autoSubmit?: boolean;
|
|
670
682
|
}
|
|
671
683
|
|
|
672
684
|
/**
|
|
@@ -685,6 +697,13 @@ export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
|
685
697
|
values: Partial<V>;
|
|
686
698
|
/** True once a submit succeeded. */
|
|
687
699
|
submitted: boolean;
|
|
700
|
+
/**
|
|
701
|
+
* The submit response, set once `submitted` is true: the resolved value of the
|
|
702
|
+
* client `handler`, the parsed JSON of a client `url` POST, or the backend
|
|
703
|
+
* relay result. Lets a UI surface a server-returned message. Undefined until
|
|
704
|
+
* a submit succeeds (and after `reset()`).
|
|
705
|
+
*/
|
|
706
|
+
submitResult?: unknown;
|
|
688
707
|
}
|
|
689
708
|
|
|
690
709
|
/** Completeness status derived from values + schema — computed on read, never stored. */
|
package/dist/react.d.ts
CHANGED
|
@@ -591,6 +591,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
591
591
|
submit?: SubmitConfig<V>;
|
|
592
592
|
/** Pre-filled values. */
|
|
593
593
|
initialValues?: Partial<V>;
|
|
594
|
+
/**
|
|
595
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
596
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
597
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
598
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
599
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
600
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
601
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
602
|
+
*/
|
|
603
|
+
autoSubmit?: boolean;
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
/**
|
|
@@ -667,6 +677,8 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
667
677
|
schema: FormCollectorSchema;
|
|
668
678
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
669
679
|
submit?: SubmitConfig<V>;
|
|
680
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
681
|
+
autoSubmit?: boolean;
|
|
670
682
|
}
|
|
671
683
|
|
|
672
684
|
/**
|
|
@@ -685,6 +697,13 @@ export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
|
685
697
|
values: Partial<V>;
|
|
686
698
|
/** True once a submit succeeded. */
|
|
687
699
|
submitted: boolean;
|
|
700
|
+
/**
|
|
701
|
+
* The submit response, set once `submitted` is true: the resolved value of the
|
|
702
|
+
* client `handler`, the parsed JSON of a client `url` POST, or the backend
|
|
703
|
+
* relay result. Lets a UI surface a server-returned message. Undefined until
|
|
704
|
+
* a submit succeeds (and after `reset()`).
|
|
705
|
+
*/
|
|
706
|
+
submitResult?: unknown;
|
|
688
707
|
}
|
|
689
708
|
|
|
690
709
|
/** Completeness status derived from values + schema — computed on read, never stored. */
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as J } from "./AgoClient-DYdIe_R4.js";
|
|
2
|
-
import { i as q, n as Me, r as z, t as H } from "./createFormCollector-
|
|
2
|
+
import { i as q, n as Me, r as z, t as H } from "./createFormCollector-BwM7qTrp.js";
|
|
3
3
|
import { t as Ee } from "./createMockClient-DwdxNwEn.js";
|
|
4
|
-
import G, { createContext as V, useCallback as E, useContext as O, useEffect as
|
|
4
|
+
import G, { createContext as V, useCallback as E, useContext as O, useEffect as S, useId as j, useMemo as F, useRef as T, useState as M, useSyncExternalStore as X } from "react";
|
|
5
5
|
import { Fragment as Y, jsx as s, jsxs as I } from "react/jsx-runtime";
|
|
6
6
|
import Q from "react-markdown";
|
|
7
7
|
import Z from "remark-gfm";
|
|
@@ -11,9 +11,9 @@ function ee(e) {
|
|
|
11
11
|
const a = new J(e);
|
|
12
12
|
return n.current = a, a;
|
|
13
13
|
}, [e?.baseUrl, e?.widgetId]);
|
|
14
|
-
return
|
|
14
|
+
return S(() => (r(!0), () => {
|
|
15
15
|
n.current?.destroy(), n.current = null;
|
|
16
|
-
}), [o]),
|
|
16
|
+
}), [o]), S(() => {
|
|
17
17
|
n.current && e && n.current.updateConfig({
|
|
18
18
|
agent: e.agent,
|
|
19
19
|
defaultAgentId: e.defaultAgentId,
|
|
@@ -38,25 +38,25 @@ function ee(e) {
|
|
|
38
38
|
}
|
|
39
39
|
var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageContext: o, ...a }) => {
|
|
40
40
|
const { client: d } = ee(t ? null : a), i = t || d;
|
|
41
|
-
return
|
|
41
|
+
return S(() => {
|
|
42
42
|
if (!(!r || r.length === 0)) {
|
|
43
43
|
for (const f of r) i.register(f);
|
|
44
44
|
return () => {
|
|
45
45
|
for (const f of r) i.unregisterFunction(f.name);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
}, [i, r]),
|
|
48
|
+
}, [i, r]), S(() => {
|
|
49
49
|
if (!n) return;
|
|
50
50
|
const f = [];
|
|
51
51
|
return import("./functions-CApuQZ2b.js").then((c) => c.n).then((c) => {
|
|
52
52
|
for (const [x, v] of Object.entries(n)) {
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
53
|
+
const k = c[x];
|
|
54
|
+
if (!k) {
|
|
55
55
|
console.warn(`[AGO] Unknown helper: "${x}"`);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
|
-
const m = v === !0 ?
|
|
59
|
-
...
|
|
58
|
+
const m = v === !0 ? k : {
|
|
59
|
+
...k,
|
|
60
60
|
handler: v
|
|
61
61
|
};
|
|
62
62
|
i.register(m), f.push(m.name);
|
|
@@ -64,7 +64,7 @@ var D = V(null), Te = ({ children: e, client: t, tools: r, helpers: n, pageConte
|
|
|
64
64
|
}), () => {
|
|
65
65
|
for (const c of f) i.unregisterFunction(c);
|
|
66
66
|
};
|
|
67
|
-
}, [i, n]),
|
|
67
|
+
}, [i, n]), S(() => {
|
|
68
68
|
o === "auto" && i.enableAutoPageContext();
|
|
69
69
|
}, [i, o]), /* @__PURE__ */ s(D.Provider, {
|
|
70
70
|
value: i,
|
|
@@ -83,17 +83,17 @@ function $({ client: e, conversationId: t } = {}) {
|
|
|
83
83
|
const r = L(), n = e || r;
|
|
84
84
|
if (!n) throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
|
|
85
85
|
const [o, a] = M([]), [d, i] = M(t), [f, c] = M(!1), [x, v] = M(null);
|
|
86
|
-
|
|
87
|
-
t && t !== d && (i(t),
|
|
86
|
+
S(() => {
|
|
87
|
+
t && t !== d && (i(t), k(t));
|
|
88
88
|
}, [t]);
|
|
89
|
-
const
|
|
89
|
+
const k = async (m) => {
|
|
90
90
|
try {
|
|
91
91
|
a(await n.getMessages(m));
|
|
92
92
|
} catch (b) {
|
|
93
93
|
v(b instanceof Error ? b : /* @__PURE__ */ new Error("Failed to load messages"));
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
return
|
|
96
|
+
return S(() => {
|
|
97
97
|
const m = (g) => {
|
|
98
98
|
d || i(g.conversationId);
|
|
99
99
|
}, b = (g) => {
|
|
@@ -197,7 +197,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
197
197
|
e
|
|
198
198
|
]), v = E((l) => {
|
|
199
199
|
l.key === "Enter" && !l.shiftKey && (l.preventDefault(), x(l));
|
|
200
|
-
}, [x]),
|
|
200
|
+
}, [x]), k = E((l) => {
|
|
201
201
|
const h = Array.from(l.target.files || []);
|
|
202
202
|
f((p) => [...p, ...h]);
|
|
203
203
|
}, []), m = E((l) => {
|
|
@@ -281,7 +281,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
281
281
|
ref: c,
|
|
282
282
|
type: "file",
|
|
283
283
|
multiple: !0,
|
|
284
|
-
onChange:
|
|
284
|
+
onChange: k,
|
|
285
285
|
style: { display: "none" }
|
|
286
286
|
})] }),
|
|
287
287
|
/* @__PURE__ */ s("textarea", {
|
|
@@ -299,7 +299,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
299
299
|
resize: "none",
|
|
300
300
|
outline: "none",
|
|
301
301
|
fontFamily: "inherit",
|
|
302
|
-
fontSize: "
|
|
302
|
+
fontSize: "16px",
|
|
303
303
|
color: "#30373e",
|
|
304
304
|
backgroundColor: "#f8f8f8",
|
|
305
305
|
transition: "border-color 0.15s"
|
|
@@ -322,7 +322,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
322
322
|
color: "#fff",
|
|
323
323
|
cursor: t || !b ? "not-allowed" : "pointer",
|
|
324
324
|
fontWeight: 500,
|
|
325
|
-
fontSize: "
|
|
325
|
+
fontSize: "16px",
|
|
326
326
|
transition: "background-color 0.15s"
|
|
327
327
|
},
|
|
328
328
|
children: "Send"
|
|
@@ -628,7 +628,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
628
628
|
backgroundColor: a ? "#03182f" : "transparent",
|
|
629
629
|
color: a ? "#fff" : "#30373e",
|
|
630
630
|
wordBreak: "break-word",
|
|
631
|
-
fontSize: "
|
|
631
|
+
fontSize: "16px",
|
|
632
632
|
lineHeight: "1.6"
|
|
633
633
|
},
|
|
634
634
|
children: e.content ? /* @__PURE__ */ s(he, { content: e.content }) : d && /* @__PURE__ */ s(be, {})
|
|
@@ -667,12 +667,12 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
667
667
|
})
|
|
668
668
|
]
|
|
669
669
|
});
|
|
670
|
-
}, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: a = !1, height: d = 500, logoUrl: i, showAgentName: f = !1, forms: c, onFollowUpClick: x, className: v = "", onMessageSent:
|
|
670
|
+
}, _e = ({ client: e, conversationId: t, title: r = "Chat", welcomeMessage: n = "Hello! How can I help you today?", placeholder: o = "Type a message...", allowFiles: a = !1, height: d = 500, logoUrl: i, showAgentName: f = !1, forms: c, onFollowUpClick: x, className: v = "", onMessageSent: k, onMessageReceived: m }) => {
|
|
671
671
|
const b = T(null), l = L(), h = e ?? l, { messages: p, isLoading: g, error: u, sendMessage: w } = $({
|
|
672
672
|
client: e,
|
|
673
673
|
conversationId: t
|
|
674
674
|
});
|
|
675
|
-
|
|
675
|
+
S(() => {
|
|
676
676
|
if (!h || !c || c.length === 0) return;
|
|
677
677
|
let y = !1;
|
|
678
678
|
const A = [];
|
|
@@ -688,9 +688,9 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
688
688
|
y.schema ?? null,
|
|
689
689
|
y.submit ?? !1,
|
|
690
690
|
y.description ?? null
|
|
691
|
-
])) : ""]),
|
|
691
|
+
])) : ""]), S(() => {
|
|
692
692
|
b.current?.scrollIntoView({ behavior: "smooth" });
|
|
693
|
-
}, [p]),
|
|
693
|
+
}, [p]), S(() => {
|
|
694
694
|
const y = p[p.length - 1];
|
|
695
695
|
y && y.role === "assistant" && y.status === "DONE" && m && m({
|
|
696
696
|
id: y.id,
|
|
@@ -698,7 +698,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
698
698
|
});
|
|
699
699
|
}, [p, m]);
|
|
700
700
|
const C = async (y, A) => {
|
|
701
|
-
|
|
701
|
+
k?.(y), await w(y, A);
|
|
702
702
|
}, _ = p[p.length - 1], B = g && _?.role === "assistant" && _.status === "IN_PROGRESS", K = x === !1 ? void 0 : x ?? ((y) => C(y));
|
|
703
703
|
return /* @__PURE__ */ I("div", {
|
|
704
704
|
className: `ago-chat-widget ${v}`,
|
|
@@ -756,7 +756,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
756
756
|
textAlign: "center",
|
|
757
757
|
color: "#6b6d6f",
|
|
758
758
|
padding: "24px 16px",
|
|
759
|
-
fontSize: "
|
|
759
|
+
fontSize: "16px",
|
|
760
760
|
lineHeight: "1.5"
|
|
761
761
|
},
|
|
762
762
|
children: n
|
|
@@ -793,7 +793,7 @@ var te = ({ onSend: e, disabled: t = !1, placeholder: r = "Type a message...", a
|
|
|
793
793
|
function we({ client: e, autoLoad: t = !0 } = {}) {
|
|
794
794
|
const r = L(), n = e || r;
|
|
795
795
|
if (!n) throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");
|
|
796
|
-
const [o, a] = M([]), [d, i] = M(null), [f, c] = M(!1), [x, v] = M(null),
|
|
796
|
+
const [o, a] = M([]), [d, i] = M(null), [f, c] = M(!1), [x, v] = M(null), k = E(async () => {
|
|
797
797
|
c(!0), v(null);
|
|
798
798
|
try {
|
|
799
799
|
a(await n.getConversations());
|
|
@@ -814,16 +814,16 @@ function we({ client: e, autoLoad: t = !0 } = {}) {
|
|
|
814
814
|
}, [n]), b = E(() => {
|
|
815
815
|
i(null);
|
|
816
816
|
}, []);
|
|
817
|
-
return
|
|
818
|
-
t &&
|
|
819
|
-
}, [t,
|
|
817
|
+
return S(() => {
|
|
818
|
+
t && k();
|
|
819
|
+
}, [t, k]), {
|
|
820
820
|
conversations: o,
|
|
821
821
|
currentConversation: d,
|
|
822
822
|
isLoading: f,
|
|
823
823
|
error: x,
|
|
824
824
|
selectConversation: m,
|
|
825
825
|
startNewConversation: b,
|
|
826
|
-
refreshConversations:
|
|
826
|
+
refreshConversations: k
|
|
827
827
|
};
|
|
828
828
|
}
|
|
829
829
|
function Pe(e = {}) {
|
|
@@ -856,7 +856,7 @@ function Le(e, t) {
|
|
|
856
856
|
name: e,
|
|
857
857
|
...t
|
|
858
858
|
} : e, i = T(d);
|
|
859
|
-
i.current = d,
|
|
859
|
+
i.current = d, S(() => {
|
|
860
860
|
const f = (c) => i.current(c);
|
|
861
861
|
return r.registerFunction(n, f, {
|
|
862
862
|
description: o,
|
|
@@ -873,7 +873,7 @@ function Le(e, t) {
|
|
|
873
873
|
}
|
|
874
874
|
function De(e, t) {
|
|
875
875
|
const r = P(), n = T(e);
|
|
876
|
-
n.current = e,
|
|
876
|
+
n.current = e, S(() => (r.registerNavigationFunction((o) => n.current(o), t), () => {
|
|
877
877
|
r.unregisterFunction("navigateToPage");
|
|
878
878
|
}), [r, t]);
|
|
879
879
|
}
|
|
@@ -881,7 +881,7 @@ function We(e, t) {
|
|
|
881
881
|
const r = P(), n = j(), o = t ?? n, a = T(e);
|
|
882
882
|
a.current = e;
|
|
883
883
|
const d = typeof e == "function";
|
|
884
|
-
|
|
884
|
+
S(() => {
|
|
885
885
|
if (typeof a.current == "function") {
|
|
886
886
|
const i = () => a.current();
|
|
887
887
|
return r.addDynamicContext(o, i), () => {
|
|
@@ -911,13 +911,14 @@ function ze(e) {
|
|
|
911
911
|
e.name,
|
|
912
912
|
n,
|
|
913
913
|
a,
|
|
914
|
-
d
|
|
914
|
+
d,
|
|
915
|
+
e.autoSubmit
|
|
915
916
|
]), [f, c] = M({
|
|
916
917
|
collector: null,
|
|
917
918
|
loading: !r,
|
|
918
919
|
error: null
|
|
919
920
|
});
|
|
920
|
-
|
|
921
|
+
S(() => {
|
|
921
922
|
if (r) return;
|
|
922
923
|
let g = !1;
|
|
923
924
|
return c({
|
|
@@ -944,10 +945,11 @@ function ze(e) {
|
|
|
944
945
|
r,
|
|
945
946
|
e.name,
|
|
946
947
|
a,
|
|
947
|
-
d
|
|
948
|
+
d,
|
|
949
|
+
e.autoSubmit
|
|
948
950
|
]);
|
|
949
|
-
const x = r ? i : f.collector, v = r ? !1 : f.loading,
|
|
950
|
-
|
|
951
|
+
const x = r ? i : f.collector, v = r ? !1 : f.loading, k = r ? null : f.error;
|
|
952
|
+
S(() => {
|
|
951
953
|
if (x)
|
|
952
954
|
return x.install(t);
|
|
953
955
|
}, [t, x]);
|
|
@@ -985,7 +987,7 @@ function ze(e) {
|
|
|
985
987
|
...x ?? p,
|
|
986
988
|
state: h,
|
|
987
989
|
loading: v,
|
|
988
|
-
error:
|
|
990
|
+
error: k
|
|
989
991
|
};
|
|
990
992
|
}
|
|
991
993
|
export {
|
package/dist/testing.d.cts
CHANGED
|
@@ -468,6 +468,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
468
468
|
schema: FormCollectorSchema;
|
|
469
469
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
470
470
|
submit?: SubmitConfig<V>;
|
|
471
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
472
|
+
autoSubmit?: boolean;
|
|
471
473
|
}
|
|
472
474
|
|
|
473
475
|
/**
|
package/dist/testing.d.ts
CHANGED
|
@@ -468,6 +468,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
468
468
|
schema: FormCollectorSchema;
|
|
469
469
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
470
470
|
submit?: SubmitConfig<V>;
|
|
471
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
472
|
+
autoSubmit?: boolean;
|
|
471
473
|
}
|
|
472
474
|
|
|
473
475
|
/**
|
package/dist/vue.d.cts
CHANGED
|
@@ -484,6 +484,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
484
484
|
schema: FormCollectorSchema;
|
|
485
485
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
486
486
|
submit?: SubmitConfig<V>;
|
|
487
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
488
|
+
autoSubmit?: boolean;
|
|
487
489
|
}
|
|
488
490
|
|
|
489
491
|
/**
|
package/dist/vue.d.ts
CHANGED
|
@@ -484,6 +484,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
484
484
|
schema: FormCollectorSchema;
|
|
485
485
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
486
486
|
submit?: SubmitConfig<V>;
|
|
487
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
488
|
+
autoSubmit?: boolean;
|
|
487
489
|
}
|
|
488
490
|
|
|
489
491
|
/**
|
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Te=require("./AgoClient--y10UXUV.cjs"),Ne=require("./createFormCollector-DWzGKDwO.cjs"),et=require("./createConversationSession-BuMXp0Ia.cjs");var tt={"&":"&","<":"<",">":">",'"':""","'":"'"};function U(o){return o.replace(/[&<>"']/g,n=>tt[n])}function Le(o){const n=o.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)?n:null}var Fe='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Q="";function B(o){const n=[],a=u=>(n.push(u),`${Q}${n.length-1}${Q}`);let t=o;return t=t.replace(/`([^`]+)`/g,(u,i)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Fe}">${U(i)}</code>`)),t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,i,f)=>{const l=Le(f);return l?a(`<img alt="${U(i)}" src="${U(l)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,i,f)=>{const l=Le(f);return l?a(`<a href="${U(l)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${B(i)}</a>`):u}),t=U(t),t=t.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),t=t.replace(new RegExp(`${Q}(\\d+)${Q}`,"g"),(u,i)=>n[Number(i)]),t}function R(o,n,a){const t=document.createElement(o);return Object.assign(t.style,n),a!==void 0&&(t.innerHTML=a),t}var ze=/^ {0,3}([-*_])( *\1){2,} *$/,He=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ue=/^ {0,3}(```+|~~~+)/,Z=/^ {0,3}>\s?/,W=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,nt=["20px","18px","16px","15px","14px","13px"],ge=o=>o.match(/^\s*/)?.[0].length??0;function ot(o){return o.trim()===""||ze.test(o)||He.test(o)||Ue.test(o)||Z.test(o)||W.test(o)}function We(o){const n=o[0].match(W),a=n[1].length,t=/\d/.test(n[2]),u=R(t?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:t?"decimal":"disc",listStylePosition:"outside"});let i=0;for(;i<o.length;){const f=o[i].match(W),l=[];for(i++;i<o.length&&ge(o[i])>a;)l.push(o[i]),i++;const p=R("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=f[3].match(/^\[([ xX])\]\s+(.*)$/);c?(p.style.listStyleType="none",p.style.marginLeft="-20px",p.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${B(c[2])}`):p.innerHTML=B(f[3]),l.filter(g=>W.test(g)).length>0&&p.appendChild(We(l.filter(g=>g.trim()!==""))),u.appendChild(p)}return u}function rt(o){const n=l=>l.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(p=>p.trim()),a=R("div",{overflowX:"auto",margin:"0 0 8px 0"}),t=R("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),i=document.createElement("tr");for(const l of n(o[0]))i.appendChild(R("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},B(l)));u.appendChild(i),t.appendChild(u);const f=document.createElement("tbody");for(const l of o.slice(2)){const p=document.createElement("tr");for(const c of n(l))p.appendChild(R("td",{border:"1px solid #dee3e8",padding:"6px 10px"},B(c)));f.appendChild(p)}return t.appendChild(f),a.appendChild(t),a}var at=o=>!!o&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);function J(o){const n=document.createDocumentFragment(),a=o.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let t=0;for(;t<
|
|
4
|
-
`)))),n.appendChild(
|
|
5
|
-
`))),n.appendChild(h);continue}if(i.includes("|")&&Je(r[t+1])){const c=[i,r[t+1]];for(t+=2;t<r.length&&r[t].includes("|")&&r[t].trim();)c.push(r[t]),t++;n.appendChild(Ze(c));continue}if(P.test(i)){const c=[],h=fe(i);for(;t<r.length&&r[t].trim()!=="";)if(P.test(r[t])||fe(r[t])>h)c.push(r[t]),t++;else break;n.appendChild(ze(c));continue}const p=[i];for(t++;t<r.length&&!Ye(r[t]);)p.push(r[t]),t++;n.appendChild(_("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>M(c)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var ue='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Ie={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color"},ge="var(--ago-brand-color, #03182f)",he="var(--ago-brand-text-color, #fff)",et="var(--ago-header-background, var(--ago-brand-color, #03182f))",Le="var(--ago-header-text-color, #e8f0fe)",j="var(--ago-panel-background, #fff)",tt="var(--ago-messages-background, #fbfbfb)",Y="var(--ago-text-color, #30373e)",nt="var(--ago-muted-text-color, #6b6d6f)",$="var(--ago-border-color, #dee3e8)",pe="var(--ago-accent-color, #1b5fc4)",ot="var(--ago-radius, 16px)",Ne="var(--ago-message-radius, 16px)";function rt(o,n){if(n)for(const r of Object.keys(Ie)){const t=n[r];t!=null&&o.style.setProperty(Ie[r],t)}}function y(o,n){Object.assign(o.style,n)}function x(o={}){const n=document.createElement("div");return y(n,o),n}var Oe="ago-chat-widget-keyframes";function at(){if(typeof document>"u"||document.getElementById(Oe))return;const o=document.createElement("style");o.id=Oe,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function it(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function st(o,n){const{title:r="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:f=500,placement:s="inline",width:p=400,defaultOpen:c=!1,logoUrl:h,showAgentName:L=!1,theme:m,loadThreads:R=!1,forms:q,onFollowUpClick:B,onMessageSent:N,onMessageReceived:me}=n;if(!n.client&&!n.config?.baseUrl)throw new ke.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const g=n.client??new ke.AgoClient(n.config),xe=it(o),z=s==="left"||s==="right",He=z&&(n.launcher??!0);let H=z?c:!0;const ee=n.persistConversation,X=ee?Ke.createConversationSession(ee===!0?{}:ee):void 0;let k=n.conversationId??X?.getLastActiveThread()??void 0,d=[],O=!1,W=null;const K=[],F=x({display:"flex",flexDirection:"column",height:z?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${$}`,borderRadius:ot,overflow:"hidden",backgroundColor:j,fontFamily:ue,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});F.className="ago-chat-widget",rt(F,m);const G=x({padding:"14px 16px",borderBottom:`1px solid ${$}`,backgroundColor:et,color:Le,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",h){const e=document.createElement("img");e.src=h,e.alt="Logo",y(e,{height:"24px",width:"auto"}),G.appendChild(e)}const te=document.createElement("h3");if(te.textContent=r,y(te,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(te),z){const e=document.createElement("button");e.type="button",e.className="ago-chat-widget__close",e.setAttribute("aria-label","Close"),e.textContent="×",y(e,{marginLeft:"auto",background:"transparent",border:"none",color:Le,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),e.addEventListener("click",()=>de()),G.appendChild(e)}const I=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:tt});I.className="ago-chat-widget__messages";const{inputRow:Fe,setDisabled:Ue,focus:ne}=lt({placeholder:u,allowFiles:i,onSend:(e,a)=>{ae(e,a)}});at(),F.append(G,I,Fe);let V=F,T,E;const oe=s==="left"?"left":"right";if(z&&(T=x({position:"fixed",top:"0",bottom:"0",[oe]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),T.className="ago-chat-widget-panel",y(F,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[oe==="left"?"borderRight":"borderLeft"]:`1px solid ${$}`}),T.appendChild(F),V=T),He){if(E=document.createElement("button"),E.type="button",E.className="ago-chat-widget-launcher",E.setAttribute("aria-label",`Open ${r}`),y(E,{position:"fixed",bottom:"20px",[oe]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:ge,color:he,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:ue}),h){const e=document.createElement("img");e.src=h,e.alt="",y(e,{width:"26px",height:"26px",objectFit:"contain"}),E.appendChild(e)}else E.appendChild(qe());E.addEventListener("click",()=>le())}xe.appendChild(V),E&&xe.appendChild(E),se();const be=B!==!1,Ce=B===!1?void 0:B??(e=>{ae(e)});function Pe(e,a){const l=e.role==="user",S=x({display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"});if(S.className=`ago-message ago-message--${e.role}`,!l&&L&&e.agent){const b=x({fontSize:"13px",fontWeight:"500",color:Y,marginBottom:"6px",padding:"0 4px"});b.className="ago-message__agent",b.textContent=e.agent.displayName||e.agent.name,S.appendChild(b)}if(!l&&e.sources&&e.sources.length>0){const b=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});b.className="ago-message__sources",e.sources.forEach((C,w)=>{const D=C.url?document.createElement("a"):document.createElement("div");C.url&&D instanceof HTMLAnchorElement&&(D.href=C.url,D.target="_blank",D.rel="noopener noreferrer"),y(D,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${$}`,borderRadius:"8px",backgroundColor:j,textDecoration:"none",color:Y,fontSize:"12px",overflow:"hidden"});const Re=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${pe}`,color:pe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Re.textContent=String(w+1);const ce=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ce.textContent=C.title,ce.title=C.title,D.append(Re,ce),b.appendChild(D)}),S.appendChild(b)}const v=x({maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?Ne:"0",backgroundColor:l?ge:"transparent",color:l?he:Y,wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(J(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(Xe()),S.appendChild(v),a&&e.followUpReplies&&e.followUpReplies.length>0){const b=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});b.className="ago-message__followups";for(const C of e.followUpReplies){const w=document.createElement("button");w.type="button",w.className="ago-message__followup-btn",w.textContent=C,w.disabled=!be,y(w,{padding:"6px 14px",fontSize:"14px",borderRadius:Ne,border:`1px solid ${$}`,backgroundColor:j,color:Y,cursor:be?"pointer":"default",transition:"border-color 0.15s"}),Ce&&w.addEventListener("click",()=>Ce(C)),w.addEventListener("mouseenter",()=>{w.style.borderColor=pe}),w.addEventListener("mouseleave",()=>{w.style.borderColor=$}),b.appendChild(w)}S.appendChild(b)}return S}function A(){if(I.replaceChildren(),d.length===0){const a=x({textAlign:"center",color:nt,padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});a.appendChild(J(t)),I.appendChild(a)}else d.forEach((a,l)=>{I.appendChild(Pe(a,l===d.length-1))});if(W){const a=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});a.textContent=W,I.appendChild(a)}I.scrollTop=I.scrollHeight;const e=d[d.length-1];Ue(O&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function We(){for(let e=d.length-1;e>=0;e--){const a=d[e];if(a.role==="assistant"&&a.status==="IN_PROGRESS")return a}}const ve=e=>{k||(k=e.conversationId)},we=e=>{const a=We();a&&(a.content+=e.content,A())},ye=e=>{const a=d.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");a>=0?d[a]=e:d.push(e),A(),ne()},Ee=e=>{const a=d.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");a>=0?d[a]=e:d.push(e),O=!1,A(),e.status==="DONE"&&me?.({id:e.id,content:e.content})},Se=e=>{W=e.error,O=!1,d=d.filter(a=>!a.id.startsWith("temp-")),A()};g.on("message:start",ve),g.on("message:chunk",we),g.on("message:answer-complete",ye),g.on("message:complete",Ee),g.on("message:error",Se);const re=[];let _e=!1;for(const e of q??[])e.schema!=null?re.push($e.createFormCollector(e).install(g)):$e.loadFormCollector(g,e).then(a=>{_e||re.push(a.install(g))}).catch(()=>{});async function ae(e,a){const l=e.trim();if(!l&&!a?.length||O)return;N?.(l),O=!0,W=null;const S=Date.now();d.push({id:`temp-user-${S}`,conversationId:k||"",content:l,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${S}`,conversationId:k||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),A();try{const v=await g.sendMessage(l,{conversationId:k,files:a});v.conversationId&&(k||(k=v.conversationId),X?.setActiveThread(v.conversationId,v.createdAt));const b=d.find(C=>C.id===`temp-user-${S}`);if(b&&(b.id=`user-${S}`,b.conversationId=v.conversationId),!d.some(C=>C.id===v.id)){const C=d.findIndex(w=>w.id===`temp-assistant-${S}`);C>=0?d[C]=v:d.push(v)}d=d.filter(C=>!C.id.startsWith("temp-")),O=!1,A(),R&&ie()}catch(v){W=v instanceof Error?v.message:"Failed to send message",O=!1,d=d.filter(b=>!b.id.startsWith("temp-")),A()}}async function ie(){try{const e=await g.getConversations();K.splice(0,K.length,...e)}catch{}return K}async function Ge(e){try{const a=(await g.getConversation(e))?.messages??[];a.length>0&&d.length===0&&(d=a,A())}catch{d.length===0&&(X?.clear(),k=void 0)}}return A(),ne(),k&&Ge(k),R&&ie(),{client:g,element:V,sendMessage:ae,...z?{open:le,close:de,toggle:je}:{},session:X,threads:K,refreshThreads:ie,destroy(){g.off("message:start",ve),g.off("message:chunk",we),g.off("message:answer-complete",ye),g.off("message:complete",Ee),g.off("message:error",Se),_e=!0,re.forEach(e=>e()),V.remove(),E?.remove(),n.client||g.destroy()}};function se(){if(!T)return;const e=s==="left"?"translateX(-100%)":"translateX(100%)";T.style.transform=H?"translateX(0)":e,T.setAttribute("aria-hidden",H?"false":"true"),E&&(E.style.display=H?"none":"flex")}function le(){H=!0,se(),ne()}function de(){H=!1,se()}function je(){H?de():le()}function qe(){const e="http://www.w3.org/2000/svg",a=document.createElementNS(e,"svg");a.setAttribute("width","26"),a.setAttribute("height","26"),a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("fill","none");const l=document.createElementNS(e,"path");return l.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),l.setAttribute("stroke","currentColor"),l.setAttribute("stroke-width","2"),l.setAttribute("stroke-linecap","round"),l.setAttribute("stroke-linejoin","round"),a.appendChild(l),a}function Xe(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let a=0;a<3;a++){const l=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${a*.2}s`});e.appendChild(l)}return e}}function lt(o){let n=[];const r=document.createElement("form");y(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${$}`,backgroundColor:j}),r.className="ago-chat-input";const t=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=o.placeholder,i.rows=1,y(i,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",fontSize:"14px",fontFamily:ue,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",y(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:ge,color:he,fontSize:"14px",fontWeight:"500",cursor:"pointer"});let s=null,p=null;o.allowFiles&&(s=document.createElement("input"),s.type="file",s.multiple=!0,y(s,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",y(p,{padding:"10px 12px",border:`1px solid ${$}`,borderRadius:"12px",backgroundColor:j,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>s?.click()),s.addEventListener("change",()=>{n=[...n,...Array.from(s?.files??[])],c()}));function c(){t.replaceChildren(),n.forEach((m,R)=>{const q=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${$}`,borderRadius:"8px",fontSize:"12px"}),B=document.createElement("span");B.textContent=m.name;const N=document.createElement("button");N.type="button",N.textContent="×",y(N,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),N.addEventListener("click",()=>{n=n.filter((me,g)=>g!==R),c()}),q.append(B,N),t.appendChild(q)})}const h=()=>{const m=i.value,R=n;return i.value="",n=[],c(),{content:m,files:R}},L=()=>{const{content:m,files:R}=h();(m.trim()||R.length>0)&&o.onSend(m.trim(),R.length>0?R:void 0)};return r.addEventListener("submit",m=>{m.preventDefault(),L()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),L())}),p&&u.appendChild(p),u.append(i,f),s&&r.appendChild(s),r.append(t,u),{inputRow:r,getValueAndClear:h,setDisabled:m=>{i.disabled=m,f.disabled=m,f.style.opacity=m?"0.6":"1",f.style.cursor=m?"not-allowed":"pointer"},focus:()=>i.focus()}}exports.mountChatWidget=st;exports.renderMarkdown=J;
|
|
3
|
+
`);let t=0;for(;t<a.length;){const i=a[t];if(i.trim()===""){t++;continue}const f=i.match(Ue);if(f){const c=f[1][0],g=[];for(t++;t<a.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[t]);)g.push(a[t]),t++;t++;const N=R("pre",{margin:"0 0 8px 0"});N.appendChild(R("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Fe,whiteSpace:"pre"},U(g.join(`
|
|
4
|
+
`)))),n.appendChild(N);continue}if(ze.test(i)){n.appendChild(R("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),t++;continue}const l=i.match(He);if(l){const c=l[1].length;n.appendChild(R(`h${c}`,{margin:"16px 0 8px 0",fontSize:nt[c-1],fontWeight:"600",lineHeight:"1.3"},B(l[2]))),t++;continue}if(Z.test(i)){const c=[];for(;t<a.length&&Z.test(a[t]);)c.push(a[t].replace(Z,"")),t++;const g=R("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});g.appendChild(J(c.join(`
|
|
5
|
+
`))),n.appendChild(g);continue}if(i.includes("|")&&at(a[t+1])){const c=[i,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;n.appendChild(rt(c));continue}if(W.test(i)){const c=[],g=ge(i);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||ge(a[t])>g)c.push(a[t]),t++;else break;n.appendChild(We(c));continue}const p=[i];for(t++;t<a.length&&!ot(a[t]);)p.push(a[t]),t++;n.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>B(c)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var me='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Oe={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color"},he="var(--ago-brand-color, #03182f)",xe="var(--ago-brand-text-color, #fff)",st="var(--ago-header-background, var(--ago-brand-color, #03182f))",De="var(--ago-header-text-color, #e8f0fe)",j="var(--ago-panel-background, #fff)",it="var(--ago-messages-background, #fbfbfb)",Y="var(--ago-text-color, #30373e)",lt="var(--ago-muted-text-color, #6b6d6f)",I="var(--ago-border-color, #dee3e8)",fe="var(--ago-accent-color, #1b5fc4)",dt="var(--ago-radius, 16px)",ue="var(--ago-message-radius, 16px)";function ct(o,n){if(n)for(const a of Object.keys(Oe)){const t=n[a];t!=null&&o.style.setProperty(Oe[a],t)}}function w(o,n){Object.assign(o.style,n)}function x(o={}){const n=document.createElement("div");return w(n,o),n}var Me="Form submitted.";function pt(o){if(typeof o=="string")return o||null;if(!o||typeof o!="object")return null;const n=o;if(typeof n.message=="string"&&n.message)return n.message;const a=n.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const t=a.message;if(typeof t=="string"&&t)return t}return null}var Be="ago-chat-widget-keyframes";function ft(){if(typeof document>"u"||document.getElementById(Be))return;const o=document.createElement("style");o.id=Be,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function ut(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function gt(o,n){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:f=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:g,showAgentName:N=!1,theme:m,loadThreads:_=!1,forms:q,formSubmittedMessage:L=Me,onFollowUpClick:$,onMessageSent:be,onMessageReceived:ee}=n;if(!n.client&&!n.config?.baseUrl)throw new Te.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const b=n.client??new Te.AgoClient(n.config),Ce=ut(o),F=l==="left"||l==="right",Pe=F&&(n.launcher??!0);let z=F?c:!0;const te=n.persistConversation,X=te?et.createConversationSession(te===!0?{}:te):void 0;let k=n.conversationId??X?.getLastActiveThread()??void 0,d=[],O=!1,P=null;const ye=[];function Ge(e){if(typeof L=="function"){const s=L(e);if(typeof s=="string"&&s)return s}const r=pt(e);return r||(typeof L=="string"?L:Me)}const K=[],H=x({display:"flex",flexDirection:"column",height:F?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${I}`,borderRadius:dt,overflow:"hidden",backgroundColor:j,fontFamily:me,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",ct(H,m);const G=x({padding:"14px 16px",borderBottom:`1px solid ${I}`,backgroundColor:st,color:De,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",g){const e=document.createElement("img");e.src=g,e.alt="Logo",w(e,{height:"24px",width:"auto"}),G.appendChild(e)}const ne=document.createElement("h3");if(ne.textContent=a,w(ne,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(ne),F){const e=document.createElement("button");e.type="button",e.className="ago-chat-widget__close",e.setAttribute("aria-label","Close"),e.textContent="×",w(e,{marginLeft:"auto",background:"transparent",border:"none",color:De,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),e.addEventListener("click",()=>ce()),G.appendChild(e)}const T=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:it});T.className="ago-chat-widget__messages";const{inputRow:je,setDisabled:qe,focus:oe}=mt({placeholder:u,allowFiles:i,onSend:(e,r)=>{se(e,r)}});ft(),H.append(G,T,je);let V=H,D,S;const re=l==="left"?"left":"right";if(F&&(D=x({position:"fixed",top:"0",bottom:"0",[re]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),D.className="ago-chat-widget-panel",w(H,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[re==="left"?"borderRight":"borderLeft"]:`1px solid ${I}`}),D.appendChild(H),V=D),Pe){if(S=document.createElement("button"),S.type="button",S.className="ago-chat-widget-launcher",S.setAttribute("aria-label",`Open ${a}`),w(S,{position:"fixed",bottom:"20px",[re]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:he,color:xe,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:me}),g){const e=document.createElement("img");e.src=g,e.alt="",w(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(Ze());S.addEventListener("click",()=>de())}Ce.appendChild(V),S&&Ce.appendChild(S),le();const ve=$!==!1,we=$===!1?void 0:$??(e=>{se(e)});function Xe(e,r){const s=e.role==="user",h=x({display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start",marginBottom:"16px"});if(h.className=`ago-message ago-message--${e.role}`,!s&&N&&e.agent){const C=x({fontSize:"13px",fontWeight:"500",color:Y,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,h.appendChild(C)}if(!s&&e.sources&&e.sources.length>0){const C=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((y,E)=>{const M=y.url?document.createElement("a"):document.createElement("div");y.url&&M instanceof HTMLAnchorElement&&(M.href=y.url,M.target="_blank",M.rel="noopener noreferrer"),w(M,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${I}`,borderRadius:"8px",backgroundColor:j,textDecoration:"none",color:Y,fontSize:"12px",overflow:"hidden"});const $e=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${fe}`,color:fe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});$e.textContent=String(E+1);const pe=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});pe.textContent=y.title,pe.title=y.title,M.append($e,pe),C.appendChild(M)}),h.appendChild(C)}const v=x({maxWidth:s?"75%":"100%",padding:s?"10px 14px":"2px 8px",borderRadius:s?ue:"0",backgroundColor:s?he:"transparent",color:s?xe:Y,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(J(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(Je()),h.appendChild(v),r&&e.followUpReplies&&e.followUpReplies.length>0){const C=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const y of e.followUpReplies){const E=document.createElement("button");E.type="button",E.className="ago-message__followup-btn",E.textContent=y,E.disabled=!ve,w(E,{padding:"6px 14px",fontSize:"14px",borderRadius:ue,border:`1px solid ${I}`,backgroundColor:j,color:Y,cursor:ve?"pointer":"default",transition:"border-color 0.15s"}),we&&E.addEventListener("click",()=>we(y)),E.addEventListener("mouseenter",()=>{E.style.borderColor=fe}),E.addEventListener("mouseleave",()=>{E.style.borderColor=I}),C.appendChild(E)}h.appendChild(C)}return h}function Ke(e){const r=x({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:ue,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});r.className="ago-form-notice",r.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),w(s,{fontWeight:"700"});const h=document.createElement("span");return h.textContent=e,r.append(s,h),r}function A(){if(T.replaceChildren(),d.length===0){const r=x({textAlign:"center",color:lt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});r.appendChild(J(t)),T.appendChild(r)}else d.forEach((r,s)=>{T.appendChild(Xe(r,s===d.length-1))});for(const r of ye)T.appendChild(Ke(r));if(P){const r=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});r.textContent=P,T.appendChild(r)}T.scrollTop=T.scrollHeight;const e=d[d.length-1];qe(O&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Ve(){for(let e=d.length-1;e>=0;e--){const r=d[e];if(r.role==="assistant"&&r.status==="IN_PROGRESS")return r}}const Ee=e=>{k||(k=e.conversationId)},Se=e=>{const r=Ve();r&&(r.content+=e.content,A())},Re=e=>{const r=d.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),A(),oe()},_e=e=>{const r=d.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),O=!1,A(),e.status==="DONE"&&ee?.({id:e.id,content:e.content})},ke=e=>{P=e.error,O=!1,d=d.filter(r=>!r.id.startsWith("temp-")),A()};b.on("message:start",Ee),b.on("message:chunk",Se),b.on("message:answer-complete",Re),b.on("message:complete",_e),b.on("message:error",ke);const ae=[];let Ae=!1;const Ie=e=>{if(Ae)return;ae.push(e.install(b));let r=e.store.get().submitted;const s=e.store.subscribe(h=>{h.submitted&&!r&&(ye.push(Ge(h.submitResult)),A()),r=h.submitted});ae.push(s)};for(const e of q??[])e.schema!=null?Ie(Ne.createFormCollector(e)):Ne.loadFormCollector(b,e).then(r=>Ie(r)).catch(()=>{});async function se(e,r){const s=e.trim();if(!s&&!r?.length||O)return;be?.(s),O=!0,P=null;const h=Date.now();d.push({id:`temp-user-${h}`,conversationId:k||"",content:s,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${h}`,conversationId:k||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),A();try{const v=await b.sendMessage(s,{conversationId:k,files:r});v.conversationId&&(k||(k=v.conversationId),X?.setActiveThread(v.conversationId,v.createdAt));const C=d.find(y=>y.id===`temp-user-${h}`);if(C&&(C.id=`user-${h}`,C.conversationId=v.conversationId),!d.some(y=>y.id===v.id)){const y=d.findIndex(E=>E.id===`temp-assistant-${h}`);y>=0?d[y]=v:d.push(v)}d=d.filter(y=>!y.id.startsWith("temp-")),O=!1,A(),_&&ie()}catch(v){P=v instanceof Error?v.message:"Failed to send message",O=!1,d=d.filter(C=>!C.id.startsWith("temp-")),A()}}async function ie(){try{const e=await b.getConversations();K.splice(0,K.length,...e)}catch{}return K}async function Qe(e){try{const r=(await b.getConversation(e))?.messages??[];r.length>0&&d.length===0&&(d=r,A())}catch{d.length===0&&(X?.clear(),k=void 0)}}return A(),oe(),k&&Qe(k),_&&ie(),{client:b,element:V,sendMessage:se,...F?{open:de,close:ce,toggle:Ye}:{},session:X,threads:K,refreshThreads:ie,destroy(){b.off("message:start",Ee),b.off("message:chunk",Se),b.off("message:answer-complete",Re),b.off("message:complete",_e),b.off("message:error",ke),Ae=!0,ae.forEach(e=>e()),V.remove(),S?.remove(),n.client||b.destroy()}};function le(){if(!D)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";D.style.transform=z?"translateX(0)":e,D.setAttribute("aria-hidden",z?"false":"true"),S&&(S.style.display=z?"none":"flex")}function de(){z=!0,le(),oe()}function ce(){z=!1,le()}function Ye(){z?ce():de()}function Ze(){const e="http://www.w3.org/2000/svg",r=document.createElementNS(e,"svg");r.setAttribute("width","26"),r.setAttribute("height","26"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none");const s=document.createElementNS(e,"path");return s.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),r.appendChild(s),r}function Je(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let r=0;r<3;r++){const s=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${r*.2}s`});e.appendChild(s)}return e}}function mt(o){let n=[];const a=document.createElement("form");w(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${I}`,backgroundColor:j}),a.className="ago-chat-input";const t=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=o.placeholder,i.rows=1,w(i,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${I}`,borderRadius:"12px",fontSize:"16px",fontFamily:me,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",w(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:he,color:xe,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;o.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,w(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",w(p,{padding:"10px 12px",border:`1px solid ${I}`,borderRadius:"12px",backgroundColor:j,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{n=[...n,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),n.forEach((m,_)=>{const q=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${I}`,borderRadius:"8px",fontSize:"12px"}),L=document.createElement("span");L.textContent=m.name;const $=document.createElement("button");$.type="button",$.textContent="×",w($,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),$.addEventListener("click",()=>{n=n.filter((be,ee)=>ee!==_),c()}),q.append(L,$),t.appendChild(q)})}const g=()=>{const m=i.value,_=n;return i.value="",n=[],c(),{content:m,files:_}},N=()=>{const{content:m,files:_}=g();(m.trim()||_.length>0)&&o.onSend(m.trim(),_.length>0?_:void 0)};return a.addEventListener("submit",m=>{m.preventDefault(),N()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),N())}),p&&u.appendChild(p),u.append(i,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:g,setDisabled:m=>{i.disabled=m,f.disabled=m,f.style.opacity=m?"0.6":"1",f.style.cursor=m?"not-allowed":"pointer"},focus:()=>i.focus()}}exports.mountChatWidget=gt;exports.renderMarkdown=J;
|
package/dist/widget.d.cts
CHANGED
|
@@ -574,6 +574,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
574
574
|
submit?: SubmitConfig<V>;
|
|
575
575
|
/** Pre-filled values. */
|
|
576
576
|
initialValues?: Partial<V>;
|
|
577
|
+
/**
|
|
578
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
579
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
580
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
581
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
582
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
583
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
584
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
585
|
+
*/
|
|
586
|
+
autoSubmit?: boolean;
|
|
577
587
|
}
|
|
578
588
|
|
|
579
589
|
/**
|
|
@@ -595,6 +605,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
595
605
|
schema: FormCollectorSchema;
|
|
596
606
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
597
607
|
submit?: SubmitConfig<V>;
|
|
608
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
609
|
+
autoSubmit?: boolean;
|
|
598
610
|
}
|
|
599
611
|
|
|
600
612
|
/**
|
|
@@ -787,6 +799,16 @@ export declare interface MountChatWidgetOptions {
|
|
|
787
799
|
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
788
800
|
*/
|
|
789
801
|
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
802
|
+
/**
|
|
803
|
+
* The confirmation notice shown in the chat once a form is submitted (auto-submit
|
|
804
|
+
* or a manual `submit_<name>`), a small success block appended below the
|
|
805
|
+
* conversation. By default the notice shows a `message` string returned by the
|
|
806
|
+
* submit response (POST body / handler result / backend relay) when present, and
|
|
807
|
+
* otherwise falls back to this string ("Form submitted." by default). Pass a
|
|
808
|
+
* function to build the text from the raw submit response yourself; return a
|
|
809
|
+
* nullish value to fall back to the default text.
|
|
810
|
+
*/
|
|
811
|
+
formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
|
|
790
812
|
/**
|
|
791
813
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
792
814
|
* reply as a new user message. Pass a handler to override, or `false` to
|
package/dist/widget.d.ts
CHANGED
|
@@ -574,6 +574,16 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
|
|
|
574
574
|
submit?: SubmitConfig<V>;
|
|
575
575
|
/** Pre-filled values. */
|
|
576
576
|
initialValues?: Partial<V>;
|
|
577
|
+
/**
|
|
578
|
+
* Submit on its own as soon as every required field is filled, without waiting
|
|
579
|
+
* for the agent or a UI button. The form submits at most once. Defaults to
|
|
580
|
+
* `true` whenever a `submit` target is set: when on, no `submit_<name>` function
|
|
581
|
+
* is exposed, the form submits itself, and the agent never confirms a submit.
|
|
582
|
+
* Pass `autoSubmit: false` to keep the manual flow (expose `submit_<name>` and
|
|
583
|
+
* submit only on an explicit call). Has no effect on a collect-only form (no
|
|
584
|
+
* `submit` target); setting it `true` there is ignored with a warning.
|
|
585
|
+
*/
|
|
586
|
+
autoSubmit?: boolean;
|
|
577
587
|
}
|
|
578
588
|
|
|
579
589
|
/**
|
|
@@ -595,6 +605,8 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
595
605
|
schema: FormCollectorSchema;
|
|
596
606
|
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
597
607
|
submit?: SubmitConfig<V>;
|
|
608
|
+
/** Server-stored default for auto-submitting once the form is complete. */
|
|
609
|
+
autoSubmit?: boolean;
|
|
598
610
|
}
|
|
599
611
|
|
|
600
612
|
/**
|
|
@@ -787,6 +799,16 @@ export declare interface MountChatWidgetOptions {
|
|
|
787
799
|
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
788
800
|
*/
|
|
789
801
|
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
802
|
+
/**
|
|
803
|
+
* The confirmation notice shown in the chat once a form is submitted (auto-submit
|
|
804
|
+
* or a manual `submit_<name>`), a small success block appended below the
|
|
805
|
+
* conversation. By default the notice shows a `message` string returned by the
|
|
806
|
+
* submit response (POST body / handler result / backend relay) when present, and
|
|
807
|
+
* otherwise falls back to this string ("Form submitted." by default). Pass a
|
|
808
|
+
* function to build the text from the raw submit response yourself; return a
|
|
809
|
+
* nullish value to fall back to the default text.
|
|
810
|
+
*/
|
|
811
|
+
formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
|
|
790
812
|
/**
|
|
791
813
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
792
814
|
* reply as a new user message. Pass a handler to override, or `false` to
|