@useago/sdk 1.13.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +43 -10
- package/dist/angular.d.ts +43 -10
- package/dist/angular.js +4 -4
- package/dist/autoContinue-C3UsCvT5.cjs +1 -0
- package/dist/{autoContinue-CC8K9mBU.js → autoContinue-Cb4_iEbO.js} +1 -1
- package/dist/{createConversationSession-BfJg0WyA.js → createConversationSession-D0vks-8C.js} +1 -1
- package/dist/{createConversationSession-CiOXKWl0.cjs → createConversationSession-Ri3EKIJU.cjs} +1 -1
- package/dist/{createFormCollector-DN1xjAv5.js → createFormCollector-BMN-blXs.js} +1 -1
- package/dist/{createFormCollector-DnQl77Ko.cjs → createFormCollector-BNCMIUw2.cjs} +1 -1
- package/dist/devtools.d.cts +34 -5
- package/dist/devtools.d.ts +34 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +4 -4
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +40 -6
- package/dist/react.d.ts +40 -6
- package/dist/react.js +290 -284
- package/dist/testing.d.cts +34 -5
- package/dist/testing.d.ts +34 -5
- package/dist/types-Ck3iZG0K.cjs +10 -0
- package/dist/{types-Q7t1peH-.js → types-fX-VoHfa.js} +860 -753
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +38 -7
- package/dist/vue.d.ts +38 -7
- package/dist/vue.js +57 -57
- package/dist/widget.cjs +6 -6
- package/dist/widget.d.cts +34 -5
- package/dist/widget.d.ts +34 -5
- package/dist/widget.js +136 -136
- package/llms-full.txt +37 -0
- package/package.json +1 -1
- package/dist/autoContinue-CP9pJR-V.cjs +0 -1
- package/dist/types-a7teDBnC.cjs +0 -10
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
var
|
|
3
|
-
function
|
|
1
|
+
import { a as X, i as F, n as S, r as V, t as C } from "./errors-BLfjXnLB.js";
|
|
2
|
+
var ts = 10, Y = 1e3;
|
|
3
|
+
function Ae(e) {
|
|
4
4
|
if (typeof e != "object" || e === null) return !1;
|
|
5
5
|
const t = Object.getPrototypeOf(e);
|
|
6
6
|
return t === Object.prototype || t === null;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function P(e, t) {
|
|
9
9
|
if (typeof e == "string") {
|
|
10
10
|
if (e.length <= 1e3) return e;
|
|
11
|
-
const s = e.length -
|
|
12
|
-
return e.slice(0,
|
|
11
|
+
const s = e.length - Y;
|
|
12
|
+
return e.slice(0, Y) + `…[truncated ${s} chars]`;
|
|
13
13
|
}
|
|
14
14
|
if (Array.isArray(e)) {
|
|
15
15
|
if (t.has(e)) return "…[circular]";
|
|
16
16
|
t.add(e);
|
|
17
|
-
const s = e.slice(0, 50).map((i) =>
|
|
17
|
+
const s = e.slice(0, 50).map((i) => P(i, t));
|
|
18
18
|
return e.length > 50 && s.push(`…[+${e.length - 50} more]`), t.delete(e), s;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (Ae(e)) {
|
|
21
21
|
if (t.has(e)) return "…[circular]";
|
|
22
22
|
t.add(e);
|
|
23
23
|
const s = {};
|
|
24
|
-
for (const [i,
|
|
24
|
+
for (const [i, n] of Object.entries(e)) s[i] = P(n, t);
|
|
25
25
|
return t.delete(e), s;
|
|
26
26
|
}
|
|
27
27
|
return e;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
return
|
|
29
|
+
function me(e) {
|
|
30
|
+
return P(e, /* @__PURE__ */ new WeakSet());
|
|
31
31
|
}
|
|
32
|
-
var
|
|
32
|
+
var ke = class {
|
|
33
33
|
constructor(e = 10) {
|
|
34
34
|
this.entries = [];
|
|
35
35
|
const t = Math.floor(e);
|
|
@@ -41,7 +41,7 @@ var be = class {
|
|
|
41
41
|
actor: e.actor ?? "user",
|
|
42
42
|
name: e.name,
|
|
43
43
|
summary: e.summary,
|
|
44
|
-
...e.data !== void 0 ? { data:
|
|
44
|
+
...e.data !== void 0 ? { data: me(e.data) } : {}
|
|
45
45
|
};
|
|
46
46
|
this.entries.push(t);
|
|
47
47
|
const s = this.entries.length - this.maxEntries;
|
|
@@ -57,7 +57,7 @@ var be = class {
|
|
|
57
57
|
this.entries = [];
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
function
|
|
60
|
+
function N(e) {
|
|
61
61
|
if (e == null) return null;
|
|
62
62
|
if (typeof e == "string") {
|
|
63
63
|
const t = e.trim().replace(/_/g, "-");
|
|
@@ -67,9 +67,9 @@ function $(e) {
|
|
|
67
67
|
} catch {
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
throw new
|
|
70
|
+
throw new S('Use a language tag such as "fr", "de-DE", or "pt-BR", or null to clear it. See docs/general/configuration.md#language (config_invalid_language).', "config_invalid_language");
|
|
71
71
|
}
|
|
72
|
-
var
|
|
72
|
+
var Re = class {
|
|
73
73
|
constructor(e = !1) {
|
|
74
74
|
this.enabled = e;
|
|
75
75
|
}
|
|
@@ -91,30 +91,30 @@ var Se = class {
|
|
|
91
91
|
debug(...e) {
|
|
92
92
|
this.enabled && console.debug("[AGO SDK]", ...e);
|
|
93
93
|
}
|
|
94
|
-
},
|
|
95
|
-
function
|
|
94
|
+
}, c = new Re(), Q = "ago_widget_id";
|
|
95
|
+
function O(e) {
|
|
96
96
|
return typeof DOMException < "u" && e instanceof DOMException && e.name === "AbortError" || e instanceof Error && e.name === "AbortError";
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function Te() {
|
|
99
99
|
if (typeof localStorage < "u") {
|
|
100
|
-
const t = localStorage.getItem(
|
|
100
|
+
const t = localStorage.getItem(Q);
|
|
101
101
|
if (t) return t;
|
|
102
102
|
}
|
|
103
103
|
const e = typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `ago-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
104
104
|
if (typeof localStorage < "u") try {
|
|
105
|
-
localStorage.setItem(
|
|
105
|
+
localStorage.setItem(Q, e);
|
|
106
106
|
} catch {
|
|
107
107
|
}
|
|
108
108
|
return e;
|
|
109
109
|
}
|
|
110
|
-
var
|
|
110
|
+
var Ie = class {
|
|
111
111
|
constructor(e) {
|
|
112
|
-
this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.headers = { "X-User-Anon-Id": e.widgetId ||
|
|
113
|
-
const t =
|
|
112
|
+
this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.headers = { "X-User-Anon-Id": e.widgetId || Te() }, e.userEmail && (this.headers["X-User-Email"] = e.userEmail), e.userJwt && (this.headers.Authorization = `Bearer ${e.userJwt}`), e.permission && (this.headers["X-Widget-Permission"] = e.permission);
|
|
113
|
+
const t = N(e.language);
|
|
114
114
|
t && (this.headers["Accept-Language"] = t);
|
|
115
115
|
}
|
|
116
116
|
updateConfig(e) {
|
|
117
|
-
const t =
|
|
117
|
+
const t = N(e.language);
|
|
118
118
|
e.baseUrl && (this.baseUrl = e.baseUrl.replace(/\/$/, "")), e.widgetId && (this.headers["X-User-Anon-Id"] = e.widgetId), e.userEmail && (this.headers["X-User-Email"] = e.userEmail), e.userJwt && (this.headers.Authorization = `Bearer ${e.userJwt}`), e.permission !== void 0 && (e.permission ? this.headers["X-Widget-Permission"] = e.permission : delete this.headers["X-Widget-Permission"]), e.language !== void 0 && (t ? this.headers["Accept-Language"] = t : delete this.headers["Accept-Language"]);
|
|
119
119
|
}
|
|
120
120
|
async get(e) {
|
|
@@ -125,9 +125,9 @@ var _e = class {
|
|
|
125
125
|
}
|
|
126
126
|
async postStream(e, t, s) {
|
|
127
127
|
const i = `${this.baseUrl}${e}`;
|
|
128
|
-
|
|
128
|
+
c.debug("POST (stream)", i, t);
|
|
129
129
|
try {
|
|
130
|
-
const
|
|
130
|
+
const n = await fetch(i, {
|
|
131
131
|
method: "POST",
|
|
132
132
|
headers: {
|
|
133
133
|
...this.headers,
|
|
@@ -136,32 +136,32 @@ var _e = class {
|
|
|
136
136
|
body: t ? JSON.stringify(t) : void 0,
|
|
137
137
|
signal: s?.signal
|
|
138
138
|
});
|
|
139
|
-
return
|
|
140
|
-
} catch (
|
|
141
|
-
throw
|
|
139
|
+
return n.ok || await this.handleErrorResponse(n), n;
|
|
140
|
+
} catch (n) {
|
|
141
|
+
throw n instanceof C || O(n) ? n : new F(`Network error: ${n instanceof Error ? n.message : "Unknown error"}. Check that \`baseUrl\` is reachable and includes the protocol (https://).`, n instanceof Error ? n : void 0);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
async postFormData(e, t, s) {
|
|
145
145
|
const i = `${this.baseUrl}${e}`;
|
|
146
|
-
|
|
147
|
-
const
|
|
146
|
+
c.debug("POST (formData)", i);
|
|
147
|
+
const n = { ...this.headers };
|
|
148
148
|
try {
|
|
149
|
-
const
|
|
149
|
+
const r = await fetch(i, {
|
|
150
150
|
method: "POST",
|
|
151
|
-
headers:
|
|
151
|
+
headers: n,
|
|
152
152
|
body: t,
|
|
153
153
|
signal: s?.signal
|
|
154
154
|
});
|
|
155
|
-
return
|
|
156
|
-
} catch (
|
|
157
|
-
throw
|
|
155
|
+
return r.ok || await this.handleErrorResponse(r), r;
|
|
156
|
+
} catch (r) {
|
|
157
|
+
throw r instanceof C || O(r) ? r : new F(`Network error: ${r instanceof Error ? r.message : "Unknown error"}. Check that \`baseUrl\` is reachable and includes the protocol (https://).`, r instanceof Error ? r : void 0);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
async request(e, t, s, i) {
|
|
161
|
-
const
|
|
162
|
-
|
|
161
|
+
const n = `${this.baseUrl}${t}`;
|
|
162
|
+
c.debug(e, n, s);
|
|
163
163
|
try {
|
|
164
|
-
const
|
|
164
|
+
const r = await fetch(n, {
|
|
165
165
|
method: e,
|
|
166
166
|
headers: {
|
|
167
167
|
...this.headers,
|
|
@@ -170,9 +170,9 @@ var _e = class {
|
|
|
170
170
|
body: s ? JSON.stringify(s) : void 0,
|
|
171
171
|
...i?.keepalive ? { keepalive: !0 } : {}
|
|
172
172
|
});
|
|
173
|
-
return
|
|
174
|
-
} catch (
|
|
175
|
-
throw
|
|
173
|
+
return r.ok || await this.handleErrorResponse(r), r.status === 204 ? void 0 : r.json();
|
|
174
|
+
} catch (r) {
|
|
175
|
+
throw r instanceof C ? r : new F(`Network error: ${r instanceof Error ? r.message : "Unknown error"}. Check that \`baseUrl\` is reachable and includes the protocol (https://).`, r instanceof Error ? r : void 0);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
async handleErrorResponse(e) {
|
|
@@ -181,39 +181,39 @@ var _e = class {
|
|
|
181
181
|
t = await e.json();
|
|
182
182
|
} catch {
|
|
183
183
|
}
|
|
184
|
-
if (t?.error) throw
|
|
184
|
+
if (t?.error) throw C.fromResponse(t, e.status);
|
|
185
185
|
let s = "";
|
|
186
|
-
throw e.status === 401 || e.status === 403 ? s = " Check `userJwt` (and that it has not expired)." : e.status === 404 && (s = " Check that `baseUrl` points at your AGO API root."), new
|
|
186
|
+
throw e.status === 401 || e.status === 403 ? s = " Check `userJwt` (and that it has not expired)." : e.status === 404 && (s = " Check that `baseUrl` points at your AGO API root."), new C(`HTTP ${e.status}: ${e.statusText}.${s}`, "http_error", e.status, "api_error");
|
|
187
187
|
}
|
|
188
|
-
},
|
|
189
|
-
var
|
|
190
|
-
function
|
|
188
|
+
}, ss = 10, is = 6e5;
|
|
189
|
+
var xe = "[AGO SDK]", Fe = 300;
|
|
190
|
+
function L(e, t) {
|
|
191
191
|
return e.length <= t ? e : e.slice(0, t) + `…[truncated ${e.length - t} chars]`;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function De(e) {
|
|
194
194
|
const t = e.search(/[?#]/);
|
|
195
195
|
return t === -1 ? e : e.slice(0, t);
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function K(e) {
|
|
198
198
|
return typeof e == "object" && e !== null && typeof e.message == "string";
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function pe(e) {
|
|
201
201
|
if (typeof e == "string") return e;
|
|
202
|
-
if (
|
|
202
|
+
if (K(e)) return (typeof e.name == "string" && e.name ? `${e.name}: ` : "") + e.message;
|
|
203
203
|
if (typeof e == "object" && e !== null) try {
|
|
204
|
-
return
|
|
204
|
+
return L(JSON.stringify(e), Fe);
|
|
205
205
|
} catch {
|
|
206
206
|
return String(e);
|
|
207
207
|
}
|
|
208
208
|
return String(e);
|
|
209
209
|
}
|
|
210
|
-
function
|
|
211
|
-
return
|
|
210
|
+
function D(e) {
|
|
211
|
+
return K(e) ? {
|
|
212
212
|
message: (typeof e.name == "string" && e.name && e.name !== "Error" ? `${e.name}: ` : "") + e.message,
|
|
213
213
|
stack: typeof e.stack == "string" ? e.stack : void 0
|
|
214
|
-
} : { message:
|
|
214
|
+
} : { message: pe(e) };
|
|
215
215
|
}
|
|
216
|
-
var
|
|
216
|
+
var $e = class {
|
|
217
217
|
constructor(e = {}) {
|
|
218
218
|
this.started = !1, this.teardowns = [], this.errors = [], this.listeners = /* @__PURE__ */ new Set(), this.capturing = !1;
|
|
219
219
|
const t = Math.floor(e.maxErrors ?? 10);
|
|
@@ -225,19 +225,19 @@ var Te = class {
|
|
|
225
225
|
const e = (s) => this.onErrorEvent(s);
|
|
226
226
|
window.addEventListener("error", e), this.teardowns.push(() => window.removeEventListener("error", e));
|
|
227
227
|
const t = (s) => this.onRejectionEvent(s);
|
|
228
|
-
window.addEventListener("unhandledrejection", t), this.teardowns.push(() => window.removeEventListener("unhandledrejection", t)), this.wrapConsoleError(),
|
|
228
|
+
window.addEventListener("unhandledrejection", t), this.teardowns.push(() => window.removeEventListener("unhandledrejection", t)), this.wrapConsoleError(), c.log("ErrorWatcher started");
|
|
229
229
|
}
|
|
230
230
|
destroy() {
|
|
231
231
|
for (const e of this.teardowns) e();
|
|
232
|
-
this.teardowns = [], this.listeners.clear(), this.started = !1,
|
|
232
|
+
this.teardowns = [], this.listeners.clear(), this.started = !1, c.log("ErrorWatcher destroyed");
|
|
233
233
|
}
|
|
234
234
|
report(e, t) {
|
|
235
|
-
const s =
|
|
235
|
+
const s = D(e);
|
|
236
236
|
this.capture({
|
|
237
237
|
type: "manual",
|
|
238
238
|
message: s.message,
|
|
239
239
|
stack: s.stack,
|
|
240
|
-
...t ? { context:
|
|
240
|
+
...t ? { context: me(t) } : {}
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
subscribe(e) {
|
|
@@ -253,18 +253,18 @@ var Te = class {
|
|
|
253
253
|
}
|
|
254
254
|
onErrorEvent(e) {
|
|
255
255
|
if (typeof e.message != "string" && !e.error) return;
|
|
256
|
-
const t = e.error !== void 0 && e.error !== null ?
|
|
256
|
+
const t = e.error !== void 0 && e.error !== null ? D(e.error) : { message: e.message ?? "" };
|
|
257
257
|
this.capture({
|
|
258
258
|
type: "error",
|
|
259
259
|
message: t.message || e.message || "Unknown error",
|
|
260
260
|
stack: t.stack,
|
|
261
|
-
source: e.filename ?
|
|
261
|
+
source: e.filename ? De(e.filename) : void 0,
|
|
262
262
|
line: e.lineno || void 0,
|
|
263
263
|
col: e.colno || void 0
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
onRejectionEvent(e) {
|
|
267
|
-
const t = e.reason, s =
|
|
267
|
+
const t = e.reason, s = D(t);
|
|
268
268
|
this.capture({
|
|
269
269
|
type: "unhandledrejection",
|
|
270
270
|
message: s.message || "Unhandled promise rejection",
|
|
@@ -287,8 +287,8 @@ var Te = class {
|
|
|
287
287
|
onConsoleError(e) {
|
|
288
288
|
if (e.length === 0) return;
|
|
289
289
|
const t = e[0];
|
|
290
|
-
if (typeof t == "string" && t.startsWith(
|
|
291
|
-
const s = e.find(
|
|
290
|
+
if (typeof t == "string" && t.startsWith(xe)) return;
|
|
291
|
+
const s = e.find(K), i = e.map(pe).join(" ");
|
|
292
292
|
this.capture({
|
|
293
293
|
type: "console",
|
|
294
294
|
message: i,
|
|
@@ -302,7 +302,7 @@ var Te = class {
|
|
|
302
302
|
const t = Date.now(), s = e.stack !== void 0 ? this.trimStack(e.stack, e.message) : void 0;
|
|
303
303
|
let i = {
|
|
304
304
|
type: e.type,
|
|
305
|
-
message:
|
|
305
|
+
message: L(e.message, 500),
|
|
306
306
|
...e.source !== void 0 ? { source: e.source } : {},
|
|
307
307
|
...e.line !== void 0 ? { line: e.line } : {},
|
|
308
308
|
...e.col !== void 0 ? { col: e.col } : {},
|
|
@@ -314,19 +314,19 @@ var Te = class {
|
|
|
314
314
|
...e.context !== void 0 ? { context: e.context } : {}
|
|
315
315
|
};
|
|
316
316
|
if (this.filter) {
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
i =
|
|
317
|
+
const a = this.filter(i);
|
|
318
|
+
if (!a) return;
|
|
319
|
+
i = a;
|
|
320
320
|
}
|
|
321
321
|
this.prune(t);
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
|
|
322
|
+
const n = Z(i), r = this.errors.find((a) => Z(a) === n);
|
|
323
|
+
if (r) {
|
|
324
|
+
r.count += 1, r.lastAt = t, i.context !== void 0 && (r.context = i.context), this.notify(r);
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
this.errors.push(i);
|
|
328
|
-
const
|
|
329
|
-
|
|
328
|
+
const o = this.errors.length - this.maxErrors;
|
|
329
|
+
o > 0 && this.errors.splice(0, o), this.notify(i);
|
|
330
330
|
} finally {
|
|
331
331
|
this.capturing = !1;
|
|
332
332
|
}
|
|
@@ -337,7 +337,7 @@ var Te = class {
|
|
|
337
337
|
for (const s of this.listeners) try {
|
|
338
338
|
s(t);
|
|
339
339
|
} catch (i) {
|
|
340
|
-
|
|
340
|
+
c.error("ErrorWatcher listener threw:", i);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
prune(e = Date.now()) {
|
|
@@ -348,18 +348,35 @@ var Te = class {
|
|
|
348
348
|
const i = s.indexOf(`
|
|
349
349
|
`);
|
|
350
350
|
if (i !== -1 && s.slice(0, i).includes(t.slice(0, 80)) && (s = s.slice(i + 1)), s = s.trim(), !!s)
|
|
351
|
-
return
|
|
351
|
+
return L(s, this.maxStackChars);
|
|
352
352
|
}
|
|
353
353
|
currentPathname() {
|
|
354
354
|
return typeof window < "u" && window.location ? window.location.pathname : "";
|
|
355
355
|
}
|
|
356
356
|
};
|
|
357
|
-
function
|
|
357
|
+
function Z(e) {
|
|
358
358
|
return `${e.type}|${e.message}|${e.source ?? ""}|${e.line ?? ""}`;
|
|
359
359
|
}
|
|
360
|
-
var
|
|
360
|
+
var k = {
|
|
361
|
+
name: 30,
|
|
362
|
+
description: 500,
|
|
363
|
+
parameterName: 30,
|
|
364
|
+
parameterDescription: 150,
|
|
365
|
+
resultBytes: 1500
|
|
366
|
+
};
|
|
367
|
+
function Me(e) {
|
|
368
|
+
const t = [], s = (i, n, r) => {
|
|
369
|
+
const o = n?.length ?? 0;
|
|
370
|
+
o > r && t.push(`${i} (${o}/${r})`);
|
|
371
|
+
};
|
|
372
|
+
s("name", e.name, k.name), s("description", e.description, k.description);
|
|
373
|
+
for (const [i, n] of Object.entries(e.parameters?.properties ?? {}))
|
|
374
|
+
s(`"${i}" name`, i, k.parameterName), s(`"${i}" description`, n.description ?? "", k.parameterDescription);
|
|
375
|
+
return t;
|
|
376
|
+
}
|
|
377
|
+
var Pe = 5e4, Ne = 2e4, Oe = 2e3, Le = class {
|
|
361
378
|
constructor(e) {
|
|
362
|
-
this.functions = /* @__PURE__ */ new Map(), this.changeListeners = /* @__PURE__ */ new Set(), this.defaultMaxResultBytes = e?.maxResultBytes ??
|
|
379
|
+
this.functions = /* @__PURE__ */ new Map(), this.changeListeners = /* @__PURE__ */ new Set(), this.defaultMaxResultBytes = e?.maxResultBytes ?? Pe;
|
|
363
380
|
}
|
|
364
381
|
onChange(e) {
|
|
365
382
|
return this.changeListeners.add(e), () => {
|
|
@@ -370,7 +387,7 @@ var Ie = 5e4, xe = 2e4, Fe = 2e3, Me = class {
|
|
|
370
387
|
for (const e of this.changeListeners) try {
|
|
371
388
|
e();
|
|
372
389
|
} catch (t) {
|
|
373
|
-
|
|
390
|
+
c.error("Function registry change listener failed:", t);
|
|
374
391
|
}
|
|
375
392
|
}
|
|
376
393
|
setDefaultMaxResultBytes(e) {
|
|
@@ -381,33 +398,35 @@ var Ie = 5e4, xe = 2e4, Fe = 2e3, Me = class {
|
|
|
381
398
|
}
|
|
382
399
|
register(e, t, s) {
|
|
383
400
|
if (typeof e == "object") {
|
|
384
|
-
const { name:
|
|
385
|
-
return this.register(
|
|
386
|
-
description:
|
|
387
|
-
parameters:
|
|
388
|
-
maxResultBytes:
|
|
389
|
-
requiresApproval:
|
|
390
|
-
webmcp:
|
|
401
|
+
const { name: d, handler: f, description: m, parameters: v, maxResultBytes: p, requiresApproval: h, webmcp: g } = e;
|
|
402
|
+
return this.register(d, f, {
|
|
403
|
+
description: m,
|
|
404
|
+
parameters: v,
|
|
405
|
+
maxResultBytes: p,
|
|
406
|
+
requiresApproval: h,
|
|
407
|
+
webmcp: g
|
|
391
408
|
});
|
|
392
409
|
}
|
|
393
410
|
const i = e;
|
|
394
|
-
if (!t || !s) throw new
|
|
395
|
-
this.functions.has(i) &&
|
|
396
|
-
const { maxResultBytes:
|
|
411
|
+
if (!t || !s) throw new S(`registerFunction("${i}"): both a handler and a schema are required. Pass them as arguments or use the single-object form: registerFunction({ name, parameters, handler }).`, "function_invalid_registration");
|
|
412
|
+
this.functions.has(i) && c.warn(`Function "${i}" is being overwritten`);
|
|
413
|
+
const { maxResultBytes: n, requiresApproval: r, webmcp: o, ...a } = s, l = {
|
|
414
|
+
...a,
|
|
415
|
+
name: i
|
|
416
|
+
};
|
|
397
417
|
this.functions.set(i, {
|
|
398
|
-
schema:
|
|
399
|
-
...o,
|
|
400
|
-
name: i
|
|
401
|
-
},
|
|
418
|
+
schema: l,
|
|
402
419
|
handler: t,
|
|
403
|
-
maxResultBytes:
|
|
404
|
-
requiresApproval:
|
|
405
|
-
webmcp:
|
|
406
|
-
})
|
|
420
|
+
maxResultBytes: n,
|
|
421
|
+
requiresApproval: r,
|
|
422
|
+
webmcp: o
|
|
423
|
+
});
|
|
424
|
+
const u = Me(l);
|
|
425
|
+
u.length > 0 && c.warn(`Function "${i}" is over the per-tool budget on ${u.join(", ")}.`), c.log(`Registered function: ${i}`), this.emitChange();
|
|
407
426
|
}
|
|
408
427
|
unregister(e) {
|
|
409
428
|
const t = this.functions.delete(e);
|
|
410
|
-
return t && (
|
|
429
|
+
return t && (c.log(`Unregistered function: ${e}`), this.emitChange()), t;
|
|
411
430
|
}
|
|
412
431
|
get(e) {
|
|
413
432
|
return this.functions.get(e);
|
|
@@ -426,13 +445,13 @@ var Ie = 5e4, xe = 2e4, Fe = 2e3, Me = class {
|
|
|
426
445
|
}
|
|
427
446
|
async execute(e, t) {
|
|
428
447
|
const s = this.functions.get(e);
|
|
429
|
-
if (!s) throw new
|
|
430
|
-
|
|
448
|
+
if (!s) throw new V(`Function "${e}" is not registered`, e);
|
|
449
|
+
c.log(`Executing function: ${e}`, t);
|
|
431
450
|
try {
|
|
432
451
|
const i = await s.handler(t);
|
|
433
|
-
return
|
|
452
|
+
return c.log(`Function ${e} completed:`, i), this.guardResultSize(e, i, s.maxResultBytes);
|
|
434
453
|
} catch (i) {
|
|
435
|
-
throw
|
|
454
|
+
throw c.error(`Function ${e} failed:`, i), new V(`Function "${e}" execution failed: ${i instanceof Error ? i.message : "Unknown error"}`, e, i instanceof Error ? i : void 0);
|
|
436
455
|
}
|
|
437
456
|
}
|
|
438
457
|
guardResultSize(e, t, s) {
|
|
@@ -443,41 +462,41 @@ var Ie = 5e4, xe = 2e4, Fe = 2e3, Me = class {
|
|
|
443
462
|
return t;
|
|
444
463
|
}
|
|
445
464
|
if (i === void 0) return t;
|
|
446
|
-
const
|
|
447
|
-
return
|
|
465
|
+
const n = new TextEncoder().encode(i).length, r = s ?? this.defaultMaxResultBytes;
|
|
466
|
+
return n > r ? (c.warn(`Function "${e}" result is ${n} bytes, over the ${r}-byte limit; a truncated preview was sent to the agent instead. Return fewer fields, paginate, or raise maxResultBytes for this function.`), {
|
|
448
467
|
truncated: !0,
|
|
449
|
-
originalBytes:
|
|
450
|
-
maxBytes:
|
|
451
|
-
preview: i.slice(0,
|
|
452
|
-
hint: `The result of "${e}" exceeded the ${
|
|
453
|
-
}) : (
|
|
468
|
+
originalBytes: n,
|
|
469
|
+
maxBytes: r,
|
|
470
|
+
preview: i.slice(0, Oe),
|
|
471
|
+
hint: `The result of "${e}" exceeded the ${r}-byte limit and was truncated. Request less data (use limit or filter parameters if available), or tell the user the result is too large to process.`
|
|
472
|
+
}) : (n > Ne && c.warn(`Function "${e}" returned a large result (${Math.round(n / 1024)} KB). Large results consume LLM context: return fewer fields, paginate, or push the data to the UI and return a summary.`), t);
|
|
454
473
|
}
|
|
455
474
|
clear() {
|
|
456
475
|
const e = this.functions.size > 0;
|
|
457
|
-
this.functions.clear(),
|
|
476
|
+
this.functions.clear(), c.log("Cleared all registered functions"), e && this.emitChange();
|
|
458
477
|
}
|
|
459
478
|
get size() {
|
|
460
479
|
return this.functions.size;
|
|
461
480
|
}
|
|
462
|
-
},
|
|
481
|
+
}, je = new TextEncoder();
|
|
463
482
|
function E(e) {
|
|
464
|
-
return
|
|
483
|
+
return je.encode(e).length;
|
|
465
484
|
}
|
|
466
|
-
function
|
|
485
|
+
function j(e) {
|
|
467
486
|
return E(JSON.stringify(e)) - 2;
|
|
468
487
|
}
|
|
469
|
-
function
|
|
488
|
+
function ye(e, t) {
|
|
470
489
|
if (t <= 0) return "";
|
|
471
490
|
let s = "", i = 0;
|
|
472
|
-
for (const
|
|
473
|
-
const
|
|
474
|
-
if (i +
|
|
475
|
-
s +=
|
|
491
|
+
for (const n of e) {
|
|
492
|
+
const r = j(n);
|
|
493
|
+
if (i + r > t) break;
|
|
494
|
+
s += n, i += r;
|
|
476
495
|
}
|
|
477
496
|
return s;
|
|
478
497
|
}
|
|
479
|
-
var
|
|
480
|
-
var
|
|
498
|
+
var Ue = 50, We = 2;
|
|
499
|
+
var Be = 2e3;
|
|
481
500
|
function A(e) {
|
|
482
501
|
try {
|
|
483
502
|
return JSON.stringify(e);
|
|
@@ -485,273 +504,401 @@ function A(e) {
|
|
|
485
504
|
return;
|
|
486
505
|
}
|
|
487
506
|
}
|
|
488
|
-
var
|
|
489
|
-
function
|
|
490
|
-
return t <= 0 ? Promise.resolve(
|
|
491
|
-
const
|
|
492
|
-
e.then((
|
|
493
|
-
clearTimeout(
|
|
494
|
-
}, (
|
|
495
|
-
clearTimeout(
|
|
507
|
+
var U = /* @__PURE__ */ Symbol("ago.pageData.timeout");
|
|
508
|
+
function Ge(e, t) {
|
|
509
|
+
return t <= 0 ? Promise.resolve(U) : new Promise((s, i) => {
|
|
510
|
+
const n = setTimeout(() => s(U), t);
|
|
511
|
+
e.then((r) => {
|
|
512
|
+
clearTimeout(n), s(r);
|
|
513
|
+
}, (r) => {
|
|
514
|
+
clearTimeout(n), i(r);
|
|
496
515
|
});
|
|
497
516
|
});
|
|
498
517
|
}
|
|
499
|
-
async function
|
|
518
|
+
async function qe(e, t) {
|
|
500
519
|
const s = Date.now() + t;
|
|
501
520
|
let i = 0;
|
|
502
|
-
for (; Date.now() < s && i <
|
|
503
|
-
i = e().isLoading?.() ? 0 : i + 1, await new Promise((
|
|
504
|
-
const
|
|
505
|
-
if (!
|
|
506
|
-
const
|
|
507
|
-
if (
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
if (!
|
|
511
|
-
Promise.resolve(
|
|
521
|
+
for (; Date.now() < s && i < We; )
|
|
522
|
+
i = e().isLoading?.() ? 0 : i + 1, await new Promise((a) => setTimeout(a, Ue));
|
|
523
|
+
const n = e().get();
|
|
524
|
+
if (!ee(n)) return n;
|
|
525
|
+
const r = await Ge(Promise.resolve(n), s - Date.now());
|
|
526
|
+
if (r !== U) return r;
|
|
527
|
+
c.warn("Page data did not resolve within the settle timeout; returning what the page has now. Raise settleTimeoutMs if the work legitimately takes longer.");
|
|
528
|
+
const o = e().get();
|
|
529
|
+
if (!ee(o)) return o;
|
|
530
|
+
Promise.resolve(o).catch(() => {
|
|
512
531
|
});
|
|
513
532
|
}
|
|
514
|
-
function
|
|
533
|
+
function ee(e) {
|
|
515
534
|
return typeof e == "object" && e !== null && typeof e.then == "function";
|
|
516
535
|
}
|
|
517
|
-
function
|
|
536
|
+
function Ke(e) {
|
|
518
537
|
if (typeof e != "object" || e === null || Array.isArray(e)) return;
|
|
519
538
|
const t = e;
|
|
520
539
|
let s;
|
|
521
540
|
for (const i of Object.keys(t)) {
|
|
522
|
-
const
|
|
523
|
-
Array.isArray(
|
|
541
|
+
const n = t[i];
|
|
542
|
+
Array.isArray(n) && (s === void 0 || n.length > t[s].length) && (s = i);
|
|
524
543
|
}
|
|
525
544
|
return s;
|
|
526
545
|
}
|
|
527
|
-
function
|
|
546
|
+
function Je(e, t) {
|
|
528
547
|
let s = 2, i = 0;
|
|
529
|
-
for (const
|
|
530
|
-
const
|
|
531
|
-
if (s +
|
|
532
|
-
s +=
|
|
548
|
+
for (const n of e) {
|
|
549
|
+
const r = E(A(n) ?? "null") + (i > 0 ? 1 : 0);
|
|
550
|
+
if (s + r > t) break;
|
|
551
|
+
s += r, i++;
|
|
533
552
|
}
|
|
534
553
|
return i;
|
|
535
554
|
}
|
|
536
|
-
function
|
|
555
|
+
function W(e) {
|
|
537
556
|
return `The page data returned by "${e}" was too large to send in full. Only the first items are included: ask for fewer rows or narrow the filters to see the rest.`;
|
|
538
557
|
}
|
|
539
|
-
function
|
|
540
|
-
const
|
|
558
|
+
function He(e, t, s, i) {
|
|
559
|
+
const n = {
|
|
541
560
|
truncated: !0,
|
|
542
561
|
originalBytes: s,
|
|
543
562
|
maxBytes: i,
|
|
544
563
|
preview: "",
|
|
545
|
-
hint:
|
|
546
|
-
},
|
|
564
|
+
hint: W(e)
|
|
565
|
+
}, r = E(A(n) ?? "{}");
|
|
547
566
|
return {
|
|
548
|
-
...
|
|
549
|
-
preview:
|
|
567
|
+
...n,
|
|
568
|
+
preview: ye(t, Math.min(Be, i - r))
|
|
550
569
|
};
|
|
551
570
|
}
|
|
552
|
-
function
|
|
553
|
-
const
|
|
554
|
-
...
|
|
555
|
-
[
|
|
571
|
+
function ze(e, t, s, i, n) {
|
|
572
|
+
const r = s === void 0 ? {} : { ...t }, o = s ?? "items", a = E(A({
|
|
573
|
+
...r,
|
|
574
|
+
[o]: [],
|
|
556
575
|
truncation: {
|
|
557
576
|
truncated: !0,
|
|
558
577
|
returnedItems: i.length,
|
|
559
578
|
totalItems: i.length,
|
|
560
|
-
hint:
|
|
579
|
+
hint: W(e)
|
|
561
580
|
}
|
|
562
581
|
}) ?? "{}") - 2;
|
|
563
|
-
if (
|
|
564
|
-
const
|
|
582
|
+
if (a >= n) return;
|
|
583
|
+
const l = i.slice(0, Je(i, n - a));
|
|
565
584
|
return {
|
|
566
|
-
...
|
|
567
|
-
[
|
|
585
|
+
...r,
|
|
586
|
+
[o]: l,
|
|
568
587
|
truncation: {
|
|
569
588
|
truncated: !0,
|
|
570
|
-
returnedItems:
|
|
589
|
+
returnedItems: l.length,
|
|
571
590
|
totalItems: i.length,
|
|
572
|
-
hint:
|
|
591
|
+
hint: W(e)
|
|
573
592
|
}
|
|
574
593
|
};
|
|
575
594
|
}
|
|
576
|
-
function
|
|
595
|
+
function te(e, t, s) {
|
|
577
596
|
const i = A(t);
|
|
578
597
|
if (i === void 0) return t;
|
|
579
|
-
const
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
if (
|
|
584
|
-
const
|
|
585
|
-
if (
|
|
598
|
+
const n = E(i);
|
|
599
|
+
if (n <= s) return t;
|
|
600
|
+
c.warn(`Page data for "${e}" is ${n} bytes, over the ${s}-byte limit; it was truncated to the first items that fit. Return fewer fields per item, paginate, or raise maxResultBytes on the data source.`);
|
|
601
|
+
const r = Ke(t), o = Array.isArray(t) ? t : r !== void 0 ? t[r] : void 0;
|
|
602
|
+
if (o) {
|
|
603
|
+
const a = ze(e, t, r, o, s), l = E(A(a) ?? "");
|
|
604
|
+
if (a !== void 0 && l <= s) return a;
|
|
605
|
+
}
|
|
606
|
+
return He(e, i, n, s);
|
|
607
|
+
}
|
|
608
|
+
var J = "navigateToPage", T = "listPages";
|
|
609
|
+
function Xe(e) {
|
|
610
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
611
|
+
}
|
|
612
|
+
function B(e) {
|
|
613
|
+
return e.split("/").filter((t) => t.startsWith(":")).map((t) => t.slice(1));
|
|
614
|
+
}
|
|
615
|
+
function Ve(e, t) {
|
|
616
|
+
const s = [];
|
|
617
|
+
return {
|
|
618
|
+
path: e.split("/").map((i) => {
|
|
619
|
+
if (!i.startsWith(":")) return i;
|
|
620
|
+
const n = i.slice(1), r = t[n];
|
|
621
|
+
return r == null || r === "" ? (s.push(n), i) : encodeURIComponent(String(r));
|
|
622
|
+
}).join("/"),
|
|
623
|
+
missing: s
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function Ye(e, t) {
|
|
627
|
+
const s = t.find((n) => n.path === e);
|
|
628
|
+
if (s) return s;
|
|
629
|
+
const i = t.find((n) => {
|
|
630
|
+
if (!n.path.includes(":")) return !1;
|
|
631
|
+
const r = "^" + n.path.split("/").map((o) => o.startsWith(":") ? "[^/]+" : Xe(o)).join("/") + "/?$";
|
|
632
|
+
return new RegExp(r).test(e);
|
|
633
|
+
});
|
|
634
|
+
return i || t.filter((n) => n.path !== "/" && e.startsWith(n.path)).sort((n, r) => r.path.length - n.path.length)[0];
|
|
635
|
+
}
|
|
636
|
+
function ve(e) {
|
|
637
|
+
return [...new Set(e.map((t) => t.section).filter((t) => !!t))];
|
|
638
|
+
}
|
|
639
|
+
function Qe(e) {
|
|
640
|
+
const t = B(e.path), s = t.length > 0 ? ` (requires ${t.map((i) => `"${i}"`).join(", ")})` : "";
|
|
641
|
+
return `- "${e.name}"${s}: ${e.description}`;
|
|
642
|
+
}
|
|
643
|
+
function Ze(e, t, s) {
|
|
644
|
+
const i = s?.catalogue === "onDemand", n = ve(t);
|
|
645
|
+
!i && n.length > 0 && c.log('registerNavigationFunction: routes declare "section" but catalogue is "inline", so it is unused. Set catalogue: "onDemand" to use it.');
|
|
646
|
+
const r = i ? `Navigate the user to a page. Call ${T} for what a page name means.` : `Navigate the user to a page in the application. Available pages:
|
|
647
|
+
${t.map(Qe).join(`
|
|
648
|
+
`)}`, o = /* @__PURE__ */ new Map();
|
|
649
|
+
for (const u of t) for (const d of B(u.path)) o.set(d, [...o.get(d) ?? [], u.name]);
|
|
650
|
+
const a = t.map((u) => u.name), l = { page: {
|
|
651
|
+
type: "string",
|
|
652
|
+
description: "The page to navigate to",
|
|
653
|
+
enum: a
|
|
654
|
+
} };
|
|
655
|
+
for (const [u, d] of o) {
|
|
656
|
+
if (u === "page") {
|
|
657
|
+
c.error('registerNavigationFunction: a ":page" placeholder collides with the "page" argument and is ignored. Rename the placeholder.');
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
l[u] = {
|
|
661
|
+
type: "string",
|
|
662
|
+
description: `Value for ":${u}" in the page path. Required when page is ${d.map((f) => `"${f}"`).join(" or ")}.`
|
|
663
|
+
};
|
|
586
664
|
}
|
|
587
|
-
return
|
|
665
|
+
return {
|
|
666
|
+
name: J,
|
|
667
|
+
description: r,
|
|
668
|
+
parameters: {
|
|
669
|
+
type: "object",
|
|
670
|
+
properties: l,
|
|
671
|
+
required: ["page"]
|
|
672
|
+
},
|
|
673
|
+
webmcp: { navigates: !0 },
|
|
674
|
+
handler: async (u) => {
|
|
675
|
+
const d = u.page, f = t.find((g) => g.name === d);
|
|
676
|
+
if (!f) return i ? {
|
|
677
|
+
success: !1,
|
|
678
|
+
error: `Unknown page: ${d}`,
|
|
679
|
+
pages: a
|
|
680
|
+
} : {
|
|
681
|
+
success: !1,
|
|
682
|
+
error: `Unknown page: ${d}`
|
|
683
|
+
};
|
|
684
|
+
let m = {};
|
|
685
|
+
if (typeof u.params == "string") try {
|
|
686
|
+
m = JSON.parse(u.params);
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
else u.params && typeof u.params == "object" && (m = u.params);
|
|
690
|
+
const v = {};
|
|
691
|
+
for (const g of B(f.path)) v[g] = u[g] ?? m[g];
|
|
692
|
+
const { path: p, missing: h } = Ve(f.path, v);
|
|
693
|
+
if (h.length > 0) {
|
|
694
|
+
const g = h.map((y) => `"${y}": "..."`).join(", ");
|
|
695
|
+
return {
|
|
696
|
+
success: !1,
|
|
697
|
+
error: `Page "${d}" needs ${h.map((y) => `"${y}"`).join(", ")}. Retry with { "page": "${d}", ${g} }.`
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
return e(p), {
|
|
701
|
+
success: !0,
|
|
702
|
+
navigatedTo: p
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function et(e) {
|
|
708
|
+
const t = ve(e), s = (i) => ({
|
|
709
|
+
name: i.name,
|
|
710
|
+
description: i.description
|
|
711
|
+
});
|
|
712
|
+
return {
|
|
713
|
+
name: T,
|
|
714
|
+
description: `List what each page name of ${J} means.`,
|
|
715
|
+
parameters: {
|
|
716
|
+
type: "object",
|
|
717
|
+
properties: t.length > 0 ? { section: {
|
|
718
|
+
type: "string",
|
|
719
|
+
description: "Which group of pages to list.",
|
|
720
|
+
enum: t
|
|
721
|
+
} } : {},
|
|
722
|
+
required: t.length > 0 ? ["section"] : []
|
|
723
|
+
},
|
|
724
|
+
webmcp: { annotations: { readOnlyHint: !0 } },
|
|
725
|
+
handler: (i) => {
|
|
726
|
+
if (t.length === 0) return { pages: e.map(s) };
|
|
727
|
+
const n = typeof i.section == "string" ? i.section : void 0, r = t.find((o) => o.toLowerCase() === n?.toLowerCase());
|
|
728
|
+
return r ? { pages: e.filter((o) => o.section === r).map(s) } : {
|
|
729
|
+
pages: [],
|
|
730
|
+
sections: t,
|
|
731
|
+
error: n ? `Unknown section: ${n}` : '"section" is required. Pick one and call again.'
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
};
|
|
588
735
|
}
|
|
589
|
-
function
|
|
736
|
+
function I(e, t) {
|
|
590
737
|
if (e === t) return !0;
|
|
591
738
|
if (e === null || t === null || typeof e != "object" || typeof t != "object" || Array.isArray(e) !== Array.isArray(t)) return !1;
|
|
592
739
|
if (Array.isArray(e))
|
|
593
|
-
return e.length !== t.length ? !1 : e.every((
|
|
740
|
+
return e.length !== t.length ? !1 : e.every((n, r) => I(n, t[r]));
|
|
594
741
|
const s = Object.keys(e), i = Object.keys(t);
|
|
595
|
-
return s.length !== i.length ? !1 : s.every((
|
|
742
|
+
return s.length !== i.length ? !1 : s.every((n) => n in t && I(e[n], t[n]));
|
|
596
743
|
}
|
|
597
|
-
var
|
|
598
|
-
function
|
|
744
|
+
var se = 100, $ = " … [truncated]", we = { truncated: !0 }, tt = E(',"data":' + JSON.stringify(we));
|
|
745
|
+
function G(e) {
|
|
599
746
|
return E(JSON.stringify(e));
|
|
600
747
|
}
|
|
601
|
-
function
|
|
602
|
-
if (
|
|
603
|
-
const s = Object.entries(e.rejected), i = Object.fromEntries(s.map(([
|
|
748
|
+
function ie(e, t) {
|
|
749
|
+
if (G(e) <= t || !e.rejected) return e;
|
|
750
|
+
const s = Object.entries(e.rejected), i = Object.fromEntries(s.map(([a]) => [a, $])), n = {
|
|
604
751
|
...e,
|
|
605
752
|
rejected: i
|
|
606
753
|
};
|
|
607
|
-
let
|
|
608
|
-
if (
|
|
609
|
-
const
|
|
610
|
-
for (const [
|
|
611
|
-
const u =
|
|
754
|
+
let r = G(n);
|
|
755
|
+
if (r > t) return n;
|
|
756
|
+
const o = j($);
|
|
757
|
+
for (const [a, l] of s) {
|
|
758
|
+
const u = j(l), d = t - r + o;
|
|
612
759
|
if (u <= d) {
|
|
613
|
-
i[
|
|
760
|
+
i[a] = l, r += u - o;
|
|
614
761
|
continue;
|
|
615
762
|
}
|
|
616
|
-
i[
|
|
763
|
+
i[a] = ye(l, d - o) + $;
|
|
617
764
|
break;
|
|
618
765
|
}
|
|
619
|
-
return
|
|
766
|
+
return n;
|
|
620
767
|
}
|
|
621
|
-
function
|
|
768
|
+
function _(e) {
|
|
622
769
|
return Array.isArray(e) ? "array" : typeof e;
|
|
623
770
|
}
|
|
624
|
-
function
|
|
625
|
-
return typeof e != "number" ? `Expected type "number", got "${
|
|
771
|
+
function ne(e) {
|
|
772
|
+
return typeof e != "number" ? `Expected type "number", got "${_(e)}".` : Number.isFinite(e) ? null : "Expected a finite number.";
|
|
626
773
|
}
|
|
627
|
-
function
|
|
628
|
-
const t = e.slice(0,
|
|
774
|
+
function Ee(e) {
|
|
775
|
+
const t = e.slice(0, se).map((i) => JSON.stringify(i)), s = e.length - se;
|
|
629
776
|
return s > 0 ? `${t.join(", ")} (${s} more not shown)` : t.join(", ");
|
|
630
777
|
}
|
|
631
|
-
function
|
|
632
|
-
return t.includes(e) ? null : `${JSON.stringify(e)} is not an allowed value. Allowed values: ${
|
|
778
|
+
function re(e, t) {
|
|
779
|
+
return t.includes(e) ? null : `${JSON.stringify(e)} is not an allowed value. Allowed values: ${Ee(t)}.`;
|
|
633
780
|
}
|
|
634
|
-
function
|
|
781
|
+
function st(e, t) {
|
|
635
782
|
const { schema: s } = t;
|
|
636
783
|
if (s.type === "array") {
|
|
637
|
-
if (!Array.isArray(e)) return `Expected type "array", got "${
|
|
638
|
-
for (let
|
|
639
|
-
const
|
|
784
|
+
if (!Array.isArray(e)) return `Expected type "array", got "${_(e)}".`;
|
|
785
|
+
for (let n = 0; n < e.length; n++) {
|
|
786
|
+
const r = e[n];
|
|
640
787
|
if (s.items?.type) {
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
788
|
+
const o = s.items.type === "number" ? ne(r) : _(r) !== s.items.type ? `Expected type "${s.items.type}", got "${_(r)}".` : null;
|
|
789
|
+
if (o) return `Array item at index ${n}: ${o[0].toLowerCase()}${o.slice(1)}`;
|
|
643
790
|
}
|
|
644
791
|
if (s.items?.enum) {
|
|
645
|
-
const
|
|
646
|
-
if (
|
|
792
|
+
const o = re(r, s.items.enum);
|
|
793
|
+
if (o) return `Array item ${o}`;
|
|
647
794
|
}
|
|
648
795
|
}
|
|
649
796
|
return null;
|
|
650
797
|
}
|
|
651
798
|
if (s.type === "number") {
|
|
652
|
-
const
|
|
653
|
-
if (
|
|
654
|
-
} else if (
|
|
655
|
-
const i =
|
|
656
|
-
return i ?
|
|
799
|
+
const n = ne(e);
|
|
800
|
+
if (n) return n;
|
|
801
|
+
} else if (_(e) !== s.type) return `Expected type "${s.type}", got "${_(e)}".`;
|
|
802
|
+
const i = be(t);
|
|
803
|
+
return i ? re(e, i) : null;
|
|
657
804
|
}
|
|
658
|
-
function
|
|
805
|
+
function H(e) {
|
|
659
806
|
return e.clearable === !0 && e.schema.type === "string";
|
|
660
807
|
}
|
|
661
|
-
function
|
|
808
|
+
function be(e) {
|
|
662
809
|
const t = e.schema.enum;
|
|
663
810
|
if (t)
|
|
664
|
-
return
|
|
811
|
+
return H(e) && !t.includes("") ? [...t, ""] : t;
|
|
665
812
|
}
|
|
666
|
-
function
|
|
813
|
+
function it(e) {
|
|
667
814
|
const t = {
|
|
668
815
|
...e.schema,
|
|
669
816
|
description: e.description
|
|
670
817
|
};
|
|
671
|
-
|
|
672
|
-
const s =
|
|
818
|
+
H(e) && (t.description = `${e.description} Pass "" to clear it.`);
|
|
819
|
+
const s = be(e);
|
|
673
820
|
return s && (t.enum = s), t;
|
|
674
821
|
}
|
|
675
|
-
function
|
|
676
|
-
const s = new Map(e.map((
|
|
822
|
+
function nt(e, t) {
|
|
823
|
+
const s = new Map(e.map((r) => [r.name, r])), i = e.map((r) => r.name), n = e.map((r) => `- "${r.name}": ${r.description}`).join(`
|
|
677
824
|
`);
|
|
678
825
|
return {
|
|
679
826
|
name: t.name,
|
|
680
|
-
handler: async (
|
|
681
|
-
const
|
|
682
|
-
for (const [h,
|
|
827
|
+
handler: async (r) => {
|
|
828
|
+
const o = [], a = [], l = {};
|
|
829
|
+
for (const [h, g] of Object.entries(r)) {
|
|
683
830
|
const y = s.get(h);
|
|
684
831
|
if (!y) {
|
|
685
|
-
|
|
832
|
+
l[h] = `"${h}" is not a registered control. Available controls: ${Ee(i)}.`;
|
|
686
833
|
continue;
|
|
687
834
|
}
|
|
688
|
-
if (
|
|
689
|
-
const b =
|
|
835
|
+
if (g == null || g === "" && !H(y)) continue;
|
|
836
|
+
const b = st(g, y);
|
|
690
837
|
if (b) {
|
|
691
|
-
|
|
838
|
+
l[h] = b;
|
|
692
839
|
continue;
|
|
693
840
|
}
|
|
694
|
-
if (y.get &&
|
|
695
|
-
|
|
841
|
+
if (y.get && I(g, y.get())) {
|
|
842
|
+
a.push(h);
|
|
696
843
|
continue;
|
|
697
844
|
}
|
|
698
|
-
const w = await y.set(
|
|
699
|
-
w ? w.result === "rejected" ?
|
|
845
|
+
const w = await y.set(g);
|
|
846
|
+
w ? w.result === "rejected" ? l[h] = w.reason || "The page rejected this field's update." : w.result === "unchanged" ? a.push(h) : o.push(h) : o.push(h);
|
|
700
847
|
}
|
|
701
|
-
const u = Object.keys(
|
|
848
|
+
const u = Object.keys(l).length > 0, d = {
|
|
702
849
|
success: !u,
|
|
703
|
-
applied:
|
|
704
|
-
unchanged:
|
|
705
|
-
...u ? { rejected:
|
|
706
|
-
},
|
|
707
|
-
if (!t.data) return
|
|
708
|
-
const m =
|
|
850
|
+
applied: o,
|
|
851
|
+
unchanged: a,
|
|
852
|
+
...u ? { rejected: l } : {}
|
|
853
|
+
}, f = t.getResultBudget();
|
|
854
|
+
if (!t.data) return ie(d, f);
|
|
855
|
+
const m = ie(d, f - tt), v = await t.data.read(m), p = {
|
|
709
856
|
...m,
|
|
710
857
|
data: v
|
|
711
858
|
};
|
|
712
|
-
return
|
|
859
|
+
return G(p) <= f ? p : {
|
|
713
860
|
...m,
|
|
714
|
-
data:
|
|
861
|
+
data: we
|
|
715
862
|
};
|
|
716
863
|
},
|
|
717
864
|
description: (e.length > 0 ? `Change the state of the current page. Set ONLY the controls the user explicitly asked for; leave the others unset. Available controls:
|
|
718
|
-
${
|
|
865
|
+
${n}` : "The current page has no editable state — nothing to change here.") + (t.data ? `
|
|
719
866
|
Returns the resulting page data once it has loaded: ${t.data.description}` : ""),
|
|
720
867
|
parameters: {
|
|
721
868
|
type: "object",
|
|
722
|
-
properties: Object.fromEntries(e.map((
|
|
869
|
+
properties: Object.fromEntries(e.map((r) => [r.name, it(r)])),
|
|
723
870
|
required: []
|
|
724
871
|
},
|
|
725
872
|
requiresApproval: t.requiresApproval,
|
|
726
873
|
maxResultBytes: t.data?.maxResultBytes
|
|
727
874
|
};
|
|
728
875
|
}
|
|
729
|
-
var
|
|
876
|
+
var rt = 250, ot = 3, at = 1e3, ct = 24, lt = 10, ut = 50, dt = [
|
|
730
877
|
"mousemove",
|
|
731
878
|
"mousedown",
|
|
732
879
|
"keydown",
|
|
733
880
|
"scroll",
|
|
734
881
|
"touchstart"
|
|
735
|
-
],
|
|
882
|
+
], ht = class {
|
|
736
883
|
constructor(e = {}) {
|
|
737
|
-
this.started = !1, this.teardowns = [], this.route = "", this.routeEnteredAt = 0, this.lastActivityAt = 0, this.lastHeavyActivityAt = 0, this.recentRoutes = [], this.routeBounces = 0, this.rageClicks = 0, this.jsErrors = 0, this.fieldErrors = {}, this.recentClicks = [], this.signals = [], this.listeners = /* @__PURE__ */ new Set(), this.getPageState = e.getPageState, this.activityThrottleMs = e.activityThrottleMs ??
|
|
884
|
+
this.started = !1, this.teardowns = [], this.route = "", this.routeEnteredAt = 0, this.lastActivityAt = 0, this.lastHeavyActivityAt = 0, this.recentRoutes = [], this.routeBounces = 0, this.rageClicks = 0, this.jsErrors = 0, this.fieldErrors = {}, this.recentClicks = [], this.signals = [], this.listeners = /* @__PURE__ */ new Set(), this.getPageState = e.getPageState, this.activityThrottleMs = e.activityThrottleMs ?? rt, this.rageClickCount = e.rageClickCount ?? ot, this.rageClickWindowMs = e.rageClickWindowMs ?? at, this.rageClickRadiusPx = e.rageClickRadiusPx ?? ct, this.maxRecentRoutes = e.maxRecentRoutes ?? lt, this.maxSignals = e.maxSignals ?? ut;
|
|
738
885
|
}
|
|
739
886
|
start() {
|
|
740
887
|
if (this.started || typeof window > "u" || typeof document > "u") return;
|
|
741
888
|
this.started = !0;
|
|
742
889
|
const e = Date.now();
|
|
743
890
|
this.route = this.currentPathname(), this.routeEnteredAt = e, this.lastActivityAt = e, this.recentRoutes = [this.route];
|
|
744
|
-
const t = (i,
|
|
745
|
-
i.addEventListener(
|
|
891
|
+
const t = (i, n, r) => {
|
|
892
|
+
i.addEventListener(n, r, { passive: !0 }), this.teardowns.push(() => i.removeEventListener(n, r));
|
|
746
893
|
}, s = () => this.recordActivity();
|
|
747
|
-
for (const i of
|
|
894
|
+
for (const i of dt) t(window, i, s);
|
|
748
895
|
t(document, "visibilitychange", () => {
|
|
749
896
|
document.visibilityState === "visible" && this.recordActivity();
|
|
750
|
-
}), t(window, "popstate", () => this.checkRoute()), t(window, "hashchange", () => this.checkRoute()), t(window, "click", (i) => this.onClick(i)),
|
|
897
|
+
}), t(window, "popstate", () => this.checkRoute()), t(window, "hashchange", () => this.checkRoute()), t(window, "click", (i) => this.onClick(i)), c.log("SignalCollector started");
|
|
751
898
|
}
|
|
752
899
|
destroy() {
|
|
753
900
|
for (const e of this.teardowns) e();
|
|
754
|
-
this.teardowns = [], this.listeners.clear(), this.recentClicks = [], this.started = !1,
|
|
901
|
+
this.teardowns = [], this.listeners.clear(), this.recentClicks = [], this.started = !1, c.log("SignalCollector destroyed");
|
|
755
902
|
}
|
|
756
903
|
signalFieldError(e) {
|
|
757
904
|
this.checkRoute();
|
|
@@ -804,7 +951,7 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
804
951
|
try {
|
|
805
952
|
return this.getPageState() ?? null;
|
|
806
953
|
} catch (e) {
|
|
807
|
-
return
|
|
954
|
+
return c.warn("SignalCollector getPageState threw:", e), null;
|
|
808
955
|
}
|
|
809
956
|
}
|
|
810
957
|
recordActivity() {
|
|
@@ -822,13 +969,13 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
822
969
|
at: t,
|
|
823
970
|
meta: { from: s }
|
|
824
971
|
});
|
|
825
|
-
const i = this.recentRoutes,
|
|
826
|
-
|
|
972
|
+
const i = this.recentRoutes, n = i.length;
|
|
973
|
+
n >= 4 && i[n - 1] === i[n - 3] && i[n - 2] === i[n - 4] && i[n - 1] !== i[n - 2] && (this.routeBounces += 1, this.pushSignal({
|
|
827
974
|
type: "route_bounce",
|
|
828
975
|
route: e,
|
|
829
976
|
at: t,
|
|
830
977
|
count: this.routeBounces,
|
|
831
|
-
meta: { between: `${i[
|
|
978
|
+
meta: { between: `${i[n - 2]}↔${i[n - 1]}` }
|
|
832
979
|
}));
|
|
833
980
|
}
|
|
834
981
|
onClick(e) {
|
|
@@ -839,9 +986,9 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
839
986
|
y: e.clientY,
|
|
840
987
|
stateKey: s
|
|
841
988
|
};
|
|
842
|
-
this.recentClicks = this.recentClicks.filter((
|
|
843
|
-
const
|
|
844
|
-
if (!
|
|
989
|
+
this.recentClicks = this.recentClicks.filter((a) => t - a.at <= this.rageClickWindowMs);
|
|
990
|
+
const n = this.recentClicks[0], r = !n || Math.abs(i.x - n.x) <= this.rageClickRadiusPx && Math.abs(i.y - n.y) <= this.rageClickRadiusPx, o = !n || n.stateKey === s;
|
|
991
|
+
if (!r || !o) {
|
|
845
992
|
this.recentClicks = [i];
|
|
846
993
|
return;
|
|
847
994
|
}
|
|
@@ -866,20 +1013,20 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
866
1013
|
for (const t of this.listeners) try {
|
|
867
1014
|
t(e);
|
|
868
1015
|
} catch (s) {
|
|
869
|
-
|
|
1016
|
+
c.error("Signal listener threw:", s);
|
|
870
1017
|
}
|
|
871
1018
|
}
|
|
872
1019
|
};
|
|
873
|
-
function
|
|
1020
|
+
function gt(e, t) {
|
|
874
1021
|
const s = t ? t.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
|
|
875
1022
|
let i = e;
|
|
876
1023
|
if (t && s) try {
|
|
877
|
-
const
|
|
878
|
-
|
|
1024
|
+
const a = s.getItem(t.key);
|
|
1025
|
+
a != null && (i = JSON.parse(a));
|
|
879
1026
|
} catch {
|
|
880
1027
|
}
|
|
881
|
-
const
|
|
882
|
-
function
|
|
1028
|
+
const n = /* @__PURE__ */ new Set(), r = () => n.forEach((a) => a(i));
|
|
1029
|
+
function o() {
|
|
883
1030
|
if (t && s) try {
|
|
884
1031
|
s.setItem(t.key, JSON.stringify(i));
|
|
885
1032
|
} catch {
|
|
@@ -887,31 +1034,31 @@ function tt(e, t) {
|
|
|
887
1034
|
}
|
|
888
1035
|
return {
|
|
889
1036
|
get: () => i,
|
|
890
|
-
set: (
|
|
891
|
-
i =
|
|
1037
|
+
set: (a) => {
|
|
1038
|
+
i = a, o(), r();
|
|
892
1039
|
},
|
|
893
|
-
subscribe: (
|
|
894
|
-
|
|
1040
|
+
subscribe: (a) => (n.add(a), () => {
|
|
1041
|
+
n.delete(a);
|
|
895
1042
|
})
|
|
896
1043
|
};
|
|
897
1044
|
}
|
|
898
|
-
var
|
|
899
|
-
function
|
|
1045
|
+
var ft = 6e4, mt = 1440 * 60 * 1e3, pt = "ago_proactive";
|
|
1046
|
+
function M(e) {
|
|
900
1047
|
const t = new Date(e), s = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getDate()).padStart(2, "0");
|
|
901
1048
|
return `${t.getFullYear()}-${s}-${i}`;
|
|
902
1049
|
}
|
|
903
|
-
var
|
|
1050
|
+
var yt = class {
|
|
904
1051
|
constructor(e = {}) {
|
|
905
|
-
this.killSwitchEnabled = !1, this.engaged = !1, this.turnInFlight = !1, this.slotOccupied = !1, this.sessionCount = 0, this.perSessionCap = e.frequencyCap?.perSession, this.perDayCap = e.frequencyCap?.perDay, this.store =
|
|
1052
|
+
this.killSwitchEnabled = !1, this.engaged = !1, this.turnInFlight = !1, this.slotOccupied = !1, this.sessionCount = 0, this.perSessionCap = e.frequencyCap?.perSession, this.perDayCap = e.frequencyCap?.perDay, this.store = gt({
|
|
906
1053
|
optOut: !1,
|
|
907
1054
|
lastFiredAt: {},
|
|
908
1055
|
dismissedAt: {},
|
|
909
1056
|
day: {
|
|
910
|
-
date:
|
|
1057
|
+
date: M(Date.now()),
|
|
911
1058
|
count: 0
|
|
912
1059
|
}
|
|
913
1060
|
}, {
|
|
914
|
-
key: e.storageKey ??
|
|
1061
|
+
key: e.storageKey ?? pt,
|
|
915
1062
|
storage: e.storage
|
|
916
1063
|
});
|
|
917
1064
|
}
|
|
@@ -955,10 +1102,10 @@ var nt = class {
|
|
|
955
1102
|
if (this.engaged) return this.deny(e, "user engaged (widget open)");
|
|
956
1103
|
if (this.turnInFlight) return this.deny(e, "message turn in flight");
|
|
957
1104
|
if (this.slotOccupied) return this.deny(e, "nudge slot occupied");
|
|
958
|
-
const i = s.lastFiredAt[e.id],
|
|
959
|
-
if (i !== void 0 && t - i <
|
|
960
|
-
const
|
|
961
|
-
return
|
|
1105
|
+
const i = s.lastFiredAt[e.id], n = e.cooldownMs ?? ft;
|
|
1106
|
+
if (i !== void 0 && t - i < n) return this.deny(e, "cooldown");
|
|
1107
|
+
const r = s.dismissedAt[e.id], o = e.resurfaceAfterMs ?? mt;
|
|
1108
|
+
return r !== void 0 && t - r < o ? this.deny(e, "dismissed recently") : this.perSessionCap !== void 0 && this.sessionCount >= this.perSessionCap ? this.deny(e, "perSession cap") : this.perDayCap !== void 0 && this.dayCount(t) >= this.perDayCap ? this.deny(e, "perDay cap") : !0;
|
|
962
1109
|
}
|
|
963
1110
|
recordFired(e, t = Date.now()) {
|
|
964
1111
|
const s = this.store.get();
|
|
@@ -972,7 +1119,7 @@ var nt = class {
|
|
|
972
1119
|
}
|
|
973
1120
|
recordNudgeShown(e = Date.now()) {
|
|
974
1121
|
this.sessionCount += 1;
|
|
975
|
-
const t = this.store.get(), s =
|
|
1122
|
+
const t = this.store.get(), s = M(e), i = t.day.date === s ? {
|
|
976
1123
|
date: s,
|
|
977
1124
|
count: t.day.count + 1
|
|
978
1125
|
} : {
|
|
@@ -996,50 +1143,50 @@ var nt = class {
|
|
|
996
1143
|
}
|
|
997
1144
|
dayCount(e) {
|
|
998
1145
|
const t = this.store.get();
|
|
999
|
-
return t.day.date ===
|
|
1146
|
+
return t.day.date === M(e) ? t.day.count : 0;
|
|
1000
1147
|
}
|
|
1001
1148
|
deny(e, t) {
|
|
1002
|
-
return
|
|
1149
|
+
return c.debug(`NudgeGovernor: trigger "${e.id}" blocked — ${t}`), !1;
|
|
1003
1150
|
}
|
|
1004
1151
|
};
|
|
1005
|
-
function
|
|
1152
|
+
function x() {
|
|
1006
1153
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
1007
1154
|
const t = Math.floor(Math.random() * 16);
|
|
1008
1155
|
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
1009
1156
|
});
|
|
1010
1157
|
}
|
|
1011
|
-
function
|
|
1158
|
+
function vt(e) {
|
|
1012
1159
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1013
1160
|
}
|
|
1014
|
-
function
|
|
1161
|
+
function wt(e, t) {
|
|
1015
1162
|
if (e === "*" || e === t) return !0;
|
|
1016
|
-
const s = e.split("/"), i = s.map((
|
|
1017
|
-
const
|
|
1018
|
-
return
|
|
1163
|
+
const s = e.split("/"), i = s.map((n, r) => {
|
|
1164
|
+
const o = r === s.length - 1;
|
|
1165
|
+
return n === "*" ? o ? "[^/]+(?:/[^/]+)*" : "[^/]+" : n.startsWith(":") ? "[^/]+" : vt(n);
|
|
1019
1166
|
});
|
|
1020
1167
|
return new RegExp("^" + i.join("/") + "/?$").test(t);
|
|
1021
1168
|
}
|
|
1022
|
-
function
|
|
1023
|
-
return e === t ? !0 : e === null || t === null ? !1 : Array.isArray(e) ? !Array.isArray(t) || t.length !== e.length ? !1 : e.every((s, i) =>
|
|
1169
|
+
function Se(e, t) {
|
|
1170
|
+
return e === t ? !0 : e === null || t === null ? !1 : Array.isArray(e) ? !Array.isArray(t) || t.length !== e.length ? !1 : e.every((s, i) => I(s, t[i])) : typeof e == "object" ? typeof t != "object" || Array.isArray(t) ? !1 : Object.entries(e).every(([s, i]) => Se(i, t[s])) : !1;
|
|
1024
1171
|
}
|
|
1025
|
-
function
|
|
1026
|
-
if (e.route !== void 0 && !
|
|
1172
|
+
function Et(e, t) {
|
|
1173
|
+
if (e.route !== void 0 && !wt(e.route, t.route) || e.idleMs !== void 0 && t.idleMs < e.idleMs || e.dwellMs !== void 0 && t.dwellMs < e.dwellMs || e.rageClicks !== void 0 && t.rageClicks < e.rageClicks || e.jsErrors !== void 0 && (t.jsErrors ?? 0) < e.jsErrors || e.routeBounces !== void 0 && t.routeBounces < e.routeBounces) return !1;
|
|
1027
1174
|
if (e.fieldErrors !== void 0) {
|
|
1028
1175
|
for (const [s, i] of Object.entries(e.fieldErrors)) if ((t.fieldErrors[s] ?? 0) < i) return !1;
|
|
1029
1176
|
}
|
|
1030
|
-
return !(e.pageState !== void 0 && !
|
|
1177
|
+
return !(e.pageState !== void 0 && !Se(e.pageState, t.pageState ?? {}));
|
|
1031
1178
|
}
|
|
1032
|
-
var
|
|
1179
|
+
var bt = 1e3, St = "/api/sdk/v1/config", _t = "/api/sdk/v1/proactive/evaluate", Ct = class {
|
|
1033
1180
|
constructor(e) {
|
|
1034
|
-
this.tickTimer = null, this.teardowns = [], this.started = !1, this.activeNudge = null, this.lastConversationId = null, this.shownIds = /* @__PURE__ */ new Set(), this.resolvedIds = /* @__PURE__ */ new Set(), this.lastEvaluationAt = 0, this.client = e.client, this.collector = e.collector, this.governor = e.governor, this.tracker = e.tracker, this.options = e.options, this.tickMs = e.options.tickMs ??
|
|
1181
|
+
this.tickTimer = null, this.teardowns = [], this.started = !1, this.activeNudge = null, this.lastConversationId = null, this.shownIds = /* @__PURE__ */ new Set(), this.resolvedIds = /* @__PURE__ */ new Set(), this.lastEvaluationAt = 0, this.client = e.client, this.collector = e.collector, this.governor = e.governor, this.tracker = e.tracker, this.options = e.options, this.tickMs = e.options.tickMs ?? bt;
|
|
1035
1182
|
}
|
|
1036
1183
|
start() {
|
|
1037
1184
|
if (this.started) return;
|
|
1038
1185
|
this.started = !0, this.options.enabledOverride !== void 0 ? this.governor.setKillSwitch(this.options.enabledOverride) : this.loadKillSwitch();
|
|
1039
|
-
const e = (
|
|
1040
|
-
|
|
1041
|
-
}, t = () => this.governor.setTurnInFlight(!1), s = () => this.governor.setTurnInFlight(!1), i = (
|
|
1042
|
-
|
|
1186
|
+
const e = (n) => {
|
|
1187
|
+
n.conversationId && (this.lastConversationId = n.conversationId), this.governor.setTurnInFlight(!0);
|
|
1188
|
+
}, t = () => this.governor.setTurnInFlight(!1), s = () => this.governor.setTurnInFlight(!1), i = (n) => {
|
|
1189
|
+
n?.id && (this.lastConversationId = n.id);
|
|
1043
1190
|
};
|
|
1044
1191
|
this.client.on("message:start", e), this.client.on("message:complete", t), this.client.on("message:error", s), this.client.on("conversation:loaded", i), this.teardowns.push(() => {
|
|
1045
1192
|
this.client.off("message:start", e), this.client.off("message:complete", t), this.client.off("message:error", s), this.client.off("conversation:loaded", i);
|
|
@@ -1057,17 +1204,17 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1057
1204
|
}
|
|
1058
1205
|
async loadKillSwitch() {
|
|
1059
1206
|
try {
|
|
1060
|
-
const e = await this.client.getHttp().get(
|
|
1207
|
+
const e = await this.client.getHttp().get(St);
|
|
1061
1208
|
this.governor.setKillSwitch(e?.proactive?.enabled === !0);
|
|
1062
1209
|
} catch (e) {
|
|
1063
|
-
|
|
1210
|
+
c.debug("Proactive config fetch failed; staying disabled:", e), this.governor.setKillSwitch(!1);
|
|
1064
1211
|
}
|
|
1065
1212
|
}
|
|
1066
1213
|
evaluate() {
|
|
1067
1214
|
if (this.lastEvaluationAt = Date.now(), typeof document < "u" && document.visibilityState === "hidden" || this.governor.isSlotOccupied()) return;
|
|
1068
1215
|
const e = this.collector.getSnapshot();
|
|
1069
1216
|
for (const t of this.options.triggers)
|
|
1070
|
-
if (
|
|
1217
|
+
if (Et(t.when, e) && this.governor.canFire(t)) {
|
|
1071
1218
|
this.fire(t);
|
|
1072
1219
|
return;
|
|
1073
1220
|
}
|
|
@@ -1078,7 +1225,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1078
1225
|
return;
|
|
1079
1226
|
}
|
|
1080
1227
|
this.setReady({
|
|
1081
|
-
id:
|
|
1228
|
+
id: x(),
|
|
1082
1229
|
triggerId: e.id,
|
|
1083
1230
|
source: "static",
|
|
1084
1231
|
message: e.intervene.message,
|
|
@@ -1089,7 +1236,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1089
1236
|
});
|
|
1090
1237
|
}
|
|
1091
1238
|
async evaluateWithAgent(e) {
|
|
1092
|
-
const t =
|
|
1239
|
+
const t = x(), s = {
|
|
1093
1240
|
client_nudge_id: t,
|
|
1094
1241
|
trigger_id: e.id,
|
|
1095
1242
|
goal: e.goal ?? "",
|
|
@@ -1100,9 +1247,9 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1100
1247
|
};
|
|
1101
1248
|
let i;
|
|
1102
1249
|
try {
|
|
1103
|
-
i = await this.client.getHttp().post(
|
|
1104
|
-
} catch (
|
|
1105
|
-
|
|
1250
|
+
i = await this.client.getHttp().post(_t, s);
|
|
1251
|
+
} catch (n) {
|
|
1252
|
+
c.debug("Proactive evaluate failed (treated as no-intervene):", n), this.governor.releaseSlot();
|
|
1106
1253
|
return;
|
|
1107
1254
|
}
|
|
1108
1255
|
if (!i?.intervene || !i.message) {
|
|
@@ -1114,7 +1261,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1114
1261
|
triggerId: e.id,
|
|
1115
1262
|
source: "agent",
|
|
1116
1263
|
message: i.message,
|
|
1117
|
-
action:
|
|
1264
|
+
action: At(i.action),
|
|
1118
1265
|
goal: e.goal,
|
|
1119
1266
|
kickoff: e.kickoff,
|
|
1120
1267
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -1150,10 +1297,10 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1150
1297
|
source: e.source,
|
|
1151
1298
|
type: "accepted",
|
|
1152
1299
|
occurredAt: Date.now()
|
|
1153
|
-
}), this.clearActive(e), this.client.emitProactiveEvent("nudge:accepted", { nudge: e }), (e.source === "agent" || e.goal) && (this.lastConversationId ? this.client.sendMessage(
|
|
1300
|
+
}), this.clearActive(e), this.client.emitProactiveEvent("nudge:accepted", { nudge: e }), (e.source === "agent" || e.goal) && (this.lastConversationId ? this.client.sendMessage(kt(e), {
|
|
1154
1301
|
hidden: !0,
|
|
1155
1302
|
conversationId: this.lastConversationId
|
|
1156
|
-
}).catch((t) =>
|
|
1303
|
+
}).catch((t) => c.debug("Nudge kickoff message failed:", t)) : e.kickoff ? this.client.sendMessage(e.kickoff).catch((t) => c.debug("Nudge kickoff message failed:", t)) : c.debug("Nudge accepted with no open conversation and no trigger.kickoff; skipping the chat pre-seed (a hidden message cannot open a conversation).")), e.action && await this.runAction(e.action));
|
|
1157
1304
|
}
|
|
1158
1305
|
markConverted(e) {
|
|
1159
1306
|
this.tracker.track({
|
|
@@ -1171,11 +1318,11 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1171
1318
|
try {
|
|
1172
1319
|
"functionName" in e ? await this.client.executeClientFunction(e.functionName, e.arguments ?? {}) : await this.client.executeClientFunction("setPageState", e.setPageState);
|
|
1173
1320
|
} catch (t) {
|
|
1174
|
-
|
|
1321
|
+
c.warn("Nudge action failed:", t);
|
|
1175
1322
|
}
|
|
1176
1323
|
}
|
|
1177
1324
|
};
|
|
1178
|
-
function
|
|
1325
|
+
function At(e) {
|
|
1179
1326
|
if (e)
|
|
1180
1327
|
return {
|
|
1181
1328
|
label: e.label,
|
|
@@ -1183,13 +1330,13 @@ function ft(e) {
|
|
|
1183
1330
|
arguments: e.arguments
|
|
1184
1331
|
};
|
|
1185
1332
|
}
|
|
1186
|
-
function
|
|
1333
|
+
function kt(e) {
|
|
1187
1334
|
const t = e.goal ? ` Goal: ${e.goal}.` : "";
|
|
1188
1335
|
return `The user accepted a proactive nudge that said: "${e.message}".${t} Recent friction signals are in the client context (friction_signals). Start helping with this now: briefly explain what you can do and take the first concrete step.`;
|
|
1189
1336
|
}
|
|
1190
|
-
var
|
|
1337
|
+
var Rt = 5e3, Tt = "/api/sdk/v1/proactive/events", It = class {
|
|
1191
1338
|
constructor(e) {
|
|
1192
|
-
if (this.queue = [], this.flushTimer = null, this.teardowns = [], this.destroyed = !1, this.post = e.post, this.agent = e.agent, this.flushIntervalMs = e.flushIntervalMs ??
|
|
1339
|
+
if (this.queue = [], this.flushTimer = null, this.teardowns = [], this.destroyed = !1, this.post = e.post, this.agent = e.agent, this.flushIntervalMs = e.flushIntervalMs ?? Rt, typeof document < "u") {
|
|
1193
1340
|
const t = () => {
|
|
1194
1341
|
document.visibilityState === "hidden" && this.flush({ keepalive: !0 });
|
|
1195
1342
|
};
|
|
@@ -1216,8 +1363,8 @@ var mt = 5e3, pt = "/api/sdk/v1/proactive/events", yt = class {
|
|
|
1216
1363
|
...this.agent ? { agent: this.agent } : {},
|
|
1217
1364
|
occurred_at: new Date(i.occurredAt).toISOString()
|
|
1218
1365
|
})) };
|
|
1219
|
-
this.post(
|
|
1220
|
-
|
|
1366
|
+
this.post(Tt, s, e).catch((i) => {
|
|
1367
|
+
c.debug("Proactive event batch failed:", i);
|
|
1221
1368
|
});
|
|
1222
1369
|
}
|
|
1223
1370
|
destroy() {
|
|
@@ -1227,81 +1374,81 @@ var mt = 5e3, pt = "/api/sdk/v1/proactive/events", yt = class {
|
|
|
1227
1374
|
this.teardowns = [];
|
|
1228
1375
|
}
|
|
1229
1376
|
}
|
|
1230
|
-
},
|
|
1231
|
-
function
|
|
1232
|
-
e.proactive && (
|
|
1233
|
-
const s = new
|
|
1377
|
+
}, oe = "friction_signals";
|
|
1378
|
+
function ae(e, t) {
|
|
1379
|
+
e.proactive && (c.warn("createAgoProactive: a proactive controller is already attached; replacing it."), e.proactive.destroy());
|
|
1380
|
+
const s = new ht({
|
|
1234
1381
|
...t.signals,
|
|
1235
1382
|
getPageState: () => {
|
|
1236
|
-
const
|
|
1237
|
-
if (!
|
|
1383
|
+
const l = e.getContextSnapshot();
|
|
1384
|
+
if (!l) return null;
|
|
1238
1385
|
const u = {};
|
|
1239
|
-
for (const [d,
|
|
1386
|
+
for (const [d, f] of Object.entries(l.entries)) d.startsWith("page-state:") && f.data && Object.assign(u, f.data);
|
|
1240
1387
|
return Object.keys(u).length > 0 ? u : null;
|
|
1241
1388
|
}
|
|
1242
1389
|
});
|
|
1243
1390
|
s.start();
|
|
1244
|
-
const i = (
|
|
1245
|
-
s.signalJsError(
|
|
1391
|
+
const i = (l) => {
|
|
1392
|
+
s.signalJsError(l.type);
|
|
1246
1393
|
};
|
|
1247
|
-
e.on("error:captured", i), e.addDynamicContext(
|
|
1248
|
-
const { pageState:
|
|
1394
|
+
e.on("error:captured", i), e.addDynamicContext(oe, () => {
|
|
1395
|
+
const { pageState: l, ...u } = s.getSnapshot({ pageState: !1 });
|
|
1249
1396
|
return {
|
|
1250
1397
|
name: "Friction signals",
|
|
1251
1398
|
description: "Behavioral friction observed on the current page: dwell/idle times, rage clicks, route bounces, repeated field errors, JavaScript error count (names and counters only).",
|
|
1252
1399
|
data: u
|
|
1253
1400
|
};
|
|
1254
1401
|
});
|
|
1255
|
-
const
|
|
1402
|
+
const n = new yt({
|
|
1256
1403
|
frequencyCap: t.frequencyCap,
|
|
1257
1404
|
storage: t.storage,
|
|
1258
1405
|
storageKey: t.storageKey
|
|
1259
|
-
}),
|
|
1260
|
-
post: (
|
|
1406
|
+
}), r = new It({
|
|
1407
|
+
post: (l, u, d) => e.getHttp().post(l, u, d),
|
|
1261
1408
|
agent: e.getConfiguredAgent()
|
|
1262
|
-
}),
|
|
1409
|
+
}), o = new Ct({
|
|
1263
1410
|
client: e,
|
|
1264
1411
|
collector: s,
|
|
1265
|
-
governor:
|
|
1266
|
-
tracker:
|
|
1412
|
+
governor: n,
|
|
1413
|
+
tracker: r,
|
|
1267
1414
|
options: t
|
|
1268
1415
|
});
|
|
1269
|
-
|
|
1270
|
-
const
|
|
1271
|
-
optOut: () =>
|
|
1272
|
-
optIn: () =>
|
|
1273
|
-
isOptedOut: () =>
|
|
1274
|
-
setEngaged: (
|
|
1275
|
-
signalFieldError: (
|
|
1416
|
+
o.start();
|
|
1417
|
+
const a = {
|
|
1418
|
+
optOut: () => n.optOut(),
|
|
1419
|
+
optIn: () => n.optIn(),
|
|
1420
|
+
isOptedOut: () => n.isOptedOut(),
|
|
1421
|
+
setEngaged: (l) => n.setEngaged(l),
|
|
1422
|
+
signalFieldError: (l) => s.signalFieldError(l),
|
|
1276
1423
|
getSignalsSnapshot: () => s.getSnapshot(),
|
|
1277
|
-
getActiveNudge: () =>
|
|
1278
|
-
shown: (
|
|
1279
|
-
accept: (
|
|
1280
|
-
dismiss: (
|
|
1281
|
-
markConverted: (
|
|
1424
|
+
getActiveNudge: () => o.getActiveNudge(),
|
|
1425
|
+
shown: (l) => o.shown(l),
|
|
1426
|
+
accept: (l) => o.accept(l),
|
|
1427
|
+
dismiss: (l) => o.dismiss(l),
|
|
1428
|
+
markConverted: (l) => o.markConverted(l),
|
|
1282
1429
|
destroy: () => {
|
|
1283
|
-
|
|
1430
|
+
o.stop(), r.destroy(), e.off("error:captured", i), s.destroy(), e.removeDynamicContext(oe), e.proactive === a && (e.proactive = null);
|
|
1284
1431
|
}
|
|
1285
1432
|
};
|
|
1286
|
-
return e.proactive =
|
|
1433
|
+
return e.proactive = a, a;
|
|
1287
1434
|
}
|
|
1288
|
-
var
|
|
1435
|
+
var xt = class {
|
|
1289
1436
|
constructor() {
|
|
1290
1437
|
this.entries = /* @__PURE__ */ new Map(), this.dynamicProviders = /* @__PURE__ */ new Map();
|
|
1291
1438
|
}
|
|
1292
1439
|
set(e, t) {
|
|
1293
|
-
this.entries.set(e, t),
|
|
1440
|
+
this.entries.set(e, t), c.log(`ClientContext set: ${e}`);
|
|
1294
1441
|
}
|
|
1295
1442
|
remove(e) {
|
|
1296
1443
|
const t = this.entries.delete(e);
|
|
1297
|
-
return t &&
|
|
1444
|
+
return t && c.log(`ClientContext removed: ${e}`), t;
|
|
1298
1445
|
}
|
|
1299
1446
|
addDynamicProvider(e, t) {
|
|
1300
|
-
this.dynamicProviders.set(e, t),
|
|
1447
|
+
this.dynamicProviders.set(e, t), c.log(`DynamicContext provider added: ${e}`);
|
|
1301
1448
|
}
|
|
1302
1449
|
removeDynamicProvider(e) {
|
|
1303
1450
|
const t = this.dynamicProviders.delete(e);
|
|
1304
|
-
return t &&
|
|
1451
|
+
return t && c.log(`DynamicContext provider removed: ${e}`), t;
|
|
1305
1452
|
}
|
|
1306
1453
|
getSnapshot() {
|
|
1307
1454
|
if (this.entries.size === 0 && this.dynamicProviders.size === 0) return null;
|
|
@@ -1311,69 +1458,69 @@ var vt = class {
|
|
|
1311
1458
|
const i = s();
|
|
1312
1459
|
i && (e[t] = i);
|
|
1313
1460
|
} catch (i) {
|
|
1314
|
-
|
|
1461
|
+
c.error(`DynamicContext provider "${t}" threw:`, i);
|
|
1315
1462
|
}
|
|
1316
1463
|
return Object.keys(e).length === 0 ? null : { entries: e };
|
|
1317
1464
|
}
|
|
1318
1465
|
clear() {
|
|
1319
|
-
this.entries.clear(), this.dynamicProviders.clear(),
|
|
1466
|
+
this.entries.clear(), this.dynamicProviders.clear(), c.log("ClientContext cleared");
|
|
1320
1467
|
}
|
|
1321
|
-
},
|
|
1322
|
-
function
|
|
1468
|
+
}, Ft = "page-state:";
|
|
1469
|
+
function Dt(e) {
|
|
1323
1470
|
const t = {};
|
|
1324
|
-
for (const [s, i] of Object.entries(e)) s.startsWith(
|
|
1471
|
+
for (const [s, i] of Object.entries(e)) s.startsWith(Ft) && i.data && Object.assign(t, i.data);
|
|
1325
1472
|
return t;
|
|
1326
1473
|
}
|
|
1327
|
-
function
|
|
1474
|
+
function $t(e) {
|
|
1328
1475
|
const t = e["current-page"]?.data;
|
|
1329
1476
|
return t?.page ? t.page : t?.url ? t.url : e["browser-page"]?.data?.url;
|
|
1330
1477
|
}
|
|
1331
|
-
function
|
|
1478
|
+
function Mt(e, t) {
|
|
1332
1479
|
return e === t ? !0 : JSON.stringify(e) === JSON.stringify(t);
|
|
1333
1480
|
}
|
|
1334
|
-
function
|
|
1481
|
+
function Pt(e, t) {
|
|
1335
1482
|
const s = [];
|
|
1336
1483
|
for (const i of Object.keys(t))
|
|
1337
|
-
i in e && (
|
|
1484
|
+
i in e && (Mt(e[i], t[i]) || s.push({
|
|
1338
1485
|
field: i,
|
|
1339
1486
|
from: e[i],
|
|
1340
1487
|
to: t[i]
|
|
1341
1488
|
}));
|
|
1342
1489
|
return s;
|
|
1343
1490
|
}
|
|
1344
|
-
function
|
|
1345
|
-
const s =
|
|
1491
|
+
function Nt(e, t) {
|
|
1492
|
+
const s = Dt(t), i = $t(t);
|
|
1346
1493
|
return {
|
|
1347
|
-
changes: e && e.page === i ?
|
|
1494
|
+
changes: e && e.page === i ? Pt(e.state, s) : [],
|
|
1348
1495
|
baseline: {
|
|
1349
1496
|
page: i,
|
|
1350
1497
|
state: s
|
|
1351
1498
|
}
|
|
1352
1499
|
};
|
|
1353
1500
|
}
|
|
1354
|
-
function
|
|
1355
|
-
return e === null || typeof e != "object" ? JSON.stringify(e) ?? "null" : Array.isArray(e) ? `[${e.map(
|
|
1501
|
+
function q(e) {
|
|
1502
|
+
return e === null || typeof e != "object" ? JSON.stringify(e) ?? "null" : Array.isArray(e) ? `[${e.map(q).join(",")}]` : `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${q(e[t])}`).join(",")}}`;
|
|
1356
1503
|
}
|
|
1357
|
-
var
|
|
1504
|
+
var ce = "", Ot = class {
|
|
1358
1505
|
constructor(e, t = {}) {
|
|
1359
1506
|
this.callbacks = e, this.options = t, this.buffer = "", this.message = {}, this.toolCalls = [], this.sources = [], this.followUpReplies = [], this.isFirstChunk = !0, this.answerCompleteEmitted = !1, this.waitingClientEmitted = !1, this.firedClientFunctions = /* @__PURE__ */ new Map();
|
|
1360
1507
|
}
|
|
1361
1508
|
async processStream(e) {
|
|
1362
|
-
if (!e.body) throw new
|
|
1509
|
+
if (!e.body) throw new X("Response has no body. The endpoint did not return a stream: check that `baseUrl` points at an AGO API and nothing (proxy, mock) strips the SSE body.", "stream_no_body");
|
|
1363
1510
|
const t = e.body.getReader(), s = new TextDecoder();
|
|
1364
1511
|
try {
|
|
1365
1512
|
for (; ; ) {
|
|
1366
|
-
const { done: i, value:
|
|
1513
|
+
const { done: i, value: n } = await t.read();
|
|
1367
1514
|
if (i) break;
|
|
1368
|
-
const
|
|
1369
|
-
this.buffer +=
|
|
1515
|
+
const r = s.decode(n, { stream: !0 });
|
|
1516
|
+
this.buffer += r, this.processBuffer();
|
|
1370
1517
|
}
|
|
1371
1518
|
return this.buffer.trim() && this.processBuffer(), this.buildFinalMessage();
|
|
1372
1519
|
} catch (i) {
|
|
1373
1520
|
if (this.options.signal?.aborted)
|
|
1374
1521
|
return this.message.status = "CANCELED", this.buildFinalMessage();
|
|
1375
|
-
const
|
|
1376
|
-
throw this.callbacks.onError?.(
|
|
1522
|
+
const n = i instanceof Error ? i : new X("Stream processing failed mid-flight. The connection may have dropped; retry the message.");
|
|
1523
|
+
throw this.callbacks.onError?.(n), n;
|
|
1377
1524
|
} finally {
|
|
1378
1525
|
t.releaseLock();
|
|
1379
1526
|
}
|
|
@@ -1389,12 +1536,12 @@ var ne = "", At = class {
|
|
|
1389
1536
|
`);
|
|
1390
1537
|
for (const i of s)
|
|
1391
1538
|
if (!i.startsWith(": ") && i.startsWith("data: ")) {
|
|
1392
|
-
const
|
|
1539
|
+
const n = i.slice(6);
|
|
1393
1540
|
try {
|
|
1394
|
-
const
|
|
1395
|
-
this.handleChunk(
|
|
1396
|
-
} catch (
|
|
1397
|
-
|
|
1541
|
+
const r = JSON.parse(n);
|
|
1542
|
+
this.handleChunk(r);
|
|
1543
|
+
} catch (r) {
|
|
1544
|
+
c.warn("Failed to parse SSE data:", n, r);
|
|
1398
1545
|
}
|
|
1399
1546
|
}
|
|
1400
1547
|
}
|
|
@@ -1422,9 +1569,9 @@ var ne = "", At = class {
|
|
|
1422
1569
|
url: s.use_external_link ? s.external_link_url : s.internal_link_url
|
|
1423
1570
|
};
|
|
1424
1571
|
})), e.type === "client_function" && e.function_name) {
|
|
1425
|
-
const t = `${e.function_name}::${
|
|
1426
|
-
let
|
|
1427
|
-
i ? s && !i.has(s) && (i.has(
|
|
1572
|
+
const t = `${e.function_name}::${q(e.arguments ?? {})}`, s = e.id || "", i = this.firedClientFunctions.get(t);
|
|
1573
|
+
let n = !1;
|
|
1574
|
+
i ? s && !i.has(s) && (i.has(ce) ? (i.delete(ce), i.add(s)) : (i.add(s), n = !0)) : (this.firedClientFunctions.set(t, /* @__PURE__ */ new Set([s])), n = !0), n && this.callbacks.onClientFunction?.({
|
|
1428
1575
|
invocationId: s,
|
|
1429
1576
|
functionName: e.function_name,
|
|
1430
1577
|
arguments: e.arguments || {},
|
|
@@ -1484,11 +1631,11 @@ var ne = "", At = class {
|
|
|
1484
1631
|
return e.status !== "WAITING_CLIENT" && this.callbacks.onComplete?.(e), e;
|
|
1485
1632
|
}
|
|
1486
1633
|
};
|
|
1487
|
-
function
|
|
1634
|
+
function ns(e) {
|
|
1488
1635
|
const t = e.message.toLowerCase();
|
|
1489
1636
|
return t.includes("load failed") || t.includes("failed to fetch") || t.includes("network") || t.includes("abort");
|
|
1490
1637
|
}
|
|
1491
|
-
var
|
|
1638
|
+
var Lt = /* @__PURE__ */ new Set([
|
|
1492
1639
|
"image/jpeg",
|
|
1493
1640
|
"image/png",
|
|
1494
1641
|
"image/gif",
|
|
@@ -1496,7 +1643,7 @@ var kt = /* @__PURE__ */ new Set([
|
|
|
1496
1643
|
"image/bmp",
|
|
1497
1644
|
"image/tiff"
|
|
1498
1645
|
]);
|
|
1499
|
-
function
|
|
1646
|
+
function jt(e) {
|
|
1500
1647
|
if (!e) return;
|
|
1501
1648
|
const t = typeof window < "u" && window.location ? window.location.href : "https://ago.local/";
|
|
1502
1649
|
try {
|
|
@@ -1505,16 +1652,16 @@ function Rt(e) {
|
|
|
1505
1652
|
} catch {
|
|
1506
1653
|
}
|
|
1507
1654
|
}
|
|
1508
|
-
function
|
|
1509
|
-
return e.isSafeImage === !0 && typeof e.contentType == "string" && e.contentType.startsWith("image/") &&
|
|
1655
|
+
function rs(e) {
|
|
1656
|
+
return e.isSafeImage === !0 && typeof e.contentType == "string" && e.contentType.startsWith("image/") && jt(e.url) !== void 0;
|
|
1510
1657
|
}
|
|
1511
|
-
function
|
|
1658
|
+
function os(e) {
|
|
1512
1659
|
if (e == null || e < 0) return "";
|
|
1513
1660
|
if (e < 1024) return `${e} B`;
|
|
1514
1661
|
const t = e / 1024;
|
|
1515
1662
|
return t < 1024 ? `${t.toFixed(1)} KB` : `${(t / 1024).toFixed(1)} MB`;
|
|
1516
1663
|
}
|
|
1517
|
-
function
|
|
1664
|
+
function Ut(e) {
|
|
1518
1665
|
return {
|
|
1519
1666
|
id: String(e.id ?? ""),
|
|
1520
1667
|
name: typeof e.name == "string" && e.name ? e.name : "file",
|
|
@@ -1524,17 +1671,17 @@ function Tt(e) {
|
|
|
1524
1671
|
isSafeImage: e.is_safe_image === !0
|
|
1525
1672
|
};
|
|
1526
1673
|
}
|
|
1527
|
-
function
|
|
1674
|
+
function as(e) {
|
|
1528
1675
|
return e.map((t, s) => ({
|
|
1529
1676
|
id: `local-${s}-${t.name}`,
|
|
1530
1677
|
name: t.name,
|
|
1531
1678
|
contentType: t.type || void 0,
|
|
1532
1679
|
fileSize: t.size,
|
|
1533
1680
|
url: typeof URL < "u" && URL.createObjectURL ? URL.createObjectURL(t) : void 0,
|
|
1534
|
-
isSafeImage:
|
|
1681
|
+
isSafeImage: Lt.has(t.type)
|
|
1535
1682
|
}));
|
|
1536
1683
|
}
|
|
1537
|
-
var
|
|
1684
|
+
var Wt = class {
|
|
1538
1685
|
constructor() {
|
|
1539
1686
|
this.handlers = /* @__PURE__ */ new Map();
|
|
1540
1687
|
}
|
|
@@ -1550,8 +1697,8 @@ var It = class {
|
|
|
1550
1697
|
s && s.forEach((i) => {
|
|
1551
1698
|
try {
|
|
1552
1699
|
i(t);
|
|
1553
|
-
} catch (
|
|
1554
|
-
console.error(`Error in event handler for ${String(e)}:`,
|
|
1700
|
+
} catch (n) {
|
|
1701
|
+
console.error(`Error in event handler for ${String(e)}:`, n);
|
|
1555
1702
|
}
|
|
1556
1703
|
});
|
|
1557
1704
|
}
|
|
@@ -1563,235 +1710,236 @@ var It = class {
|
|
|
1563
1710
|
}
|
|
1564
1711
|
waitFor(e, t) {
|
|
1565
1712
|
return new Promise((s, i) => {
|
|
1566
|
-
let
|
|
1567
|
-
const
|
|
1568
|
-
|
|
1713
|
+
let n;
|
|
1714
|
+
const r = ((o) => {
|
|
1715
|
+
n && clearTimeout(n), s(o);
|
|
1569
1716
|
});
|
|
1570
|
-
this.once(e,
|
|
1571
|
-
this.off(e,
|
|
1717
|
+
this.once(e, r), t?.timeout && (n = setTimeout(() => {
|
|
1718
|
+
this.off(e, r), i(/* @__PURE__ */ new Error(`waitFor("${String(e)}") timed out after ${t.timeout}ms`));
|
|
1572
1719
|
}, t.timeout));
|
|
1573
1720
|
});
|
|
1574
1721
|
}
|
|
1575
1722
|
removeAllListeners(e) {
|
|
1576
1723
|
e ? this.handlers.delete(e) : this.handlers.clear();
|
|
1577
1724
|
}
|
|
1578
|
-
},
|
|
1579
|
-
function
|
|
1725
|
+
}, Bt = 4e3, Gt = 150, qt = 600;
|
|
1726
|
+
function Kt() {
|
|
1580
1727
|
if (!(typeof document > "u"))
|
|
1581
1728
|
return document.modelContext;
|
|
1582
1729
|
}
|
|
1583
|
-
function
|
|
1730
|
+
function Jt(e, t) {
|
|
1584
1731
|
return new Promise((s) => {
|
|
1585
|
-
let i,
|
|
1586
|
-
const
|
|
1587
|
-
if (!
|
|
1588
|
-
|
|
1589
|
-
for (const d of t) d?.removeEventListener("abort",
|
|
1732
|
+
let i, n = !1;
|
|
1733
|
+
const r = () => {
|
|
1734
|
+
if (!n) {
|
|
1735
|
+
n = !0, clearTimeout(i), clearTimeout(l), clearTimeout(a);
|
|
1736
|
+
for (const d of t) d?.removeEventListener("abort", r);
|
|
1590
1737
|
u(), s();
|
|
1591
1738
|
}
|
|
1592
|
-
},
|
|
1593
|
-
clearTimeout(
|
|
1594
|
-
},
|
|
1739
|
+
}, o = () => {
|
|
1740
|
+
clearTimeout(l), clearTimeout(i), i = setTimeout(r, Gt);
|
|
1741
|
+
}, a = setTimeout(r, Bt), l = setTimeout(r, qt), u = e(o);
|
|
1595
1742
|
for (const d of t) {
|
|
1596
|
-
if (d?.aborted) return
|
|
1597
|
-
d?.addEventListener("abort",
|
|
1743
|
+
if (d?.aborted) return r();
|
|
1744
|
+
d?.addEventListener("abort", r);
|
|
1598
1745
|
}
|
|
1599
1746
|
});
|
|
1600
1747
|
}
|
|
1601
|
-
function
|
|
1602
|
-
const t =
|
|
1748
|
+
function Ht(e) {
|
|
1749
|
+
const t = Kt();
|
|
1603
1750
|
if (!t)
|
|
1604
|
-
return
|
|
1751
|
+
return c.log("WebMCP is not available in this browser; bridge not attached"), () => {
|
|
1605
1752
|
};
|
|
1606
|
-
const s = t, i = /* @__PURE__ */ new Map(),
|
|
1607
|
-
let
|
|
1608
|
-
function
|
|
1753
|
+
const s = t, i = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = new AbortController();
|
|
1754
|
+
let o = !1, a = !1;
|
|
1755
|
+
function l(p) {
|
|
1609
1756
|
return JSON.stringify([
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1757
|
+
p.description,
|
|
1758
|
+
p.inputSchema,
|
|
1759
|
+
p.annotations
|
|
1613
1760
|
]);
|
|
1614
1761
|
}
|
|
1615
|
-
function u(
|
|
1616
|
-
const
|
|
1617
|
-
return !
|
|
1762
|
+
function u(p, h) {
|
|
1763
|
+
const g = e.getFunctionRegistrations().find((y) => y.name === p)?.webmcp;
|
|
1764
|
+
return !g || !g.navigates ? !1 : h?.success !== !1;
|
|
1618
1765
|
}
|
|
1619
1766
|
function d() {
|
|
1620
|
-
const
|
|
1767
|
+
const p = /* @__PURE__ */ new Map();
|
|
1621
1768
|
for (const h of e.getFunctionRegistrations()) {
|
|
1622
1769
|
if (h.webmcp === !1) continue;
|
|
1623
|
-
const
|
|
1770
|
+
const g = h.webmcp || void 0, y = h.name, b = {
|
|
1624
1771
|
name: y,
|
|
1625
1772
|
description: h.schema.description,
|
|
1626
1773
|
inputSchema: h.schema.parameters,
|
|
1627
|
-
annotations:
|
|
1628
|
-
execute: async (w,
|
|
1629
|
-
const
|
|
1630
|
-
return !
|
|
1774
|
+
annotations: g?.annotations,
|
|
1775
|
+
execute: async (w, _e) => {
|
|
1776
|
+
const z = await e.runExternalFunction(y, w ?? {});
|
|
1777
|
+
return !o && u(y, z) && await Jt((Ce) => e.onFunctionsChanged(Ce), [_e?.signal, r.signal]), z;
|
|
1631
1778
|
}
|
|
1632
1779
|
};
|
|
1633
|
-
|
|
1780
|
+
p.set(y, {
|
|
1634
1781
|
tool: b,
|
|
1635
|
-
signature:
|
|
1782
|
+
signature: l(b)
|
|
1636
1783
|
});
|
|
1637
1784
|
}
|
|
1638
|
-
return
|
|
1785
|
+
return p;
|
|
1639
1786
|
}
|
|
1640
|
-
function
|
|
1641
|
-
|
|
1642
|
-
|
|
1787
|
+
function f() {
|
|
1788
|
+
o || a || (a = !0, queueMicrotask(() => {
|
|
1789
|
+
a = !1, m();
|
|
1643
1790
|
}));
|
|
1644
1791
|
}
|
|
1645
1792
|
function m() {
|
|
1646
|
-
if (
|
|
1647
|
-
const
|
|
1648
|
-
for (const [h,
|
|
1649
|
-
|
|
1650
|
-
for (const [h,
|
|
1793
|
+
if (o) return;
|
|
1794
|
+
const p = d();
|
|
1795
|
+
for (const [h, g] of i)
|
|
1796
|
+
p.get(h)?.signature !== g.signature && (g.controller.abort(), i.delete(h));
|
|
1797
|
+
for (const [h, g] of p) {
|
|
1651
1798
|
if (i.has(h)) continue;
|
|
1652
1799
|
const y = new AbortController();
|
|
1653
1800
|
i.set(h, {
|
|
1654
|
-
signature:
|
|
1801
|
+
signature: g.signature,
|
|
1655
1802
|
controller: y
|
|
1656
|
-
}), Promise.resolve(s.registerTool(
|
|
1657
|
-
if (
|
|
1803
|
+
}), Promise.resolve(s.registerTool(g.tool, { signal: y.signal })).catch((b) => {
|
|
1804
|
+
if (c.error(`WebMCP rejected the tool "${h}":`, b), i.get(h)?.controller !== y) return;
|
|
1658
1805
|
i.delete(h);
|
|
1659
|
-
const w = JSON.stringify([h,
|
|
1660
|
-
|
|
1806
|
+
const w = JSON.stringify([h, g.signature]);
|
|
1807
|
+
n.has(w) || (n.add(w), f());
|
|
1661
1808
|
});
|
|
1662
1809
|
}
|
|
1663
1810
|
}
|
|
1664
|
-
const v = e.onFunctionsChanged(
|
|
1665
|
-
return m(),
|
|
1666
|
-
if (!
|
|
1667
|
-
|
|
1668
|
-
for (const
|
|
1669
|
-
i.clear(),
|
|
1811
|
+
const v = e.onFunctionsChanged(f);
|
|
1812
|
+
return m(), c.log("WebMCP bridge attached"), () => {
|
|
1813
|
+
if (!o) {
|
|
1814
|
+
o = !0, r.abort(), v();
|
|
1815
|
+
for (const p of i.values()) p.controller.abort();
|
|
1816
|
+
i.clear(), c.log("WebMCP bridge detached");
|
|
1670
1817
|
}
|
|
1671
1818
|
};
|
|
1672
1819
|
}
|
|
1673
|
-
var
|
|
1674
|
-
function
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
function M(e) {
|
|
1684
|
-
return e.split("/").filter((t) => t.startsWith(":")).map((t) => t.slice(1));
|
|
1820
|
+
var zt = "/api/sdk/v1/client-function-calls", le = "ago_webmcp_tab";
|
|
1821
|
+
function Xt() {
|
|
1822
|
+
try {
|
|
1823
|
+
const e = sessionStorage.getItem(le);
|
|
1824
|
+
if (e) return e;
|
|
1825
|
+
const t = x();
|
|
1826
|
+
return sessionStorage.setItem(le, t), t;
|
|
1827
|
+
} catch {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1685
1830
|
}
|
|
1686
|
-
function
|
|
1687
|
-
const s =
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1831
|
+
function Vt(e, t) {
|
|
1832
|
+
const { name: s } = t.schema, i = Xt(), n = {
|
|
1833
|
+
function_name: s,
|
|
1834
|
+
arguments: t.args,
|
|
1835
|
+
result: t.error === void 0 ? t.result ?? null : null,
|
|
1836
|
+
error: t.error ?? null,
|
|
1837
|
+
duration_ms: t.durationMs,
|
|
1838
|
+
...i ? { tab_id: i } : {},
|
|
1839
|
+
...e.declared.has(s) ? {} : { client_functions: [t.schema] }
|
|
1695
1840
|
};
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
const i = t.find((r) => {
|
|
1701
|
-
if (!r.path.includes(":")) return !1;
|
|
1702
|
-
const n = "^" + r.path.split("/").map((a) => a.startsWith(":") ? "[^/]+" : Ot(a)).join("/") + "/?$";
|
|
1703
|
-
return new RegExp(n).test(e);
|
|
1841
|
+
e.post(zt, n, t.navigates ? { keepalive: !0 } : void 0).then(() => {
|
|
1842
|
+
e.declared.add(s);
|
|
1843
|
+
}).catch((r) => {
|
|
1844
|
+
c.debug("External call report failed:", r);
|
|
1704
1845
|
});
|
|
1705
|
-
return i || t.filter((r) => r.path !== "/" && e.startsWith(r.path)).sort((r, n) => n.path.length - r.path.length)[0];
|
|
1706
1846
|
}
|
|
1707
|
-
var
|
|
1708
|
-
function
|
|
1847
|
+
var ue = '`baseUrl` is required, e.g. new AgoClient({ baseUrl: "https://YOUR-DOMAIN.api.useago.com" }). Try the public demo account https://playground.api.useago.com (agent generic-guide). See docs/general/configuration.md#error-codes (config_missing_base_url).', Yt = /^[a-z][a-z0-9+.-]*:\/\//i, de = !1;
|
|
1848
|
+
function he(e, t = "AgoClient") {
|
|
1849
|
+
if (typeof e != "object" || e === null) throw new S(`${t}: ${ue}`, "config_missing_base_url");
|
|
1850
|
+
const s = e.baseUrl;
|
|
1851
|
+
if (typeof s != "string" || s.trim() === "") throw new S(`${t}: ${ue}`, "config_missing_base_url");
|
|
1852
|
+
N(e.language), !s.startsWith("/") && !Yt.test(s) && (de || (de = !0, console.warn(`[AGO] ${t}: \`baseUrl\` has no protocol and is not a relative path (config_suspect_base_url). Requests will fail: Node throws a URL parse error, browsers fetch it as a relative path. Use "https://..." (or a "/path" for a same-origin proxy).`)));
|
|
1853
|
+
}
|
|
1854
|
+
var Qt = "activity:recent", Zt = "state:delta", ge = "errors:recent";
|
|
1855
|
+
function fe(e) {
|
|
1709
1856
|
return e === "setPageState" ? "readPageData" : `read${e.charAt(0).toUpperCase()}${e.slice(1)}Data`;
|
|
1710
1857
|
}
|
|
1711
|
-
var
|
|
1858
|
+
var cs = class R {
|
|
1712
1859
|
constructor(t) {
|
|
1713
|
-
this.errorWatcher = null, this.lastSentPageState = null, this.warnedEmptyConversations = /* @__PURE__ */ new Set(), this.warnedPageDataPlaceholder = !1, this.pageDataCompanions = /* @__PURE__ */ new Set(), this.pendingResumes = /* @__PURE__ */ new Map(), this.pendingApprovals = /* @__PURE__ */ new Map(), this.resumeGate = null, this.activeTurn = null, this.pausedTurn = null, this.stoppedTurnIds = /* @__PURE__ */ new Set(), this.proactive = null, this.detachWebMCP = null,
|
|
1860
|
+
this.errorWatcher = null, this.lastSentPageState = null, this.warnedEmptyConversations = /* @__PURE__ */ new Set(), this.declaredExternally = /* @__PURE__ */ new Set(), this.warnedPageDataPlaceholder = !1, this.pageDataCompanions = /* @__PURE__ */ new Set(), this.pendingResumes = /* @__PURE__ */ new Map(), this.pendingApprovals = /* @__PURE__ */ new Map(), this.resumeGate = null, this.activeTurn = null, this.pausedTurn = null, this.stoppedTurnIds = /* @__PURE__ */ new Set(), this.proactive = null, this.detachWebMCP = null, this.listPagesRegistered = !1, he(t, "AgoClient"), this.config = t, this.activityLedger = new ke(t.maxActivityEntries), this.httpClient = new Ie(t), this.functionRegistry = new Le({ maxResultBytes: t.maxFunctionResultBytes }), this.contextRegistry = new xt(), this.eventEmitter = new Wt(), this.registerActivityContext(), this.functionRegistry.onChange(() => {
|
|
1714
1861
|
this.eventEmitter.emit("functions:changed", this.functionRegistry.getSchemas());
|
|
1715
|
-
}), t.debug &&
|
|
1862
|
+
}), t.debug && c.enable(), t.errorWatcher && this.enableErrorWatcher(t.errorWatcher === !0 ? void 0 : t.errorWatcher), t.proactive && ae(this, t.proactive), this.attachWebMCPBridge(), c.log("AgoClient initialized");
|
|
1716
1863
|
}
|
|
1717
1864
|
attachWebMCPBridge() {
|
|
1718
|
-
!this.config.webmcp || this.detachWebMCP || (this.detachWebMCP =
|
|
1865
|
+
!this.config.webmcp || this.detachWebMCP || (this.detachWebMCP = Ht(this));
|
|
1719
1866
|
}
|
|
1720
1867
|
async sendMessage(t, s) {
|
|
1721
|
-
|
|
1868
|
+
if (typeof t != "string" || !t.trim()) throw new S("Add message text before sending, including when attaching files. See docs/general/core.md#file-attachments.", "message_empty_content");
|
|
1869
|
+
const i = this.functionRegistry.getSchemas(), n = this.buildSendContext(), r = this.config.agent || this.config.defaultAgentId, o = this.resolveClientFunctionsMode(s), a = s?.metadata !== void 0 ? s.metadata : this.config.metadata, l = a != null ? JSON.stringify(a) : void 0, u = {
|
|
1722
1870
|
content: t,
|
|
1723
1871
|
conversation_id: s?.conversationId,
|
|
1724
|
-
agent_id: s?.agentId ||
|
|
1872
|
+
agent_id: s?.agentId || r
|
|
1725
1873
|
};
|
|
1726
|
-
|
|
1874
|
+
a != null && (u.metadata = a), i.length > 0 && (u.client_functions = i, o === "pause" && (u.client_functions_mode = o)), n && (u.client_context = n), s?.hidden && (u.hidden = !0);
|
|
1727
1875
|
const d = this.beginTurn();
|
|
1728
|
-
let
|
|
1876
|
+
let f;
|
|
1729
1877
|
if (s?.files && s.files.length > 0) {
|
|
1730
1878
|
const m = new FormData();
|
|
1731
|
-
m.append("content", t),
|
|
1879
|
+
m.append("content", t), l !== void 0 && m.append("metadata", l), s.conversationId && m.append("conversation_id", s.conversationId), (s.agentId || r) && m.append("agent_id", s.agentId || r || ""), i.length > 0 && (m.append("client_functions", JSON.stringify(i)), o === "pause" && m.append("client_functions_mode", o)), n && m.append("client_context", JSON.stringify(n)), s.hidden && m.append("hidden", "true");
|
|
1732
1880
|
for (const v of s.files) m.append("files", v);
|
|
1733
|
-
|
|
1734
|
-
} else
|
|
1735
|
-
return
|
|
1881
|
+
f = await this.sendRequest(d, () => this.httpClient.postFormData("/api/sdk/v1/messages", m, { signal: d.controller.signal }));
|
|
1882
|
+
} else f = await this.sendRequest(d, () => this.httpClient.postStream("/api/sdk/v1/messages", u, { signal: d.controller.signal }));
|
|
1883
|
+
return f ? this.processSSEResponse(f, d) : this.buildStoppedMessage(d);
|
|
1736
1884
|
}
|
|
1737
1885
|
async sendRequest(t, s) {
|
|
1738
1886
|
try {
|
|
1739
1887
|
return await s();
|
|
1740
1888
|
} catch (i) {
|
|
1741
|
-
if (this.endTurn(t),
|
|
1889
|
+
if (this.endTurn(t), O(i)) return null;
|
|
1742
1890
|
throw i;
|
|
1743
1891
|
}
|
|
1744
1892
|
}
|
|
1745
1893
|
async processSSEResponse(t, s) {
|
|
1746
1894
|
let i = !1;
|
|
1747
|
-
const
|
|
1748
|
-
onRawChunk: (
|
|
1749
|
-
s && (
|
|
1895
|
+
const n = new Ot({
|
|
1896
|
+
onRawChunk: (r) => {
|
|
1897
|
+
s && (r.message_id && !s.messageId && (s.messageId = r.message_id), r.thread?.id && (s.conversationId = r.thread.id)), this.eventEmitter.emit("stream:message", r);
|
|
1750
1898
|
},
|
|
1751
|
-
onStart: (
|
|
1752
|
-
this.eventEmitter.emit("message:start",
|
|
1899
|
+
onStart: (r) => {
|
|
1900
|
+
this.eventEmitter.emit("message:start", r);
|
|
1753
1901
|
},
|
|
1754
|
-
onChunk: (
|
|
1755
|
-
this.eventEmitter.emit("message:chunk",
|
|
1902
|
+
onChunk: (r) => {
|
|
1903
|
+
this.eventEmitter.emit("message:chunk", r);
|
|
1756
1904
|
},
|
|
1757
|
-
onToolCall: (
|
|
1758
|
-
this.eventEmitter.emit("toolCall:received",
|
|
1905
|
+
onToolCall: (r) => {
|
|
1906
|
+
this.eventEmitter.emit("toolCall:received", r), r.type === "form" && this.eventEmitter.emit("toolCall:form", r);
|
|
1759
1907
|
},
|
|
1760
|
-
onClientFunction: async (
|
|
1761
|
-
if (i = !0, this.eventEmitter.emit("function:invoke",
|
|
1762
|
-
this.pendingApprovals.set(
|
|
1908
|
+
onClientFunction: async (r) => {
|
|
1909
|
+
if (i = !0, this.eventEmitter.emit("function:invoke", r), this.recordAgentAction(r), r.invocationId && this.requiresApproval(r)) {
|
|
1910
|
+
this.pendingApprovals.set(r.invocationId, r), this.eventEmitter.emit("function:awaiting-approval", r);
|
|
1763
1911
|
return;
|
|
1764
1912
|
}
|
|
1765
|
-
await this.handleClientFunctionInvocation(
|
|
1913
|
+
await this.handleClientFunctionInvocation(r);
|
|
1766
1914
|
},
|
|
1767
|
-
onTitle: (
|
|
1768
|
-
this.eventEmitter.emit("conversation:title",
|
|
1915
|
+
onTitle: (r) => {
|
|
1916
|
+
this.eventEmitter.emit("conversation:title", r);
|
|
1769
1917
|
},
|
|
1770
|
-
onAnswerComplete: (
|
|
1771
|
-
this.eventEmitter.emit("message:answer-complete",
|
|
1918
|
+
onAnswerComplete: (r) => {
|
|
1919
|
+
this.eventEmitter.emit("message:answer-complete", r);
|
|
1772
1920
|
},
|
|
1773
|
-
onWaitingClient: (
|
|
1921
|
+
onWaitingClient: (r) => {
|
|
1774
1922
|
this.pausedTurn = {
|
|
1775
|
-
messageId:
|
|
1776
|
-
conversationId:
|
|
1777
|
-
}, this.eventEmitter.emit("message:waiting-client",
|
|
1923
|
+
messageId: r.messageId,
|
|
1924
|
+
conversationId: r.conversationId
|
|
1925
|
+
}, this.eventEmitter.emit("message:waiting-client", r), this.markResumeSignal(r.messageId, r.conversationId, "waitingConfirmed");
|
|
1778
1926
|
},
|
|
1779
|
-
onComplete: (
|
|
1780
|
-
s?.stopRequested && !
|
|
1927
|
+
onComplete: (r) => {
|
|
1928
|
+
s?.stopRequested && !r.id || this.eventEmitter.emit("message:complete", r);
|
|
1781
1929
|
},
|
|
1782
|
-
onError: (
|
|
1930
|
+
onError: (r) => {
|
|
1783
1931
|
this.eventEmitter.emit("message:error", {
|
|
1784
|
-
error:
|
|
1785
|
-
code:
|
|
1932
|
+
error: r.message,
|
|
1933
|
+
code: r instanceof S ? r.code : void 0
|
|
1786
1934
|
});
|
|
1787
1935
|
}
|
|
1788
1936
|
}, { signal: s?.controller.signal });
|
|
1789
1937
|
try {
|
|
1790
|
-
const
|
|
1791
|
-
return s?.stopRequested && (this.postStopForTurn(s, s.messageId ??
|
|
1792
|
-
conversationId: s.conversationId ??
|
|
1793
|
-
messageId: s.messageId ??
|
|
1794
|
-
})),
|
|
1938
|
+
const r = await n.processStream(t);
|
|
1939
|
+
return s?.stopRequested && (this.postStopForTurn(s, s.messageId ?? r.id), this.eventEmitter.emit("message:stopped", {
|
|
1940
|
+
conversationId: s.conversationId ?? r.conversationId ?? "",
|
|
1941
|
+
messageId: s.messageId ?? r.id ?? ""
|
|
1942
|
+
})), r.status !== "WAITING_CLIENT" && this.maybeFlagEmptyReply(r, i), r;
|
|
1795
1943
|
} finally {
|
|
1796
1944
|
s && this.endTurn(s);
|
|
1797
1945
|
}
|
|
@@ -1800,8 +1948,8 @@ var Vt = class k {
|
|
|
1800
1948
|
const t = this.activeTurn;
|
|
1801
1949
|
if (t) {
|
|
1802
1950
|
t.stopRequested = !0;
|
|
1803
|
-
const
|
|
1804
|
-
return t.controller.abort(),
|
|
1951
|
+
const n = t.messageId;
|
|
1952
|
+
return t.controller.abort(), n ? this.postStopForTurn(t, n) : null;
|
|
1805
1953
|
}
|
|
1806
1954
|
const s = this.pausedTurn;
|
|
1807
1955
|
if (!s) return null;
|
|
@@ -1809,8 +1957,8 @@ var Vt = class k {
|
|
|
1809
1957
|
let i = null;
|
|
1810
1958
|
try {
|
|
1811
1959
|
i = await this.stopMessage(s.messageId);
|
|
1812
|
-
} catch (
|
|
1813
|
-
|
|
1960
|
+
} catch (n) {
|
|
1961
|
+
c.warn("Failed to stop the paused turn:", n);
|
|
1814
1962
|
}
|
|
1815
1963
|
return this.eventEmitter.emit("message:stopped", {
|
|
1816
1964
|
conversationId: s.conversationId,
|
|
@@ -1847,7 +1995,7 @@ var Vt = class k {
|
|
|
1847
1995
|
try {
|
|
1848
1996
|
return await this.stopMessage(s);
|
|
1849
1997
|
} catch (i) {
|
|
1850
|
-
return
|
|
1998
|
+
return c.warn("Failed to stop the turn server-side:", i), null;
|
|
1851
1999
|
}
|
|
1852
2000
|
}
|
|
1853
2001
|
buildStoppedMessage(t) {
|
|
@@ -1873,22 +2021,22 @@ var Vt = class k {
|
|
|
1873
2021
|
};
|
|
1874
2022
|
}
|
|
1875
2023
|
async continueMessage(t) {
|
|
1876
|
-
const s = this.functionRegistry.getSchemas(), i = this.buildSendContext(),
|
|
1877
|
-
s.length > 0 && (
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
const
|
|
1881
|
-
return
|
|
2024
|
+
const s = this.functionRegistry.getSchemas(), i = this.buildSendContext(), n = {};
|
|
2025
|
+
s.length > 0 && (n.client_functions = s), i && (n.client_context = i);
|
|
2026
|
+
const r = this.beginTurn();
|
|
2027
|
+
r.messageId = t;
|
|
2028
|
+
const o = await this.sendRequest(r, () => this.httpClient.postStream(`/api/sdk/v1/messages/${t}/continue`, n, { signal: r.controller.signal }));
|
|
2029
|
+
return o ? this.processSSEResponse(o, r) : this.buildStoppedMessage(r);
|
|
1882
2030
|
}
|
|
1883
2031
|
markResumeSignal(t, s, i) {
|
|
1884
2032
|
if (!t) return;
|
|
1885
|
-
const
|
|
2033
|
+
const n = this.pendingResumes.get(t) ?? {
|
|
1886
2034
|
conversationId: s,
|
|
1887
2035
|
waitingConfirmed: !1,
|
|
1888
2036
|
resultsReady: !1,
|
|
1889
2037
|
started: !1
|
|
1890
2038
|
};
|
|
1891
|
-
|
|
2039
|
+
n[i] = !0, s && (n.conversationId = s), this.pendingResumes.set(t, n), !(!n.waitingConfirmed || !n.resultsReady || n.started) && (n.started = !0, this.runAutoResume(t, n.conversationId));
|
|
1892
2040
|
}
|
|
1893
2041
|
async runAutoResume(t, s) {
|
|
1894
2042
|
try {
|
|
@@ -1897,13 +2045,13 @@ var Vt = class k {
|
|
|
1897
2045
|
messageId: t
|
|
1898
2046
|
});
|
|
1899
2047
|
} catch (i) {
|
|
1900
|
-
|
|
2048
|
+
c.warn("Resume gate threw; resuming anyway:", i);
|
|
1901
2049
|
}
|
|
1902
2050
|
if (this.pendingResumes.delete(t), !this.stoppedTurnIds.delete(t))
|
|
1903
2051
|
try {
|
|
1904
2052
|
await this.continueMessage(t);
|
|
1905
2053
|
} catch (i) {
|
|
1906
|
-
|
|
2054
|
+
c.warn("Auto-resume of paused turn failed:", i);
|
|
1907
2055
|
}
|
|
1908
2056
|
}
|
|
1909
2057
|
maybeFlagEmptyReply(t, s) {
|
|
@@ -1915,26 +2063,26 @@ var Vt = class k {
|
|
|
1915
2063
|
const i = t.conversationId || "(no conversation)";
|
|
1916
2064
|
if (this.warnedEmptyConversations.has(i)) return;
|
|
1917
2065
|
this.warnedEmptyConversations.add(i);
|
|
1918
|
-
const
|
|
1919
|
-
t.id ? console.warn("[AGO] Reply completed with empty content. Possible causes: " + (
|
|
2066
|
+
const n = this.config.agent || this.config.defaultAgentId;
|
|
2067
|
+
t.id ? console.warn("[AGO] Reply completed with empty content. Possible causes: " + (n ? `the agent "${n}" may not exist for this tenant, ` : "an unknown `agent` slug, ") + "or the agent replied with no text. Listen for the `message:empty` event to handle this in your app; silence this warning with `warnOnEmptyReply: false`.") : console.warn("[AGO] The stream completed without any message data. Possible causes: " + (n ? `the agent "${n}" may not exist for this tenant, or ` : "") + "`baseUrl` does not point at an AGO endpoint that returns server-sent events. Listen for the `message:empty` event to handle this in your app; silence this warning with `warnOnEmptyReply: false`.");
|
|
1920
2068
|
}, 0);
|
|
1921
2069
|
}
|
|
1922
2070
|
async handleClientFunctionInvocation(t) {
|
|
1923
2071
|
let s, i;
|
|
1924
2072
|
try {
|
|
1925
2073
|
s = await this.functionRegistry.execute(t.functionName, t.arguments);
|
|
1926
|
-
} catch (
|
|
1927
|
-
i =
|
|
2074
|
+
} catch (n) {
|
|
2075
|
+
i = n instanceof Error ? n.message : "Unknown error", c.error("Client function execution failed:", n);
|
|
1928
2076
|
}
|
|
1929
2077
|
if (t.invocationId) try {
|
|
1930
|
-
const
|
|
2078
|
+
const n = await this.submitToolCallForm(t.invocationId, {
|
|
1931
2079
|
result: s,
|
|
1932
2080
|
error: i,
|
|
1933
2081
|
_type: "client_function_result"
|
|
1934
2082
|
});
|
|
1935
|
-
|
|
1936
|
-
} catch (
|
|
1937
|
-
|
|
2083
|
+
n?.resume?.ready && this.markResumeSignal(n.resume.message_id, t.conversationId, "resultsReady");
|
|
2084
|
+
} catch (n) {
|
|
2085
|
+
c.error("Failed to submit function result:", n);
|
|
1938
2086
|
}
|
|
1939
2087
|
this.eventEmitter.emit("function:result", {
|
|
1940
2088
|
invocationId: t.invocationId,
|
|
@@ -1947,7 +2095,7 @@ var Vt = class k {
|
|
|
1947
2095
|
if (s) try {
|
|
1948
2096
|
if (s(t)) return !0;
|
|
1949
2097
|
} catch (i) {
|
|
1950
|
-
|
|
2098
|
+
c.warn("approvalPolicy threw; not gating this call:", i);
|
|
1951
2099
|
}
|
|
1952
2100
|
return this.functionRegistry.get(t.functionName)?.requiresApproval === !0;
|
|
1953
2101
|
}
|
|
@@ -1964,13 +2112,13 @@ var Vt = class k {
|
|
|
1964
2112
|
reason: "user_rejected"
|
|
1965
2113
|
};
|
|
1966
2114
|
try {
|
|
1967
|
-
const
|
|
2115
|
+
const n = await this.submitToolCallForm(t, {
|
|
1968
2116
|
result: i,
|
|
1969
2117
|
_type: "client_function_result"
|
|
1970
2118
|
});
|
|
1971
|
-
|
|
1972
|
-
} catch (
|
|
1973
|
-
|
|
2119
|
+
n?.resume?.ready && this.markResumeSignal(n.resume.message_id, s.conversationId, "resultsReady");
|
|
2120
|
+
} catch (n) {
|
|
2121
|
+
c.error("Failed to submit function rejection:", n);
|
|
1974
2122
|
}
|
|
1975
2123
|
this.eventEmitter.emit("function:result", {
|
|
1976
2124
|
invocationId: t,
|
|
@@ -1979,38 +2127,53 @@ var Vt = class k {
|
|
|
1979
2127
|
}
|
|
1980
2128
|
async runExternalFunction(t, s) {
|
|
1981
2129
|
const i = {
|
|
1982
|
-
invocationId: `webmcp-${
|
|
2130
|
+
invocationId: `webmcp-${x()}`,
|
|
1983
2131
|
functionName: t,
|
|
1984
2132
|
arguments: s,
|
|
1985
2133
|
conversationId: ""
|
|
1986
|
-
}, { invocationId:
|
|
2134
|
+
}, { invocationId: n } = i;
|
|
1987
2135
|
this.eventEmitter.emit("function:invoke", i);
|
|
2136
|
+
const r = Date.now();
|
|
1988
2137
|
try {
|
|
1989
|
-
const
|
|
2138
|
+
const o = await this.functionRegistry.execute(t, s);
|
|
1990
2139
|
return this.eventEmitter.emit("function:result", {
|
|
1991
|
-
invocationId:
|
|
1992
|
-
result:
|
|
1993
|
-
}),
|
|
1994
|
-
} catch (
|
|
2140
|
+
invocationId: n,
|
|
2141
|
+
result: o
|
|
2142
|
+
}), this.reportExternalCall(t, s, r, { result: o }), o;
|
|
2143
|
+
} catch (o) {
|
|
2144
|
+
const a = o instanceof Error ? o.message : String(o);
|
|
1995
2145
|
throw this.eventEmitter.emit("function:result", {
|
|
1996
|
-
invocationId:
|
|
2146
|
+
invocationId: n,
|
|
1997
2147
|
result: null,
|
|
1998
|
-
error:
|
|
1999
|
-
}),
|
|
2148
|
+
error: a
|
|
2149
|
+
}), this.reportExternalCall(t, s, r, { error: a }), o;
|
|
2000
2150
|
}
|
|
2001
2151
|
}
|
|
2152
|
+
reportExternalCall(t, s, i, n) {
|
|
2153
|
+
const r = this.functionRegistry.get(t);
|
|
2154
|
+
r && Vt({
|
|
2155
|
+
post: (o, a, l) => this.httpClient.post(o, a, l),
|
|
2156
|
+
declared: this.declaredExternally
|
|
2157
|
+
}, {
|
|
2158
|
+
schema: r.schema,
|
|
2159
|
+
args: s,
|
|
2160
|
+
durationMs: Date.now() - i,
|
|
2161
|
+
navigates: r.webmcp ? r.webmcp.navigates : void 0,
|
|
2162
|
+
...n
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2002
2165
|
async getConversations(t) {
|
|
2003
2166
|
const s = new URLSearchParams();
|
|
2004
2167
|
t?.page !== void 0 && s.set("page", String(t.page)), t?.pageSize !== void 0 && s.set("page_size", String(t.pageSize));
|
|
2005
|
-
const i = s.toString(),
|
|
2006
|
-
id: String(
|
|
2007
|
-
title:
|
|
2008
|
-
lastMessageDate: new Date(
|
|
2168
|
+
const i = s.toString(), n = await this.httpClient.get(`/api/sdk/v1/conversations${i ? `?${i}` : ""}`), r = (Array.isArray(n.data) ? n.data : []).map((o) => ({
|
|
2169
|
+
id: String(o.id),
|
|
2170
|
+
title: o.title ?? "",
|
|
2171
|
+
lastMessageDate: new Date(o.last_message_at ?? o.created_at ?? 0)
|
|
2009
2172
|
}));
|
|
2010
2173
|
return {
|
|
2011
|
-
data:
|
|
2012
|
-
hasMore:
|
|
2013
|
-
total:
|
|
2174
|
+
data: r,
|
|
2175
|
+
hasMore: n.has_more ?? !1,
|
|
2176
|
+
total: n.total ?? r.length
|
|
2014
2177
|
};
|
|
2015
2178
|
}
|
|
2016
2179
|
async getConversation(t) {
|
|
@@ -2018,22 +2181,22 @@ var Vt = class k {
|
|
|
2018
2181
|
id: s.id,
|
|
2019
2182
|
title: s.title,
|
|
2020
2183
|
lastMessageDate: new Date(s.last_message_at ?? s.created_at ?? 0),
|
|
2021
|
-
messages: s.messages.map((
|
|
2022
|
-
id:
|
|
2184
|
+
messages: s.messages.map((n) => ({
|
|
2185
|
+
id: n.id,
|
|
2023
2186
|
conversationId: s.id,
|
|
2024
|
-
content:
|
|
2025
|
-
role:
|
|
2026
|
-
status:
|
|
2027
|
-
createdAt: new Date(
|
|
2028
|
-
hidden:
|
|
2029
|
-
sources:
|
|
2030
|
-
id:
|
|
2031
|
-
title:
|
|
2032
|
-
url:
|
|
2187
|
+
content: n.content,
|
|
2188
|
+
role: n.role,
|
|
2189
|
+
status: n.status,
|
|
2190
|
+
createdAt: new Date(n.created_at),
|
|
2191
|
+
hidden: n.hidden,
|
|
2192
|
+
sources: n.sources && n.sources.length > 0 ? n.sources.map(({ id: r, title: o, url: a }) => ({
|
|
2193
|
+
id: r,
|
|
2194
|
+
title: o,
|
|
2195
|
+
url: a ?? void 0
|
|
2033
2196
|
})) : void 0,
|
|
2034
|
-
toolCalls:
|
|
2035
|
-
attachments:
|
|
2036
|
-
followUpReplies:
|
|
2197
|
+
toolCalls: R.mapPersistedToolCalls(n.tool_call_data),
|
|
2198
|
+
attachments: n.attachments && n.attachments.length > 0 ? n.attachments.map(Ut) : void 0,
|
|
2199
|
+
followUpReplies: n.follow_up_replies && n.follow_up_replies.length > 0 ? n.follow_up_replies : void 0
|
|
2037
2200
|
}))
|
|
2038
2201
|
};
|
|
2039
2202
|
return this.eventEmitter.emit("conversation:loaded", i), i;
|
|
@@ -2076,8 +2239,8 @@ var Vt = class k {
|
|
|
2076
2239
|
id: i.id,
|
|
2077
2240
|
name: i.name ?? void 0
|
|
2078
2241
|
})),
|
|
2079
|
-
ticketForm: s.ticket_form ?
|
|
2080
|
-
homePage: s.home_page ?
|
|
2242
|
+
ticketForm: s.ticket_form ? R.mapTicketForm(s.ticket_form) : void 0,
|
|
2243
|
+
homePage: s.home_page ? R.mapHomePage(s.home_page) : void 0,
|
|
2081
2244
|
fileAttachmentsEnabled: !!s.file_attachments_enabled,
|
|
2082
2245
|
voiceEnabled: !!s.voice_enabled,
|
|
2083
2246
|
speechToTextEnabled: !!s.speech_to_text_enabled
|
|
@@ -2091,11 +2254,11 @@ var Vt = class k {
|
|
|
2091
2254
|
title: t.title ?? void 0,
|
|
2092
2255
|
subtitle: t.subtitle ?? void 0,
|
|
2093
2256
|
starters: (t.home_starters ?? []).flatMap((i) => {
|
|
2094
|
-
const
|
|
2095
|
-
return !
|
|
2257
|
+
const n = i.description || i.title || "", r = i.initial_message || n;
|
|
2258
|
+
return !n || !r ? [] : [{
|
|
2096
2259
|
id: i.id,
|
|
2097
|
-
label:
|
|
2098
|
-
message:
|
|
2260
|
+
label: n,
|
|
2261
|
+
message: r,
|
|
2099
2262
|
agentId: i.agent_id ?? void 0
|
|
2100
2263
|
}];
|
|
2101
2264
|
}),
|
|
@@ -2151,7 +2314,7 @@ var Vt = class k {
|
|
|
2151
2314
|
async createTicket(t) {
|
|
2152
2315
|
const s = new FormData();
|
|
2153
2316
|
s.append("subject", t.subject), s.append("body", t.body), t.priority && s.append("priority", t.priority), t.typology && s.append("typology", t.typology), t.conversationId && s.append("conversation_id", t.conversationId), t.email && s.append("email", t.email), t.customFields && t.customFields.length > 0 && s.append("custom_fields", JSON.stringify(t.customFields));
|
|
2154
|
-
for (const
|
|
2317
|
+
for (const n of t.files ?? []) s.append("files", n, n.name);
|
|
2155
2318
|
t.ticketFormId && s.append("ticket_form_id", t.ticketFormId);
|
|
2156
2319
|
const i = await (await this.httpClient.postFormData("/api/sdk/v1/tickets", s)).json();
|
|
2157
2320
|
return {
|
|
@@ -2163,41 +2326,41 @@ var Vt = class k {
|
|
|
2163
2326
|
return (await this.getConversation(t)).messages || [];
|
|
2164
2327
|
}
|
|
2165
2328
|
async resumePendingClientFunctions(t) {
|
|
2166
|
-
const s = [...t.messages ?? []].reverse().find((
|
|
2329
|
+
const s = [...t.messages ?? []].reverse().find((a) => a.role === "assistant" && a.status === "WAITING_CLIENT");
|
|
2167
2330
|
if (!s) return null;
|
|
2168
|
-
const i = (s.toolCalls ?? []).filter((
|
|
2169
|
-
if (
|
|
2170
|
-
return
|
|
2171
|
-
let
|
|
2172
|
-
for (const
|
|
2173
|
-
const
|
|
2174
|
-
invocationId:
|
|
2175
|
-
functionName:
|
|
2176
|
-
arguments:
|
|
2331
|
+
const i = (s.toolCalls ?? []).filter((a) => a.type === "client_function" && a.status === "waiting_input" && a.functionName), n = new Set(this.functionRegistry.getSchemas().map((a) => a.name)), r = i.filter((a) => !n.has(a.functionName));
|
|
2332
|
+
if (r.length > 0)
|
|
2333
|
+
return c.warn("Cannot resume paused turn: function(s) not registered on this page:", r.map((a) => a.functionName)), null;
|
|
2334
|
+
let o = i.length === 0;
|
|
2335
|
+
for (const a of i) {
|
|
2336
|
+
const l = {
|
|
2337
|
+
invocationId: a.id,
|
|
2338
|
+
functionName: a.functionName,
|
|
2339
|
+
arguments: a.arguments ?? {},
|
|
2177
2340
|
conversationId: t.id
|
|
2178
2341
|
};
|
|
2179
|
-
if (this.requiresApproval(
|
|
2180
|
-
this.pendingApprovals.set(
|
|
2342
|
+
if (this.requiresApproval(l)) {
|
|
2343
|
+
this.pendingApprovals.set(a.id, l), this.markResumeSignal(s.id, t.id, "waitingConfirmed"), this.eventEmitter.emit("function:awaiting-approval", l), o = !1;
|
|
2181
2344
|
continue;
|
|
2182
2345
|
}
|
|
2183
|
-
this.eventEmitter.emit("function:invoke",
|
|
2346
|
+
this.eventEmitter.emit("function:invoke", l);
|
|
2184
2347
|
let u, d;
|
|
2185
2348
|
try {
|
|
2186
|
-
u = await this.functionRegistry.execute(
|
|
2187
|
-
} catch (
|
|
2188
|
-
d =
|
|
2349
|
+
u = await this.functionRegistry.execute(a.functionName, a.arguments ?? {});
|
|
2350
|
+
} catch (f) {
|
|
2351
|
+
d = f instanceof Error ? f.message : "Unknown error", c.error("Client function execution failed:", f);
|
|
2189
2352
|
}
|
|
2190
2353
|
this.eventEmitter.emit("function:result", {
|
|
2191
|
-
invocationId:
|
|
2354
|
+
invocationId: a.id,
|
|
2192
2355
|
result: u,
|
|
2193
2356
|
error: d
|
|
2194
|
-
}),
|
|
2357
|
+
}), o = (await this.submitToolCallForm(a.id, {
|
|
2195
2358
|
result: u,
|
|
2196
2359
|
error: d,
|
|
2197
2360
|
_type: "client_function_result"
|
|
2198
|
-
}))?.resume?.ready ??
|
|
2361
|
+
}))?.resume?.ready ?? o;
|
|
2199
2362
|
}
|
|
2200
|
-
return
|
|
2363
|
+
return o ? this.continueMessage(s.id) : null;
|
|
2201
2364
|
}
|
|
2202
2365
|
async submitToolCallForm(t, s) {
|
|
2203
2366
|
return this.httpClient.post(`/api/sdk/v1/tool-calls/${t}/submit`, { formData: s });
|
|
@@ -2224,21 +2387,21 @@ var Vt = class k {
|
|
|
2224
2387
|
});
|
|
2225
2388
|
}
|
|
2226
2389
|
async submitFeedback(t, s, i) {
|
|
2227
|
-
const
|
|
2390
|
+
const n = i?.comment?.trim(), r = i?.reasons?.length ? [...new Set(i.reasons)] : [];
|
|
2228
2391
|
await this.httpClient.post(`/api/sdk/v1/messages/${t}/feedback`, {
|
|
2229
2392
|
rating: s,
|
|
2230
|
-
...
|
|
2231
|
-
...
|
|
2393
|
+
...r.length ? { reasons: r } : {},
|
|
2394
|
+
...n ? { comment: n } : {}
|
|
2232
2395
|
});
|
|
2233
2396
|
}
|
|
2234
2397
|
async submitConversationFeedback(t, s, i) {
|
|
2235
|
-
let
|
|
2236
|
-
if (!
|
|
2237
|
-
const
|
|
2238
|
-
if (!
|
|
2239
|
-
|
|
2398
|
+
let n = i?.lastMessageId;
|
|
2399
|
+
if (!n) {
|
|
2400
|
+
const r = [...(await this.getConversation(t)).messages ?? []].reverse().find((o) => o.role === "assistant" && !o.hidden && !!o.content && o.status !== "IN_PROGRESS" && o.status !== "WAITING_CLIENT");
|
|
2401
|
+
if (!r) throw new S(`Conversation ${t} has no finished answer to report feedback on. Wait for the turn to complete, or pass \`lastMessageId\`.`, "feedback_no_message");
|
|
2402
|
+
n = r.id;
|
|
2240
2403
|
}
|
|
2241
|
-
return await this.submitFeedback(
|
|
2404
|
+
return await this.submitFeedback(n, s, i), n;
|
|
2242
2405
|
}
|
|
2243
2406
|
registerFunction(t, s, i) {
|
|
2244
2407
|
typeof t == "object" ? this.functionRegistry.register(t) : this.functionRegistry.register(t, s, i);
|
|
@@ -2262,112 +2425,56 @@ var Vt = class k {
|
|
|
2262
2425
|
async executeClientFunction(t, s) {
|
|
2263
2426
|
return this.functionRegistry.execute(t, s);
|
|
2264
2427
|
}
|
|
2265
|
-
registerNavigationFunction(t, s) {
|
|
2266
|
-
|
|
2267
|
-
const c = M(o.path), u = c.length > 0 ? ` (requires ${c.map((d) => `"${d}"`).join(", ")})` : "";
|
|
2268
|
-
return `- "${o.name}"${u}: ${o.description}`;
|
|
2269
|
-
}).join(`
|
|
2270
|
-
`), n = /* @__PURE__ */ new Map();
|
|
2271
|
-
for (const o of s) for (const c of M(o.path)) n.set(c, [...n.get(c) ?? [], o.name]);
|
|
2272
|
-
const a = { page: {
|
|
2273
|
-
type: "string",
|
|
2274
|
-
description: "The page to navigate to",
|
|
2275
|
-
enum: i
|
|
2276
|
-
} };
|
|
2277
|
-
for (const [o, c] of n) {
|
|
2278
|
-
if (o === "page") {
|
|
2279
|
-
l.error('registerNavigationFunction: a ":page" placeholder collides with the "page" argument and is ignored. Rename the placeholder.');
|
|
2280
|
-
continue;
|
|
2281
|
-
}
|
|
2282
|
-
a[o] = {
|
|
2283
|
-
type: "string",
|
|
2284
|
-
description: `Value for ":${o}" in the page path. Required when page is ${c.map((u) => `"${u}"`).join(" or ")}.`
|
|
2285
|
-
};
|
|
2286
|
-
}
|
|
2287
|
-
this.registerFunction("navigateToPage", async (o) => {
|
|
2288
|
-
const c = o.page, u = s.find((f) => f.name === c);
|
|
2289
|
-
if (!u) return {
|
|
2290
|
-
success: !1,
|
|
2291
|
-
error: `Unknown page: ${c}`
|
|
2292
|
-
};
|
|
2293
|
-
let d = {};
|
|
2294
|
-
if (typeof o.params == "string") try {
|
|
2295
|
-
d = JSON.parse(o.params);
|
|
2296
|
-
} catch {
|
|
2297
|
-
}
|
|
2298
|
-
else o.params && typeof o.params == "object" && (d = o.params);
|
|
2299
|
-
const g = {};
|
|
2300
|
-
for (const f of M(u.path)) g[f] = o[f] ?? d[f];
|
|
2301
|
-
const { path: m, missing: v } = jt(u.path, g);
|
|
2302
|
-
if (v.length > 0) {
|
|
2303
|
-
const f = v.map((h) => `"${h}": "..."`).join(", ");
|
|
2304
|
-
return {
|
|
2305
|
-
success: !1,
|
|
2306
|
-
error: `Page "${c}" needs ${v.map((h) => `"${h}"`).join(", ")}. Retry with { "page": "${c}", ${f} }.`
|
|
2307
|
-
};
|
|
2308
|
-
}
|
|
2309
|
-
return t(m), {
|
|
2310
|
-
success: !0,
|
|
2311
|
-
navigatedTo: m
|
|
2312
|
-
};
|
|
2313
|
-
}, {
|
|
2314
|
-
description: `Navigate the user to a page in the application. Available pages:
|
|
2315
|
-
${r}`,
|
|
2316
|
-
parameters: {
|
|
2317
|
-
type: "object",
|
|
2318
|
-
properties: a,
|
|
2319
|
-
required: ["page"]
|
|
2320
|
-
},
|
|
2321
|
-
webmcp: { navigates: !0 }
|
|
2322
|
-
}), this.addDynamicContext("current-page", () => {
|
|
2428
|
+
registerNavigationFunction(t, s, i) {
|
|
2429
|
+
this.registerFunction(Ze(t, s, i)), i?.catalogue === "onDemand" ? (this.registerFunction(et(s)), this.listPagesRegistered = !0) : this.listPagesRegistered && (this.unregisterFunction(T), this.listPagesRegistered = !1), this.addDynamicContext("current-page", () => {
|
|
2323
2430
|
if (typeof window > "u" || !window.location) return null;
|
|
2324
|
-
const
|
|
2325
|
-
return
|
|
2431
|
+
const n = window.location.href, r = typeof document < "u" ? document.title : void 0, o = Ye(window.location.pathname, s), a = { url: n };
|
|
2432
|
+
return o && (a.page = o.name), r && (a.title = r), {
|
|
2326
2433
|
name: "Current page",
|
|
2327
2434
|
description: "The page the user is currently viewing.",
|
|
2328
|
-
data:
|
|
2435
|
+
data: a
|
|
2329
2436
|
};
|
|
2330
2437
|
});
|
|
2331
2438
|
}
|
|
2332
2439
|
unregisterNavigationFunction() {
|
|
2333
|
-
this.unregisterFunction(
|
|
2440
|
+
this.unregisterFunction(J), this.listPagesRegistered && (this.unregisterFunction(T), this.listPagesRegistered = !1), this.removeDynamicContext("current-page");
|
|
2334
2441
|
}
|
|
2335
2442
|
registerPageStateFunction(t, s) {
|
|
2336
|
-
const i = s?.functionName ?? "setPageState",
|
|
2337
|
-
this.registerFunction(
|
|
2443
|
+
const i = s?.functionName ?? "setPageState", n = s?.data;
|
|
2444
|
+
this.registerFunction(nt(t, {
|
|
2338
2445
|
name: i,
|
|
2339
2446
|
requiresApproval: s?.requiresApproval,
|
|
2340
|
-
getResultBudget: () =>
|
|
2341
|
-
data:
|
|
2342
|
-
description:
|
|
2343
|
-
maxResultBytes:
|
|
2344
|
-
read: async (
|
|
2447
|
+
getResultBudget: () => n ? this.pageDataBudget(n) : this.functionRegistry.getDefaultMaxResultBytes(),
|
|
2448
|
+
data: n ? {
|
|
2449
|
+
description: n.description,
|
|
2450
|
+
maxResultBytes: n.maxResultBytes,
|
|
2451
|
+
read: async (o) => te(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes(o))
|
|
2345
2452
|
} : void 0
|
|
2346
2453
|
}));
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
description: `Read what the current page is displaying, without changing anything: ${
|
|
2454
|
+
const r = fe(i);
|
|
2455
|
+
n ? (this.warnIfPlaceholderMode(i), this.registerFunction(r, async () => ({ data: te(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes({})) }), {
|
|
2456
|
+
description: `Read what the current page is displaying, without changing anything: ${n.description}`,
|
|
2350
2457
|
parameters: {
|
|
2351
2458
|
type: "object",
|
|
2352
2459
|
properties: {}
|
|
2353
2460
|
},
|
|
2354
|
-
maxResultBytes:
|
|
2355
|
-
}), this.pageDataCompanions.add(
|
|
2356
|
-
const
|
|
2357
|
-
if (
|
|
2358
|
-
const
|
|
2359
|
-
for (const
|
|
2461
|
+
maxResultBytes: n.maxResultBytes
|
|
2462
|
+
}), this.pageDataCompanions.add(r)) : this.pageDataCompanions.delete(r) && this.unregisterFunction(r), this.addDynamicContext(`page-state:${i}`, () => {
|
|
2463
|
+
const o = t.filter((l) => typeof l.get == "function");
|
|
2464
|
+
if (o.length === 0) return null;
|
|
2465
|
+
const a = {};
|
|
2466
|
+
for (const l of o) a[l.name] = l.get();
|
|
2360
2467
|
return {
|
|
2361
2468
|
name: "Page state",
|
|
2362
2469
|
description: "Current, editable state of the page the user is viewing.",
|
|
2363
|
-
data:
|
|
2470
|
+
data: a
|
|
2364
2471
|
};
|
|
2365
2472
|
});
|
|
2366
2473
|
}
|
|
2367
2474
|
unregisterPageStateFunction(t) {
|
|
2368
2475
|
const s = t ?? "setPageState";
|
|
2369
2476
|
this.unregisterFunction(s);
|
|
2370
|
-
const i =
|
|
2477
|
+
const i = fe(s);
|
|
2371
2478
|
this.pageDataCompanions.delete(i) && this.unregisterFunction(i), this.removeDynamicContext(`page-state:${s}`);
|
|
2372
2479
|
}
|
|
2373
2480
|
pageDataBudget(t) {
|
|
@@ -2380,13 +2487,13 @@ ${r}`,
|
|
|
2380
2487
|
})) - 4;
|
|
2381
2488
|
}
|
|
2382
2489
|
readPageData(t, s, i) {
|
|
2383
|
-
return
|
|
2490
|
+
return qe(() => s, i?.settleTimeoutMs ?? 1e4).catch((n) => (c.warn(`Reading page data for "${t}" failed:`, n), {
|
|
2384
2491
|
error: "page_data_unavailable",
|
|
2385
|
-
message:
|
|
2492
|
+
message: n instanceof Error ? n.message : String(n)
|
|
2386
2493
|
}));
|
|
2387
2494
|
}
|
|
2388
2495
|
warnIfPlaceholderMode(t) {
|
|
2389
|
-
this.warnedPageDataPlaceholder || this.config.clientFunctionsMode === "placeholder" && (this.warnedPageDataPlaceholder = !0,
|
|
2496
|
+
this.warnedPageDataPlaceholder || this.config.clientFunctionsMode === "placeholder" && (this.warnedPageDataPlaceholder = !0, c.warn(`"${t}" declares a data source, but clientFunctionsMode is "placeholder": the agent will not see that data during the turn it calls the function. Switch to "pause" (the default) for the data to come back as the result of its own call.`));
|
|
2390
2497
|
}
|
|
2391
2498
|
setContext(t, s) {
|
|
2392
2499
|
this.contextRegistry.set(t, s), this.notifyContextChanged();
|
|
@@ -2440,10 +2547,10 @@ ${r}`,
|
|
|
2440
2547
|
return this.contextRegistry.getSnapshot();
|
|
2441
2548
|
}
|
|
2442
2549
|
buildSendContext() {
|
|
2443
|
-
const t = this.contextRegistry.getSnapshot(), s = t?.entries ?? {}, { changes: i, baseline:
|
|
2444
|
-
return this.lastSentPageState =
|
|
2550
|
+
const t = this.contextRegistry.getSnapshot(), s = t?.entries ?? {}, { changes: i, baseline: n } = Nt(this.lastSentPageState, s);
|
|
2551
|
+
return this.lastSentPageState = n, i.length === 0 ? t : { entries: {
|
|
2445
2552
|
...s,
|
|
2446
|
-
[
|
|
2553
|
+
[Zt]: {
|
|
2447
2554
|
name: "State changes",
|
|
2448
2555
|
description: "Fields in the page state that changed since your last message, as field: <old> -> <new>.",
|
|
2449
2556
|
data: { changes: i }
|
|
@@ -2465,20 +2572,20 @@ ${r}`,
|
|
|
2465
2572
|
}
|
|
2466
2573
|
recordAgentAction(t) {
|
|
2467
2574
|
const s = t.functionName, i = t.arguments;
|
|
2468
|
-
let
|
|
2575
|
+
let n, r;
|
|
2469
2576
|
if (s === "navigateToPage") {
|
|
2470
|
-
const
|
|
2471
|
-
|
|
2472
|
-
} else s === "setPageState" ? (
|
|
2577
|
+
const o = i?.page;
|
|
2578
|
+
n = "agent.navigate", r = o ? `Agent navigated to "${String(o)}"` : "Agent navigated";
|
|
2579
|
+
} else s === "setPageState" ? (n = "agent.page_state", r = "Agent changed the page state") : (n = `agent.${s}`, r = `Agent ran "${s}"`);
|
|
2473
2580
|
this.addActivity({
|
|
2474
2581
|
actor: "agent",
|
|
2475
|
-
name:
|
|
2476
|
-
summary:
|
|
2582
|
+
name: n,
|
|
2583
|
+
summary: r,
|
|
2477
2584
|
...i && Object.keys(i).length > 0 ? { data: { arguments: i } } : {}
|
|
2478
2585
|
});
|
|
2479
2586
|
}
|
|
2480
2587
|
registerActivityContext() {
|
|
2481
|
-
this.contextRegistry.addDynamicProvider(
|
|
2588
|
+
this.contextRegistry.addDynamicProvider(Qt, () => {
|
|
2482
2589
|
const t = this.activityLedger.getRecent();
|
|
2483
2590
|
return t.length === 0 ? null : {
|
|
2484
2591
|
name: "Recent activity",
|
|
@@ -2489,30 +2596,30 @@ ${r}`,
|
|
|
2489
2596
|
}
|
|
2490
2597
|
enableErrorWatcher(t) {
|
|
2491
2598
|
this.disableErrorWatcher();
|
|
2492
|
-
const s = new
|
|
2599
|
+
const s = new $e(t);
|
|
2493
2600
|
this.errorWatcher = s, s.start(), s.subscribe((i) => {
|
|
2494
2601
|
this.eventEmitter.emit("error:captured", i), this.notifyContextChanged();
|
|
2495
|
-
}), this.contextRegistry.addDynamicProvider(
|
|
2602
|
+
}), this.contextRegistry.addDynamicProvider(ge, () => {
|
|
2496
2603
|
const i = s.getErrors();
|
|
2497
2604
|
if (i.length === 0) return null;
|
|
2498
|
-
const
|
|
2605
|
+
const n = Date.now();
|
|
2499
2606
|
return {
|
|
2500
2607
|
name: "Recent JavaScript errors",
|
|
2501
2608
|
description: "JavaScript errors captured on the page in the last minutes, oldest first, with how long ago each last fired (ageMs) and how many times (count). Use them to diagnose when the user reports something broken or unresponsive; do not bring them up otherwise.",
|
|
2502
|
-
data: { errors: i.map(({ firstAt:
|
|
2503
|
-
...
|
|
2504
|
-
ageMs: Math.max(0,
|
|
2505
|
-
...
|
|
2609
|
+
data: { errors: i.map(({ firstAt: r, lastAt: o, ...a }) => ({
|
|
2610
|
+
...a,
|
|
2611
|
+
ageMs: Math.max(0, n - o),
|
|
2612
|
+
...r !== o ? { firstSeenAgoMs: Math.max(0, n - r) } : {}
|
|
2506
2613
|
})) }
|
|
2507
2614
|
};
|
|
2508
2615
|
});
|
|
2509
2616
|
}
|
|
2510
2617
|
disableErrorWatcher() {
|
|
2511
|
-
this.errorWatcher && (this.errorWatcher.destroy(), this.errorWatcher = null, this.contextRegistry.removeDynamicProvider(
|
|
2618
|
+
this.errorWatcher && (this.errorWatcher.destroy(), this.errorWatcher = null, this.contextRegistry.removeDynamicProvider(ge));
|
|
2512
2619
|
}
|
|
2513
2620
|
reportError(t, s) {
|
|
2514
2621
|
if (!this.errorWatcher) {
|
|
2515
|
-
|
|
2622
|
+
c.warn("reportError() ignored: enable the error watcher first (errorWatcher: true).");
|
|
2516
2623
|
return;
|
|
2517
2624
|
}
|
|
2518
2625
|
this.errorWatcher.report(t, s);
|
|
@@ -2537,48 +2644,48 @@ ${r}`,
|
|
|
2537
2644
|
}
|
|
2538
2645
|
updateConfig(t) {
|
|
2539
2646
|
const s = {};
|
|
2540
|
-
for (const [
|
|
2647
|
+
for (const [n, r] of Object.entries(t)) r !== void 0 && (s[n] = r);
|
|
2541
2648
|
const i = {
|
|
2542
2649
|
...this.config,
|
|
2543
2650
|
...s
|
|
2544
2651
|
};
|
|
2545
|
-
|
|
2652
|
+
he(i, "AgoClient.updateConfig"), this.config = i, this.httpClient.updateConfig(s), s.debug !== void 0 && (s.debug ? c.enable() : c.disable()), s.maxFunctionResultBytes !== void 0 && this.functionRegistry.setDefaultMaxResultBytes(s.maxFunctionResultBytes), s.errorWatcher !== void 0 && (s.errorWatcher ? this.enableErrorWatcher(s.errorWatcher === !0 ? void 0 : s.errorWatcher) : this.disableErrorWatcher());
|
|
2546
2653
|
}
|
|
2547
2654
|
destroy() {
|
|
2548
|
-
this.proactive?.destroy(), this.proactive = null, this.errorWatcher?.destroy(), this.errorWatcher = null, this.detachWebMCP?.(), this.detachWebMCP = null, this.activeTurn?.controller.abort(), this.activeTurn = null, this.pausedTurn = null, this.stoppedTurnIds.clear(), this.eventEmitter.removeAllListeners(), this.functionRegistry.clear(), this.contextRegistry.clear(), this.pendingResumes.clear(), this.pendingApprovals.clear(), this.resumeGate = null,
|
|
2655
|
+
this.proactive?.destroy(), this.proactive = null, this.errorWatcher?.destroy(), this.errorWatcher = null, this.detachWebMCP?.(), this.detachWebMCP = null, this.activeTurn?.controller.abort(), this.activeTurn = null, this.pausedTurn = null, this.stoppedTurnIds.clear(), this.eventEmitter.removeAllListeners(), this.functionRegistry.clear(), this.listPagesRegistered = !1, this.contextRegistry.clear(), this.pendingResumes.clear(), this.pendingApprovals.clear(), this.resumeGate = null, c.log("AgoClient destroyed");
|
|
2549
2656
|
}
|
|
2550
2657
|
reviveAfterDestroy() {
|
|
2551
|
-
this.registerActivityContext(), this.config.errorWatcher && !this.errorWatcher && this.enableErrorWatcher(this.config.errorWatcher === !0 ? void 0 : this.config.errorWatcher), this.config.proactive && !this.proactive &&
|
|
2658
|
+
this.registerActivityContext(), this.config.errorWatcher && !this.errorWatcher && this.enableErrorWatcher(this.config.errorWatcher === !0 ? void 0 : this.config.errorWatcher), this.config.proactive && !this.proactive && ae(this, this.config.proactive), this.attachWebMCPBridge();
|
|
2552
2659
|
}
|
|
2553
|
-
},
|
|
2660
|
+
}, ls = [
|
|
2554
2661
|
"inaccurate",
|
|
2555
2662
|
"incomplete",
|
|
2556
2663
|
"information_not_found",
|
|
2557
2664
|
"technical_issue"
|
|
2558
2665
|
];
|
|
2559
2666
|
export {
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2667
|
+
ke as C,
|
|
2668
|
+
c as S,
|
|
2669
|
+
ht as _,
|
|
2670
|
+
as as a,
|
|
2671
|
+
is as b,
|
|
2672
|
+
jt as c,
|
|
2673
|
+
xt as d,
|
|
2674
|
+
ae as f,
|
|
2675
|
+
gt as g,
|
|
2676
|
+
Se as h,
|
|
2677
|
+
Wt as i,
|
|
2678
|
+
Ot as l,
|
|
2679
|
+
Et as m,
|
|
2680
|
+
cs as n,
|
|
2681
|
+
rs as o,
|
|
2682
|
+
wt as p,
|
|
2683
|
+
he as r,
|
|
2684
|
+
os as s,
|
|
2685
|
+
ls as t,
|
|
2686
|
+
ns as u,
|
|
2687
|
+
Le as v,
|
|
2688
|
+
ts as w,
|
|
2689
|
+
$e as x,
|
|
2690
|
+
ss as y
|
|
2584
2691
|
};
|