@useago/sdk 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AgoClient-B6PsfMeg.cjs → AgoClient-D4EL6nva.cjs} +3 -3
- package/dist/{AgoClient-BerJvssl.js → AgoClient-rvTz2thR.js} +19 -14
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +15 -0
- package/dist/angular.d.ts +15 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-CLZvxyuu.js → createConversationSession-D9FesBQS.js} +1 -1
- package/dist/{createConversationSession-D3K5Gf1k.cjs → createConversationSession-DtaeA418.cjs} +1 -1
- package/dist/{createFormCollector-CD1rqRG4.js → createFormCollector-BwvkKi48.js} +32 -29
- package/dist/createFormCollector-Wb8Rr-U2.cjs +1 -0
- package/dist/{createMockClient-tVsApEAh.js → createMockClient-DwdxNwEn.js} +4 -2
- package/dist/createMockClient-zHQ0cjUH.cjs +1 -0
- package/dist/devtools.cjs +5 -4
- package/dist/devtools.d.cts +15 -0
- package/dist/devtools.d.ts +15 -0
- package/dist/devtools.js +35 -31
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +4 -4
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +15 -0
- package/dist/react.d.ts +15 -0
- package/dist/react.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +15 -0
- package/dist/vue.d.ts +15 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +50 -0
- package/dist/widget.d.ts +50 -0
- package/dist/widget.js +203 -183
- package/package.json +1 -1
- package/dist/createFormCollector-D1FfiSgA.cjs +0 -1
- package/dist/createMockClient-DMFGIOtc.cjs +0 -1
package/dist/widget.js
CHANGED
|
@@ -1,94 +1,114 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { t as ge } from "./AgoClient-rvTz2thR.js";
|
|
2
|
+
import { t as ue } from "./createFormCollector-BwvkKi48.js";
|
|
3
|
+
import { t as xe } from "./createConversationSession-D9FesBQS.js";
|
|
4
|
+
var oe = 'var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)', ee = {
|
|
5
|
+
font: "--ago-font",
|
|
6
|
+
radius: "--ago-radius",
|
|
7
|
+
brand: "--ago-brand-color",
|
|
8
|
+
brandText: "--ago-brand-text-color",
|
|
9
|
+
headerBg: "--ago-header-background",
|
|
10
|
+
headerText: "--ago-header-text-color",
|
|
11
|
+
panelBg: "--ago-panel-background",
|
|
12
|
+
messagesBg: "--ago-messages-background",
|
|
13
|
+
text: "--ago-text-color",
|
|
14
|
+
mutedText: "--ago-muted-text-color",
|
|
15
|
+
border: "--ago-border-color",
|
|
16
|
+
accent: "--ago-accent-color"
|
|
17
|
+
}, ne = "var(--ago-brand-color, #03182f)", re = "var(--ago-brand-text-color, #fff)", me = "var(--ago-header-background, var(--ago-brand-color, #03182f))", he = "var(--ago-header-text-color, #e8f0fe)", L = "var(--ago-panel-background, #fff)", be = "var(--ago-messages-background, #fbfbfb)", H = "var(--ago-text-color, #30373e)", ve = "var(--ago-muted-text-color, #6b6d6f)", E = "var(--ago-border-color, #dee3e8)", K = "var(--ago-accent-color, #1b5fc4)", X = "var(--ago-radius, 16px)";
|
|
18
|
+
function Ce(i, o) {
|
|
19
|
+
if (o)
|
|
20
|
+
for (const g of Object.keys(ee)) {
|
|
21
|
+
const w = o[g];
|
|
22
|
+
w != null && i.style.setProperty(ee[g], w);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function m(i, o) {
|
|
26
|
+
Object.assign(i.style, o);
|
|
7
27
|
}
|
|
8
|
-
function c(
|
|
9
|
-
const
|
|
10
|
-
return
|
|
28
|
+
function c(i = {}) {
|
|
29
|
+
const o = document.createElement("div");
|
|
30
|
+
return m(o, i), o;
|
|
11
31
|
}
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
if (typeof document > "u" || document.getElementById(
|
|
15
|
-
const
|
|
16
|
-
|
|
32
|
+
var te = "ago-chat-widget-keyframes";
|
|
33
|
+
function ye() {
|
|
34
|
+
if (typeof document > "u" || document.getElementById(te)) return;
|
|
35
|
+
const i = document.createElement("style");
|
|
36
|
+
i.id = te, i.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }", document.head.appendChild(i);
|
|
17
37
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
21
|
-
return
|
|
38
|
+
function Ee(i) {
|
|
39
|
+
const o = typeof i == "string" ? document.querySelector(i) : i;
|
|
40
|
+
if (!o) throw new Error(`mountChatWidget: target "${String(i)}" not found.`);
|
|
41
|
+
return o;
|
|
22
42
|
}
|
|
23
|
-
function
|
|
24
|
-
const { title:
|
|
25
|
-
if (!
|
|
26
|
-
const l =
|
|
27
|
-
let
|
|
28
|
-
const
|
|
43
|
+
function _e(i, o) {
|
|
44
|
+
const { title: g = "Chat", welcomeMessage: w = "Hello! How can I help you today?", placeholder: T = "Type a message...", allowFiles: u = !1, height: x = 500, logoUrl: f, showAgentName: v = !1, theme: A, loadThreads: D = !1, forms: B, onFollowUpClick: s, onMessageSent: C, onMessageReceived: $ } = o;
|
|
45
|
+
if (!o.client && !o.config?.baseUrl) throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");
|
|
46
|
+
const l = o.client ?? new ge(o.config), k = Ee(i), U = o.persistConversation, I = U ? xe(U === !0 ? {} : U) : void 0;
|
|
47
|
+
let h = o.conversationId ?? I?.getLastActiveThread() ?? void 0, n = [], _ = !1, N = null;
|
|
48
|
+
const M = [], O = c({
|
|
29
49
|
display: "flex",
|
|
30
50
|
flexDirection: "column",
|
|
31
|
-
height: typeof
|
|
32
|
-
border:
|
|
33
|
-
borderRadius:
|
|
51
|
+
height: typeof x == "number" ? `${x}px` : x,
|
|
52
|
+
border: `1px solid ${E}`,
|
|
53
|
+
borderRadius: X,
|
|
34
54
|
overflow: "hidden",
|
|
35
|
-
backgroundColor:
|
|
36
|
-
fontFamily:
|
|
55
|
+
backgroundColor: L,
|
|
56
|
+
fontFamily: oe,
|
|
37
57
|
boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
|
|
38
58
|
});
|
|
39
|
-
|
|
40
|
-
const
|
|
59
|
+
O.className = "ago-chat-widget", Ce(O, A);
|
|
60
|
+
const z = c({
|
|
41
61
|
padding: "14px 16px",
|
|
42
|
-
borderBottom:
|
|
43
|
-
backgroundColor:
|
|
44
|
-
color:
|
|
62
|
+
borderBottom: `1px solid ${E}`,
|
|
63
|
+
backgroundColor: me,
|
|
64
|
+
color: he,
|
|
45
65
|
display: "flex",
|
|
46
66
|
alignItems: "center",
|
|
47
67
|
gap: "10px"
|
|
48
68
|
});
|
|
49
|
-
if (
|
|
69
|
+
if (z.className = "ago-chat-widget__header", f) {
|
|
50
70
|
const e = document.createElement("img");
|
|
51
|
-
e.src = f, e.alt = "Logo",
|
|
71
|
+
e.src = f, e.alt = "Logo", m(e, {
|
|
52
72
|
height: "24px",
|
|
53
73
|
width: "auto"
|
|
54
|
-
}),
|
|
74
|
+
}), z.appendChild(e);
|
|
55
75
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
76
|
+
const W = document.createElement("h3");
|
|
77
|
+
W.textContent = g, m(W, {
|
|
58
78
|
margin: "0",
|
|
59
79
|
fontSize: "15px",
|
|
60
80
|
fontWeight: "600"
|
|
61
|
-
}),
|
|
62
|
-
const
|
|
81
|
+
}), z.appendChild(W);
|
|
82
|
+
const R = c({
|
|
63
83
|
flex: "1",
|
|
64
84
|
overflow: "auto",
|
|
65
85
|
padding: "16px",
|
|
66
|
-
backgroundColor:
|
|
86
|
+
backgroundColor: be
|
|
67
87
|
});
|
|
68
|
-
|
|
69
|
-
const { inputRow:
|
|
70
|
-
placeholder:
|
|
71
|
-
allowFiles:
|
|
88
|
+
R.className = "ago-chat-widget__messages";
|
|
89
|
+
const { inputRow: ae, setDisabled: se, focus: ie } = we({
|
|
90
|
+
placeholder: T,
|
|
91
|
+
allowFiles: u,
|
|
72
92
|
onSend: (e, t) => {
|
|
73
|
-
|
|
93
|
+
F(e, t);
|
|
74
94
|
}
|
|
75
95
|
});
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
96
|
+
ye(), O.append(z, R, ae), k.appendChild(O);
|
|
97
|
+
const j = s !== !1, V = s === !1 ? void 0 : s ?? ((e) => {
|
|
98
|
+
F(e);
|
|
79
99
|
});
|
|
80
|
-
function
|
|
100
|
+
function le(e) {
|
|
81
101
|
const t = e.role === "user", d = c({
|
|
82
102
|
display: "flex",
|
|
83
103
|
flexDirection: "column",
|
|
84
104
|
alignItems: t ? "flex-end" : "flex-start",
|
|
85
105
|
marginBottom: "16px"
|
|
86
106
|
});
|
|
87
|
-
if (d.className = `ago-message ago-message--${e.role}`, !t &&
|
|
107
|
+
if (d.className = `ago-message ago-message--${e.role}`, !t && v && e.agent) {
|
|
88
108
|
const r = c({
|
|
89
109
|
fontSize: "13px",
|
|
90
110
|
fontWeight: "500",
|
|
91
|
-
color:
|
|
111
|
+
color: H,
|
|
92
112
|
marginBottom: "6px",
|
|
93
113
|
padding: "0 4px"
|
|
94
114
|
});
|
|
@@ -104,27 +124,27 @@ function ue(s, n) {
|
|
|
104
124
|
maxWidth: "85%"
|
|
105
125
|
});
|
|
106
126
|
r.className = "ago-message__sources", e.sources.forEach((p, a) => {
|
|
107
|
-
const
|
|
108
|
-
p.url &&
|
|
127
|
+
const y = p.url ? document.createElement("a") : document.createElement("div");
|
|
128
|
+
p.url && y instanceof HTMLAnchorElement && (y.href = p.url, y.target = "_blank", y.rel = "noopener noreferrer"), m(y, {
|
|
109
129
|
display: "flex",
|
|
110
130
|
alignItems: "center",
|
|
111
131
|
gap: "8px",
|
|
112
132
|
padding: "8px 10px",
|
|
113
|
-
border:
|
|
133
|
+
border: `1px solid ${E}`,
|
|
114
134
|
borderRadius: "8px",
|
|
115
|
-
backgroundColor:
|
|
135
|
+
backgroundColor: L,
|
|
116
136
|
textDecoration: "none",
|
|
117
|
-
color:
|
|
137
|
+
color: H,
|
|
118
138
|
fontSize: "12px",
|
|
119
139
|
overflow: "hidden"
|
|
120
140
|
});
|
|
121
|
-
const
|
|
141
|
+
const Z = c({
|
|
122
142
|
flexShrink: "0",
|
|
123
143
|
width: "18px",
|
|
124
144
|
height: "18px",
|
|
125
145
|
borderRadius: "3px",
|
|
126
|
-
border:
|
|
127
|
-
color:
|
|
146
|
+
border: `1px solid ${K}`,
|
|
147
|
+
color: K,
|
|
128
148
|
fontSize: "11px",
|
|
129
149
|
fontWeight: "500",
|
|
130
150
|
display: "flex",
|
|
@@ -132,27 +152,27 @@ function ue(s, n) {
|
|
|
132
152
|
justifyContent: "center",
|
|
133
153
|
backgroundColor: "#f0f4ff"
|
|
134
154
|
});
|
|
135
|
-
|
|
136
|
-
const
|
|
155
|
+
Z.textContent = String(a + 1);
|
|
156
|
+
const P = c({
|
|
137
157
|
overflow: "hidden",
|
|
138
158
|
textOverflow: "ellipsis",
|
|
139
159
|
whiteSpace: "nowrap"
|
|
140
160
|
});
|
|
141
|
-
|
|
161
|
+
P.textContent = p.title, P.title = p.title, y.append(Z, P), r.appendChild(y);
|
|
142
162
|
}), d.appendChild(r);
|
|
143
163
|
}
|
|
144
|
-
const
|
|
164
|
+
const b = c({
|
|
145
165
|
maxWidth: t ? "75%" : "100%",
|
|
146
166
|
padding: t ? "10px 14px" : "2px 8px",
|
|
147
|
-
borderRadius: t ?
|
|
148
|
-
backgroundColor: t ?
|
|
149
|
-
color: t ?
|
|
167
|
+
borderRadius: t ? X : "0",
|
|
168
|
+
backgroundColor: t ? ne : "transparent",
|
|
169
|
+
color: t ? re : H,
|
|
150
170
|
wordBreak: "break-word",
|
|
151
171
|
fontSize: "14px",
|
|
152
172
|
lineHeight: "1.6",
|
|
153
173
|
whiteSpace: "pre-wrap"
|
|
154
174
|
});
|
|
155
|
-
if (
|
|
175
|
+
if (b.className = "ago-message__content", e.content ? b.textContent = e.content : e.status === "IN_PROGRESS" && b.appendChild(fe()), d.appendChild(b), e.followUpReplies && e.followUpReplies.length > 0) {
|
|
156
176
|
const r = c({
|
|
157
177
|
display: "flex",
|
|
158
178
|
flexWrap: "wrap",
|
|
@@ -162,19 +182,19 @@ function ue(s, n) {
|
|
|
162
182
|
r.className = "ago-message__followups";
|
|
163
183
|
for (const p of e.followUpReplies) {
|
|
164
184
|
const a = document.createElement("button");
|
|
165
|
-
a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !
|
|
185
|
+
a.type = "button", a.className = "ago-message__followup-btn", a.textContent = p, a.disabled = !j, m(a, {
|
|
166
186
|
padding: "6px 14px",
|
|
167
187
|
fontSize: "13px",
|
|
168
|
-
borderRadius:
|
|
169
|
-
border:
|
|
170
|
-
backgroundColor:
|
|
171
|
-
color:
|
|
172
|
-
cursor:
|
|
188
|
+
borderRadius: X,
|
|
189
|
+
border: `1px solid ${E}`,
|
|
190
|
+
backgroundColor: L,
|
|
191
|
+
color: H,
|
|
192
|
+
cursor: j ? "pointer" : "default",
|
|
173
193
|
transition: "border-color 0.15s"
|
|
174
|
-
}),
|
|
175
|
-
a.style.borderColor =
|
|
194
|
+
}), V && a.addEventListener("click", () => V(p)), a.addEventListener("mouseenter", () => {
|
|
195
|
+
a.style.borderColor = K;
|
|
176
196
|
}), a.addEventListener("mouseleave", () => {
|
|
177
|
-
a.style.borderColor =
|
|
197
|
+
a.style.borderColor = E;
|
|
178
198
|
}), r.appendChild(a);
|
|
179
199
|
}
|
|
180
200
|
d.appendChild(r);
|
|
@@ -182,17 +202,17 @@ function ue(s, n) {
|
|
|
182
202
|
return d;
|
|
183
203
|
}
|
|
184
204
|
function S() {
|
|
185
|
-
if (
|
|
205
|
+
if (R.replaceChildren(), n.length === 0) {
|
|
186
206
|
const e = c({
|
|
187
207
|
textAlign: "center",
|
|
188
|
-
color:
|
|
208
|
+
color: ve,
|
|
189
209
|
padding: "24px 16px",
|
|
190
210
|
fontSize: "14px",
|
|
191
211
|
lineHeight: "1.5"
|
|
192
212
|
});
|
|
193
|
-
e.textContent =
|
|
194
|
-
} else for (const e of
|
|
195
|
-
if (
|
|
213
|
+
e.textContent = w, R.appendChild(e);
|
|
214
|
+
} else for (const e of n) R.appendChild(le(e));
|
|
215
|
+
if (N) {
|
|
196
216
|
const e = c({
|
|
197
217
|
padding: "10px 14px",
|
|
198
218
|
backgroundColor: "#fef2f2",
|
|
@@ -202,47 +222,47 @@ function ue(s, n) {
|
|
|
202
222
|
fontSize: "13px",
|
|
203
223
|
border: "1px solid #fecaca"
|
|
204
224
|
});
|
|
205
|
-
e.textContent =
|
|
225
|
+
e.textContent = N, R.appendChild(e);
|
|
206
226
|
}
|
|
207
|
-
|
|
227
|
+
R.scrollTop = R.scrollHeight, se(_);
|
|
208
228
|
}
|
|
209
|
-
function
|
|
210
|
-
for (let e =
|
|
211
|
-
const t =
|
|
229
|
+
function de() {
|
|
230
|
+
for (let e = n.length - 1; e >= 0; e--) {
|
|
231
|
+
const t = n[e];
|
|
212
232
|
if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
|
|
213
233
|
}
|
|
214
234
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
},
|
|
218
|
-
const t =
|
|
235
|
+
const q = (e) => {
|
|
236
|
+
h || (h = e.conversationId);
|
|
237
|
+
}, Y = (e) => {
|
|
238
|
+
const t = de();
|
|
219
239
|
t && (t.content += e.content, S());
|
|
220
|
-
},
|
|
221
|
-
const t =
|
|
222
|
-
t >= 0 ?
|
|
240
|
+
}, J = (e) => {
|
|
241
|
+
const t = n.findIndex((d) => d.id === e.id || d.role === "assistant" && d.status === "IN_PROGRESS");
|
|
242
|
+
t >= 0 ? n[t] = e : n.push(e), _ = !1, S(), e.status === "DONE" && $?.({
|
|
223
243
|
id: e.id,
|
|
224
244
|
content: e.content
|
|
225
245
|
});
|
|
226
|
-
},
|
|
227
|
-
|
|
246
|
+
}, Q = (e) => {
|
|
247
|
+
N = e.error, _ = !1, n = n.filter((t) => !t.id.startsWith("temp-")), S();
|
|
228
248
|
};
|
|
229
|
-
l.on("message:start",
|
|
230
|
-
const
|
|
231
|
-
async function
|
|
249
|
+
l.on("message:start", q), l.on("message:chunk", Y), l.on("message:complete", J), l.on("message:error", Q);
|
|
250
|
+
const ce = (B ?? []).map((e) => ue(e).install(l));
|
|
251
|
+
async function F(e, t) {
|
|
232
252
|
const d = e.trim();
|
|
233
|
-
if (!d && !t?.length ||
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
id: `temp-user-${
|
|
238
|
-
conversationId:
|
|
253
|
+
if (!d && !t?.length || _) return;
|
|
254
|
+
C?.(d), _ = !0, N = null;
|
|
255
|
+
const b = Date.now();
|
|
256
|
+
n.push({
|
|
257
|
+
id: `temp-user-${b}`,
|
|
258
|
+
conversationId: h || "",
|
|
239
259
|
content: d,
|
|
240
260
|
role: "user",
|
|
241
261
|
status: "DONE",
|
|
242
262
|
createdAt: /* @__PURE__ */ new Date()
|
|
243
|
-
}),
|
|
244
|
-
id: `temp-assistant-${
|
|
245
|
-
conversationId:
|
|
263
|
+
}), n.push({
|
|
264
|
+
id: `temp-assistant-${b}`,
|
|
265
|
+
conversationId: h || "",
|
|
246
266
|
content: "",
|
|
247
267
|
role: "assistant",
|
|
248
268
|
status: "IN_PROGRESS",
|
|
@@ -250,48 +270,48 @@ function ue(s, n) {
|
|
|
250
270
|
}), S();
|
|
251
271
|
try {
|
|
252
272
|
const r = await l.sendMessage(d, {
|
|
253
|
-
conversationId:
|
|
273
|
+
conversationId: h,
|
|
254
274
|
files: t
|
|
255
275
|
});
|
|
256
|
-
r.conversationId && (
|
|
257
|
-
const p =
|
|
258
|
-
if (p && (p.id = `user-${
|
|
259
|
-
const a =
|
|
260
|
-
a >= 0 ?
|
|
276
|
+
r.conversationId && (h || (h = r.conversationId), I?.setActiveThread(r.conversationId, r.createdAt));
|
|
277
|
+
const p = n.find((a) => a.id === `temp-user-${b}`);
|
|
278
|
+
if (p && (p.id = `user-${b}`, p.conversationId = r.conversationId), !n.some((a) => a.id === r.id)) {
|
|
279
|
+
const a = n.findIndex((y) => y.id === `temp-assistant-${b}`);
|
|
280
|
+
a >= 0 ? n[a] = r : n.push(r);
|
|
261
281
|
}
|
|
262
|
-
|
|
282
|
+
n = n.filter((a) => !a.id.startsWith("temp-")), _ = !1, S(), D && G();
|
|
263
283
|
} catch (r) {
|
|
264
|
-
|
|
284
|
+
N = r instanceof Error ? r.message : "Failed to send message", _ = !1, n = n.filter((p) => !p.id.startsWith("temp-")), S();
|
|
265
285
|
}
|
|
266
286
|
}
|
|
267
|
-
async function
|
|
287
|
+
async function G() {
|
|
268
288
|
try {
|
|
269
289
|
const e = await l.getConversations();
|
|
270
|
-
|
|
290
|
+
M.splice(0, M.length, ...e);
|
|
271
291
|
} catch {
|
|
272
292
|
}
|
|
273
|
-
return
|
|
293
|
+
return M;
|
|
274
294
|
}
|
|
275
|
-
async function
|
|
295
|
+
async function pe(e) {
|
|
276
296
|
try {
|
|
277
297
|
const t = (await l.getConversation(e))?.messages ?? [];
|
|
278
|
-
t.length > 0 &&
|
|
298
|
+
t.length > 0 && n.length === 0 && (n = t, S());
|
|
279
299
|
} catch {
|
|
280
|
-
|
|
300
|
+
n.length === 0 && (I?.clear(), h = void 0);
|
|
281
301
|
}
|
|
282
302
|
}
|
|
283
|
-
return S(),
|
|
303
|
+
return S(), ie(), h && pe(h), D && G(), {
|
|
284
304
|
client: l,
|
|
285
|
-
element:
|
|
286
|
-
sendMessage:
|
|
287
|
-
session:
|
|
288
|
-
threads:
|
|
289
|
-
refreshThreads:
|
|
305
|
+
element: O,
|
|
306
|
+
sendMessage: F,
|
|
307
|
+
session: I,
|
|
308
|
+
threads: M,
|
|
309
|
+
refreshThreads: G,
|
|
290
310
|
destroy() {
|
|
291
|
-
l.off("message:start",
|
|
311
|
+
l.off("message:start", q), l.off("message:chunk", Y), l.off("message:complete", J), l.off("message:error", Q), ce.forEach((e) => e()), O.remove(), o.client || l.destroy();
|
|
292
312
|
}
|
|
293
313
|
};
|
|
294
|
-
function
|
|
314
|
+
function fe() {
|
|
295
315
|
const e = c({
|
|
296
316
|
display: "flex",
|
|
297
317
|
gap: "4px",
|
|
@@ -311,108 +331,108 @@ function ue(s, n) {
|
|
|
311
331
|
return e;
|
|
312
332
|
}
|
|
313
333
|
}
|
|
314
|
-
function
|
|
315
|
-
let
|
|
316
|
-
const
|
|
317
|
-
|
|
334
|
+
function we(i) {
|
|
335
|
+
let o = [];
|
|
336
|
+
const g = document.createElement("form");
|
|
337
|
+
m(g, {
|
|
318
338
|
display: "flex",
|
|
319
339
|
flexDirection: "column",
|
|
320
340
|
gap: "8px",
|
|
321
341
|
padding: "12px",
|
|
322
|
-
borderTop:
|
|
323
|
-
backgroundColor:
|
|
324
|
-
}),
|
|
325
|
-
const
|
|
342
|
+
borderTop: `1px solid ${E}`,
|
|
343
|
+
backgroundColor: L
|
|
344
|
+
}), g.className = "ago-chat-input";
|
|
345
|
+
const w = c({
|
|
326
346
|
display: "flex",
|
|
327
347
|
flexWrap: "wrap",
|
|
328
348
|
gap: "6px"
|
|
329
|
-
}),
|
|
349
|
+
}), T = c({
|
|
330
350
|
display: "flex",
|
|
331
351
|
gap: "8px",
|
|
332
352
|
alignItems: "flex-end"
|
|
333
|
-
}),
|
|
334
|
-
|
|
353
|
+
}), u = document.createElement("textarea");
|
|
354
|
+
u.placeholder = i.placeholder, u.rows = 1, m(u, {
|
|
335
355
|
flex: "1",
|
|
336
356
|
resize: "none",
|
|
337
357
|
padding: "10px 12px",
|
|
338
|
-
border:
|
|
358
|
+
border: `1px solid ${E}`,
|
|
339
359
|
borderRadius: "12px",
|
|
340
360
|
fontSize: "14px",
|
|
341
|
-
fontFamily:
|
|
361
|
+
fontFamily: oe,
|
|
342
362
|
lineHeight: "1.4",
|
|
343
363
|
maxHeight: "120px",
|
|
344
364
|
outline: "none"
|
|
345
365
|
});
|
|
346
|
-
const
|
|
347
|
-
|
|
366
|
+
const x = document.createElement("button");
|
|
367
|
+
x.type = "submit", x.textContent = "Send", m(x, {
|
|
348
368
|
padding: "10px 16px",
|
|
349
369
|
border: "none",
|
|
350
370
|
borderRadius: "12px",
|
|
351
|
-
backgroundColor:
|
|
352
|
-
color:
|
|
371
|
+
backgroundColor: ne,
|
|
372
|
+
color: re,
|
|
353
373
|
fontSize: "14px",
|
|
354
374
|
fontWeight: "500",
|
|
355
375
|
cursor: "pointer"
|
|
356
376
|
});
|
|
357
|
-
let f = null,
|
|
358
|
-
|
|
377
|
+
let f = null, v = null;
|
|
378
|
+
i.allowFiles && (f = document.createElement("input"), f.type = "file", f.multiple = !0, m(f, { display: "none" }), v = document.createElement("button"), v.type = "button", v.textContent = "📎", m(v, {
|
|
359
379
|
padding: "10px 12px",
|
|
360
|
-
border:
|
|
380
|
+
border: `1px solid ${E}`,
|
|
361
381
|
borderRadius: "12px",
|
|
362
|
-
backgroundColor:
|
|
382
|
+
backgroundColor: L,
|
|
363
383
|
cursor: "pointer",
|
|
364
384
|
fontSize: "14px"
|
|
365
|
-
}),
|
|
366
|
-
|
|
385
|
+
}), v.addEventListener("click", () => f?.click()), f.addEventListener("change", () => {
|
|
386
|
+
o = [...o, ...Array.from(f?.files ?? [])], A();
|
|
367
387
|
}));
|
|
368
|
-
function
|
|
369
|
-
|
|
370
|
-
const
|
|
388
|
+
function A() {
|
|
389
|
+
w.replaceChildren(), o.forEach((s, C) => {
|
|
390
|
+
const $ = c({
|
|
371
391
|
display: "flex",
|
|
372
392
|
alignItems: "center",
|
|
373
393
|
gap: "4px",
|
|
374
394
|
padding: "4px 8px",
|
|
375
395
|
backgroundColor: "#f0f4ff",
|
|
376
|
-
border:
|
|
396
|
+
border: `1px solid ${E}`,
|
|
377
397
|
borderRadius: "8px",
|
|
378
398
|
fontSize: "12px"
|
|
379
|
-
}),
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
399
|
+
}), l = document.createElement("span");
|
|
400
|
+
l.textContent = s.name;
|
|
401
|
+
const k = document.createElement("button");
|
|
402
|
+
k.type = "button", k.textContent = "×", m(k, {
|
|
383
403
|
border: "none",
|
|
384
404
|
background: "transparent",
|
|
385
405
|
cursor: "pointer",
|
|
386
406
|
fontSize: "14px",
|
|
387
407
|
lineHeight: "1"
|
|
388
|
-
}),
|
|
389
|
-
|
|
390
|
-
}),
|
|
408
|
+
}), k.addEventListener("click", () => {
|
|
409
|
+
o = o.filter((U, I) => I !== C), A();
|
|
410
|
+
}), $.append(l, k), w.appendChild($);
|
|
391
411
|
});
|
|
392
412
|
}
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
return
|
|
396
|
-
content:
|
|
413
|
+
const D = () => {
|
|
414
|
+
const s = u.value, C = o;
|
|
415
|
+
return u.value = "", o = [], A(), {
|
|
416
|
+
content: s,
|
|
397
417
|
files: C
|
|
398
418
|
};
|
|
399
|
-
},
|
|
400
|
-
const { content:
|
|
401
|
-
(
|
|
419
|
+
}, B = () => {
|
|
420
|
+
const { content: s, files: C } = D();
|
|
421
|
+
(s.trim() || C.length > 0) && i.onSend(s.trim(), C.length > 0 ? C : void 0);
|
|
402
422
|
};
|
|
403
|
-
return
|
|
404
|
-
|
|
405
|
-
}),
|
|
406
|
-
|
|
407
|
-
}),
|
|
408
|
-
inputRow:
|
|
409
|
-
getValueAndClear:
|
|
410
|
-
setDisabled: (
|
|
411
|
-
|
|
423
|
+
return g.addEventListener("submit", (s) => {
|
|
424
|
+
s.preventDefault(), B();
|
|
425
|
+
}), u.addEventListener("keydown", (s) => {
|
|
426
|
+
s.key === "Enter" && !s.shiftKey && (s.preventDefault(), B());
|
|
427
|
+
}), v && T.appendChild(v), T.append(u, x), f && g.appendChild(f), g.append(w, T), {
|
|
428
|
+
inputRow: g,
|
|
429
|
+
getValueAndClear: D,
|
|
430
|
+
setDisabled: (s) => {
|
|
431
|
+
u.disabled = s, x.disabled = s, x.style.opacity = s ? "0.6" : "1", x.style.cursor = s ? "not-allowed" : "pointer";
|
|
412
432
|
},
|
|
413
|
-
focus: () =>
|
|
433
|
+
focus: () => u.focus()
|
|
414
434
|
};
|
|
415
435
|
}
|
|
416
436
|
export {
|
|
417
|
-
|
|
437
|
+
_e as mountChatWidget
|
|
418
438
|
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const I=require("./AgoClient-B6PsfMeg.cjs");function P(u,r){const m=r?r.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let c=u;if(r&&m)try{const a=m.getItem(r.key);a!=null&&(c=JSON.parse(a))}catch{}const o=new Set,h=()=>o.forEach(a=>a(c));function y(){if(r&&m)try{m.setItem(r.key,JSON.stringify(c))}catch{}}return{get:()=>c,set:a=>{c=a,y(),h()},subscribe:a=>(o.add(a),()=>{o.delete(a)})}}var O=/^[a-zA-Z0-9_-]{1,40}$/;function j(u){const{name:r,description:m,schema:c}=u;if(!O.test(r))throw new Error(`Invalid form collector name "${r}": must match ${O} (it becomes the update_/submit_ function names).`);const o=typeof u.submit=="string"?u.submit?{via:"client",url:u.submit}:!1:u.submit??!1,h=c.properties??{},y=c.required??[],a=e=>e==null||e==="",b=e=>y.filter(t=>a(e[t])),v=e=>{const t={};for(const[n,s]of Object.entries(e)){const i=h[n];if(i)if(s==null)t[n]=s;else if(i.type==="number"||i.type==="integer"){const g=typeof s=="number"?s:Number(s);t[n]=Number.isNaN(g)?s:g}else i.type==="boolean"?t[n]=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:!!s:t[n]=s}return t},f=u.initialValues??{},N=b(f),l=P({values:f,missing:N,complete:N.length===0,submitted:!1}),$=e=>{const t=l.get(),n={...t.values,...e},s=b(n),i={...t,values:n,missing:s,complete:s.length===0};return l.set(i),i};let d=null;const S=async()=>{const e=l.get();if(!e.complete)return{ok:!1,missing:e.missing};if(!o)return{ok:!1,error:"No submit target configured for this form collector."};const t=e.values;try{let n;if(o.via==="client")if("handler"in o)n=await o.handler(t);else{const s=await fetch(o.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!s.ok)return{ok:!1,error:`Submit failed: HTTP ${s.status}`};n=await s.json().catch(()=>{})}else{if(!d)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};n=await d.submitFormCollector(o.destination,t)}return l.set({...l.get(),submitted:!0}),{ok:!0,result:n}}catch(n){const s=n instanceof Error?n.message:"Submit failed";return I.logger.error(`FormCollector "${r}" submit failed:`,n),{ok:!1,error:s}}},_={name:`update_${r}`,description:`Fill or update fields of the "${r}" form. ${m} Pass any subset of fields; call it repeatedly to fill the form as the user provides information. Returns the current values and which required fields are still missing.`,parameters:{...c,required:[]},handler:e=>{const t=$(v(e));return{ok:!0,values:t.values,missing:t.missing,complete:t.complete}}},p=[_];o&&p.push({name:`submit_${r}`,description:`Submit the completed "${r}" form. Only call this once every required field is collected and the user has confirmed. If fields are missing it returns them instead of submitting.`,parameters:{type:"object",properties:{}},handler:()=>S()});const E="client__",k=o?`submit_${r}`:null,T=e=>{const t=e.functionName??e.toolName;if(t)return t.startsWith(E)?t.slice(8):t},w=e=>{let t={...f},n=!1;for(const i of e){const g=T(i);g===_.name?i.arguments&&(t={...t,...v(i.arguments)}):k&&g===k&&i.status?.toLowerCase()==="done"&&(n=!0)}const s=b(t);l.set({values:t,missing:s,complete:s.length===0,submitted:n})},C=`form:${r}`,F=()=>{const e=l.get(),t=o?` When all required fields are present and the user confirms, call submit_${r}.`:"";return{name:`Form: ${r}`,description:`Conversational form the assistant is helping fill. ${m} Use update_${r} to record fields; ask the user only for what is still missing.${t}`,data:{values:e.values,missing:e.missing,complete:e.complete,submitted:e.submitted}}},q=e=>{w((e.messages??[]).flatMap(t=>t.toolCalls??[]))};return{name:r,store:l,functions:p,contextKey:C,contextProvider:F,install:e=>{d=e;for(const t of p)e.register(t);return e.addDynamicContext(C,F),e.on("conversation:loaded",q),()=>{for(const t of p)e.unregisterFunction(t.name);e.removeDynamicContext(C),e.off("conversation:loaded",q),d===e&&(d=null)}},hydrate:w,submit:S,getValues:()=>l.get().values,setValues:e=>{$(v(e))},reset:()=>{const e=b(f);l.set({values:f,missing:e,complete:e.length===0,submitted:!1})}}}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return P}});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function w(u={}){const{overrides:g={}}=u,d={id:"mock-msg-1",conversationId:"mock-conv-1",content:"Mock response",role:"assistant",status:"DONE",createdAt:new Date},l={id:"mock-conv-1",title:"Mock Conversation",lastMessageDate:new Date},t=new Map,a=[],m={sendMessage:async()=>d,getConversations:async()=>[l],getConversation:async()=>l,getMessages:async()=>[d],submitToolCallForm:async()=>{},confirmToolCall:async()=>{},rejectToolCall:async()=>{},submitFeedback:async()=>{},registerFunction:()=>{},unregisterFunction:()=>!0,getRegisteredFunctions:()=>[],getContextSnapshot:()=>null,registerNavigationFunction:()=>{},on:(e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)},off:(e,o)=>{t.get(e)?.delete(o)},once:(e,o)=>{const n=(...r)=>{t.get(e)?.delete(n),o(...r)};t.has(e)||t.set(e,new Set),t.get(e).add(n)},waitFor:(e,o)=>new Promise((n,r)=>{let i;const c=f=>{i&&clearTimeout(i),t.get(e)?.delete(c),n(f)};t.has(e)||t.set(e,new Set),t.get(e).add(c),o?.timeout&&(i=setTimeout(()=>{t.get(e)?.delete(c),r(new Error(`waitFor("${e}") timed out after ${o.timeout}ms`))},o.timeout))}),updateConfig:()=>{},destroy:()=>{t.clear()},...g},s={};for(const[e,o]of Object.entries(m))s[e]=(...n)=>(a.push({method:e,args:n}),o(...n));return s.__calls=a,s.__callsFor=e=>a.filter(o=>o.method===e),s.__emitEvent=(e,o)=>{const n=t.get(e);n&&[...n].forEach(r=>r(o))},s}Object.defineProperty(exports,"createMockClient",{enumerable:!0,get:function(){return w}});
|