@useago/sdk 1.13.0 → 1.13.2
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-CiOXKWl0.cjs → createConversationSession-Digvn0GQ.cjs} +1 -1
- package/dist/{createConversationSession-BfJg0WyA.js → createConversationSession-DrmOaZdO.js} +1 -1
- package/dist/{createFormCollector-DnQl77Ko.cjs → createFormCollector-Cq7HWjtU.cjs} +1 -1
- package/dist/{createFormCollector-DN1xjAv5.js → createFormCollector-ki_GTlp9.js} +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-Q7t1peH-.js → types-D1ZrqVhr.js} +884 -776
- package/dist/types-DNr6XEwI.cjs +10 -0
- 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 +56 -3
- 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: u, handler: g, description: f, parameters: v, maxResultBytes: y, requiresApproval: h, webmcp: p } = e;
|
|
402
|
+
return this.register(u, g, {
|
|
403
|
+
description: f,
|
|
404
|
+
parameters: v,
|
|
405
|
+
maxResultBytes: y,
|
|
406
|
+
requiresApproval: h,
|
|
407
|
+
webmcp: p
|
|
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 d = Me(l);
|
|
425
|
+
d.length > 0 && c.warn(`Function "${i}" is over the per-tool budget on ${d.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
|
-
},
|
|
463
|
-
function
|
|
464
|
-
return
|
|
481
|
+
}, je = new TextEncoder();
|
|
482
|
+
function b(e) {
|
|
483
|
+
return je.encode(e).length;
|
|
465
484
|
}
|
|
466
|
-
function
|
|
467
|
-
return
|
|
485
|
+
function j(e) {
|
|
486
|
+
return b(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,402 @@ 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 = b(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 = b(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 = b(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 = b(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 = b(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 = "Available functions depend on the current page. After navigation, you will receive the destination page’s available functions and current state. Use them to complete any remaining actions in the user’s request.", o = i ? `Navigate the user to a page. Call ${T} for what a page name means. ${r}` : `Navigate the user to a page in the application. ${r} Available pages:
|
|
647
|
+
${t.map(Qe).join(`
|
|
648
|
+
`)}`, a = /* @__PURE__ */ new Map();
|
|
649
|
+
for (const u of t) for (const g of B(u.path)) a.set(g, [...a.get(g) ?? [], u.name]);
|
|
650
|
+
const l = t.map((u) => u.name), d = { page: {
|
|
651
|
+
type: "string",
|
|
652
|
+
description: "The page to navigate to",
|
|
653
|
+
enum: l
|
|
654
|
+
} };
|
|
655
|
+
for (const [u, g] of a) {
|
|
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
|
+
d[u] = {
|
|
661
|
+
type: "string",
|
|
662
|
+
description: `Value for ":${u}" in the page path. Required when page is ${g.map((f) => `"${f}"`).join(" or ")}.`
|
|
663
|
+
};
|
|
586
664
|
}
|
|
587
|
-
return
|
|
665
|
+
return {
|
|
666
|
+
name: J,
|
|
667
|
+
description: o,
|
|
668
|
+
parameters: {
|
|
669
|
+
type: "object",
|
|
670
|
+
properties: d,
|
|
671
|
+
required: ["page"]
|
|
672
|
+
},
|
|
673
|
+
webmcp: { navigates: !0 },
|
|
674
|
+
handler: async (u) => {
|
|
675
|
+
const g = u.page, f = t.find((m) => m.name === g);
|
|
676
|
+
if (!f) return i ? {
|
|
677
|
+
success: !1,
|
|
678
|
+
error: `Unknown page: ${g}`,
|
|
679
|
+
pages: l
|
|
680
|
+
} : {
|
|
681
|
+
success: !1,
|
|
682
|
+
error: `Unknown page: ${g}`
|
|
683
|
+
};
|
|
684
|
+
let v = {};
|
|
685
|
+
if (typeof u.params == "string") try {
|
|
686
|
+
v = JSON.parse(u.params);
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
else u.params && typeof u.params == "object" && (v = u.params);
|
|
690
|
+
const y = {};
|
|
691
|
+
for (const m of B(f.path)) y[m] = u[m] ?? v[m];
|
|
692
|
+
const { path: h, missing: p } = Ve(f.path, y);
|
|
693
|
+
if (p.length > 0) {
|
|
694
|
+
const m = p.map((w) => `"${w}": "..."`).join(", ");
|
|
695
|
+
return {
|
|
696
|
+
success: !1,
|
|
697
|
+
error: `Page "${g}" needs ${p.map((w) => `"${w}"`).join(", ")}. Retry with { "page": "${g}", ${m} }.`
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
return e(h), {
|
|
701
|
+
success: !0,
|
|
702
|
+
navigatedTo: h
|
|
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
|
|
599
|
-
return
|
|
744
|
+
var se = 100, $ = " … [truncated]", we = { truncated: !0 }, tt = b(',"data":' + JSON.stringify(we));
|
|
745
|
+
function G(e) {
|
|
746
|
+
return b(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
|
|
612
|
-
if (
|
|
613
|
-
i[
|
|
754
|
+
let r = G(n);
|
|
755
|
+
if (r > t) return n;
|
|
756
|
+
const o = j($);
|
|
757
|
+
for (const [a, l] of s) {
|
|
758
|
+
const d = j(l), u = t - r + o;
|
|
759
|
+
if (d <= u) {
|
|
760
|
+
i[a] = l, r += d - o;
|
|
614
761
|
continue;
|
|
615
762
|
}
|
|
616
|
-
i[
|
|
763
|
+
i[a] = ye(l, u - 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 : t.length === 0 ? "No values are currently allowed." : `${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,
|
|
816
|
+
...e.schema.items ? { items: { ...e.schema.items } } : {},
|
|
669
817
|
description: e.description
|
|
670
818
|
};
|
|
671
|
-
|
|
672
|
-
const s =
|
|
673
|
-
return s && (t.enum = s), t;
|
|
819
|
+
t.enum?.length === 0 && delete t.enum, t.items?.enum?.length === 0 && delete t.items.enum, H(e) && (t.description = `${e.description} Pass "" to clear it.`);
|
|
820
|
+
const s = be(e);
|
|
821
|
+
return s?.length && (t.enum = s), t;
|
|
674
822
|
}
|
|
675
|
-
function
|
|
676
|
-
const s = new Map(e.map((
|
|
823
|
+
function nt(e, t) {
|
|
824
|
+
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
825
|
`);
|
|
678
826
|
return {
|
|
679
827
|
name: t.name,
|
|
680
|
-
handler: async (
|
|
681
|
-
const
|
|
682
|
-
for (const [h, p] of Object.entries(
|
|
683
|
-
const
|
|
684
|
-
if (!
|
|
685
|
-
|
|
828
|
+
handler: async (r) => {
|
|
829
|
+
const o = [], a = [], l = {};
|
|
830
|
+
for (const [h, p] of Object.entries(r)) {
|
|
831
|
+
const m = s.get(h);
|
|
832
|
+
if (!m) {
|
|
833
|
+
l[h] = `"${h}" is not a registered control. Available controls: ${Ee(i)}.`;
|
|
686
834
|
continue;
|
|
687
835
|
}
|
|
688
|
-
if (p == null || p === "" && !
|
|
689
|
-
const
|
|
690
|
-
if (
|
|
691
|
-
|
|
836
|
+
if (p == null || p === "" && !H(m)) continue;
|
|
837
|
+
const w = st(p, m);
|
|
838
|
+
if (w) {
|
|
839
|
+
l[h] = w;
|
|
692
840
|
continue;
|
|
693
841
|
}
|
|
694
|
-
if (
|
|
695
|
-
|
|
842
|
+
if (m.get && I(p, m.get())) {
|
|
843
|
+
a.push(h);
|
|
696
844
|
continue;
|
|
697
845
|
}
|
|
698
|
-
const
|
|
699
|
-
|
|
846
|
+
const E = await m.set(p);
|
|
847
|
+
E ? E.result === "rejected" ? l[h] = E.reason || "The page rejected this field's update." : E.result === "unchanged" ? a.push(h) : o.push(h) : o.push(h);
|
|
700
848
|
}
|
|
701
|
-
const
|
|
702
|
-
success: !
|
|
703
|
-
applied:
|
|
704
|
-
unchanged:
|
|
705
|
-
...
|
|
849
|
+
const d = Object.keys(l).length > 0, u = {
|
|
850
|
+
success: !d,
|
|
851
|
+
applied: o,
|
|
852
|
+
unchanged: a,
|
|
853
|
+
...d ? { rejected: l } : {}
|
|
706
854
|
}, g = t.getResultBudget();
|
|
707
|
-
if (!t.data) return
|
|
708
|
-
const
|
|
709
|
-
...
|
|
855
|
+
if (!t.data) return ie(u, g);
|
|
856
|
+
const f = ie(u, g - tt), v = await t.data.read(f), y = {
|
|
857
|
+
...f,
|
|
710
858
|
data: v
|
|
711
859
|
};
|
|
712
|
-
return
|
|
713
|
-
...
|
|
714
|
-
data:
|
|
860
|
+
return G(y) <= g ? y : {
|
|
861
|
+
...f,
|
|
862
|
+
data: we
|
|
715
863
|
};
|
|
716
864
|
},
|
|
717
865
|
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
|
-
${
|
|
866
|
+
${n}` : "The current page has no editable state — nothing to change here.") + (t.data ? `
|
|
719
867
|
Returns the resulting page data once it has loaded: ${t.data.description}` : ""),
|
|
720
868
|
parameters: {
|
|
721
869
|
type: "object",
|
|
722
|
-
properties: Object.fromEntries(e.map((
|
|
870
|
+
properties: Object.fromEntries(e.map((r) => [r.name, it(r)])),
|
|
723
871
|
required: []
|
|
724
872
|
},
|
|
725
873
|
requiresApproval: t.requiresApproval,
|
|
726
874
|
maxResultBytes: t.data?.maxResultBytes
|
|
727
875
|
};
|
|
728
876
|
}
|
|
729
|
-
var
|
|
877
|
+
var rt = 250, ot = 3, at = 1e3, ct = 24, lt = 10, ut = 50, dt = [
|
|
730
878
|
"mousemove",
|
|
731
879
|
"mousedown",
|
|
732
880
|
"keydown",
|
|
733
881
|
"scroll",
|
|
734
882
|
"touchstart"
|
|
735
|
-
],
|
|
883
|
+
], ht = class {
|
|
736
884
|
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 ??
|
|
885
|
+
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
886
|
}
|
|
739
887
|
start() {
|
|
740
888
|
if (this.started || typeof window > "u" || typeof document > "u") return;
|
|
741
889
|
this.started = !0;
|
|
742
890
|
const e = Date.now();
|
|
743
891
|
this.route = this.currentPathname(), this.routeEnteredAt = e, this.lastActivityAt = e, this.recentRoutes = [this.route];
|
|
744
|
-
const t = (i,
|
|
745
|
-
i.addEventListener(
|
|
892
|
+
const t = (i, n, r) => {
|
|
893
|
+
i.addEventListener(n, r, { passive: !0 }), this.teardowns.push(() => i.removeEventListener(n, r));
|
|
746
894
|
}, s = () => this.recordActivity();
|
|
747
|
-
for (const i of
|
|
895
|
+
for (const i of dt) t(window, i, s);
|
|
748
896
|
t(document, "visibilitychange", () => {
|
|
749
897
|
document.visibilityState === "visible" && this.recordActivity();
|
|
750
|
-
}), t(window, "popstate", () => this.checkRoute()), t(window, "hashchange", () => this.checkRoute()), t(window, "click", (i) => this.onClick(i)),
|
|
898
|
+
}), t(window, "popstate", () => this.checkRoute()), t(window, "hashchange", () => this.checkRoute()), t(window, "click", (i) => this.onClick(i)), c.log("SignalCollector started");
|
|
751
899
|
}
|
|
752
900
|
destroy() {
|
|
753
901
|
for (const e of this.teardowns) e();
|
|
754
|
-
this.teardowns = [], this.listeners.clear(), this.recentClicks = [], this.started = !1,
|
|
902
|
+
this.teardowns = [], this.listeners.clear(), this.recentClicks = [], this.started = !1, c.log("SignalCollector destroyed");
|
|
755
903
|
}
|
|
756
904
|
signalFieldError(e) {
|
|
757
905
|
this.checkRoute();
|
|
@@ -804,7 +952,7 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
804
952
|
try {
|
|
805
953
|
return this.getPageState() ?? null;
|
|
806
954
|
} catch (e) {
|
|
807
|
-
return
|
|
955
|
+
return c.warn("SignalCollector getPageState threw:", e), null;
|
|
808
956
|
}
|
|
809
957
|
}
|
|
810
958
|
recordActivity() {
|
|
@@ -822,13 +970,13 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
822
970
|
at: t,
|
|
823
971
|
meta: { from: s }
|
|
824
972
|
});
|
|
825
|
-
const i = this.recentRoutes,
|
|
826
|
-
|
|
973
|
+
const i = this.recentRoutes, n = i.length;
|
|
974
|
+
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
975
|
type: "route_bounce",
|
|
828
976
|
route: e,
|
|
829
977
|
at: t,
|
|
830
978
|
count: this.routeBounces,
|
|
831
|
-
meta: { between: `${i[
|
|
979
|
+
meta: { between: `${i[n - 2]}↔${i[n - 1]}` }
|
|
832
980
|
}));
|
|
833
981
|
}
|
|
834
982
|
onClick(e) {
|
|
@@ -839,9 +987,9 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
839
987
|
y: e.clientY,
|
|
840
988
|
stateKey: s
|
|
841
989
|
};
|
|
842
|
-
this.recentClicks = this.recentClicks.filter((
|
|
843
|
-
const
|
|
844
|
-
if (!
|
|
990
|
+
this.recentClicks = this.recentClicks.filter((a) => t - a.at <= this.rageClickWindowMs);
|
|
991
|
+
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;
|
|
992
|
+
if (!r || !o) {
|
|
845
993
|
this.recentClicks = [i];
|
|
846
994
|
return;
|
|
847
995
|
}
|
|
@@ -866,20 +1014,20 @@ var He = 250, Xe = 3, ze = 1e3, Ve = 24, Ye = 10, Qe = 50, Ze = [
|
|
|
866
1014
|
for (const t of this.listeners) try {
|
|
867
1015
|
t(e);
|
|
868
1016
|
} catch (s) {
|
|
869
|
-
|
|
1017
|
+
c.error("Signal listener threw:", s);
|
|
870
1018
|
}
|
|
871
1019
|
}
|
|
872
1020
|
};
|
|
873
|
-
function
|
|
1021
|
+
function gt(e, t) {
|
|
874
1022
|
const s = t ? t.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
|
|
875
1023
|
let i = e;
|
|
876
1024
|
if (t && s) try {
|
|
877
|
-
const
|
|
878
|
-
|
|
1025
|
+
const a = s.getItem(t.key);
|
|
1026
|
+
a != null && (i = JSON.parse(a));
|
|
879
1027
|
} catch {
|
|
880
1028
|
}
|
|
881
|
-
const
|
|
882
|
-
function
|
|
1029
|
+
const n = /* @__PURE__ */ new Set(), r = () => n.forEach((a) => a(i));
|
|
1030
|
+
function o() {
|
|
883
1031
|
if (t && s) try {
|
|
884
1032
|
s.setItem(t.key, JSON.stringify(i));
|
|
885
1033
|
} catch {
|
|
@@ -887,31 +1035,31 @@ function tt(e, t) {
|
|
|
887
1035
|
}
|
|
888
1036
|
return {
|
|
889
1037
|
get: () => i,
|
|
890
|
-
set: (
|
|
891
|
-
i =
|
|
1038
|
+
set: (a) => {
|
|
1039
|
+
i = a, o(), r();
|
|
892
1040
|
},
|
|
893
|
-
subscribe: (
|
|
894
|
-
|
|
1041
|
+
subscribe: (a) => (n.add(a), () => {
|
|
1042
|
+
n.delete(a);
|
|
895
1043
|
})
|
|
896
1044
|
};
|
|
897
1045
|
}
|
|
898
|
-
var
|
|
899
|
-
function
|
|
1046
|
+
var ft = 6e4, mt = 1440 * 60 * 1e3, pt = "ago_proactive";
|
|
1047
|
+
function M(e) {
|
|
900
1048
|
const t = new Date(e), s = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getDate()).padStart(2, "0");
|
|
901
1049
|
return `${t.getFullYear()}-${s}-${i}`;
|
|
902
1050
|
}
|
|
903
|
-
var
|
|
1051
|
+
var yt = class {
|
|
904
1052
|
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 =
|
|
1053
|
+
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
1054
|
optOut: !1,
|
|
907
1055
|
lastFiredAt: {},
|
|
908
1056
|
dismissedAt: {},
|
|
909
1057
|
day: {
|
|
910
|
-
date:
|
|
1058
|
+
date: M(Date.now()),
|
|
911
1059
|
count: 0
|
|
912
1060
|
}
|
|
913
1061
|
}, {
|
|
914
|
-
key: e.storageKey ??
|
|
1062
|
+
key: e.storageKey ?? pt,
|
|
915
1063
|
storage: e.storage
|
|
916
1064
|
});
|
|
917
1065
|
}
|
|
@@ -955,10 +1103,10 @@ var nt = class {
|
|
|
955
1103
|
if (this.engaged) return this.deny(e, "user engaged (widget open)");
|
|
956
1104
|
if (this.turnInFlight) return this.deny(e, "message turn in flight");
|
|
957
1105
|
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
|
|
1106
|
+
const i = s.lastFiredAt[e.id], n = e.cooldownMs ?? ft;
|
|
1107
|
+
if (i !== void 0 && t - i < n) return this.deny(e, "cooldown");
|
|
1108
|
+
const r = s.dismissedAt[e.id], o = e.resurfaceAfterMs ?? mt;
|
|
1109
|
+
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
1110
|
}
|
|
963
1111
|
recordFired(e, t = Date.now()) {
|
|
964
1112
|
const s = this.store.get();
|
|
@@ -972,7 +1120,7 @@ var nt = class {
|
|
|
972
1120
|
}
|
|
973
1121
|
recordNudgeShown(e = Date.now()) {
|
|
974
1122
|
this.sessionCount += 1;
|
|
975
|
-
const t = this.store.get(), s =
|
|
1123
|
+
const t = this.store.get(), s = M(e), i = t.day.date === s ? {
|
|
976
1124
|
date: s,
|
|
977
1125
|
count: t.day.count + 1
|
|
978
1126
|
} : {
|
|
@@ -996,50 +1144,50 @@ var nt = class {
|
|
|
996
1144
|
}
|
|
997
1145
|
dayCount(e) {
|
|
998
1146
|
const t = this.store.get();
|
|
999
|
-
return t.day.date ===
|
|
1147
|
+
return t.day.date === M(e) ? t.day.count : 0;
|
|
1000
1148
|
}
|
|
1001
1149
|
deny(e, t) {
|
|
1002
|
-
return
|
|
1150
|
+
return c.debug(`NudgeGovernor: trigger "${e.id}" blocked — ${t}`), !1;
|
|
1003
1151
|
}
|
|
1004
1152
|
};
|
|
1005
|
-
function
|
|
1153
|
+
function x() {
|
|
1006
1154
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
1007
1155
|
const t = Math.floor(Math.random() * 16);
|
|
1008
1156
|
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
1009
1157
|
});
|
|
1010
1158
|
}
|
|
1011
|
-
function
|
|
1159
|
+
function vt(e) {
|
|
1012
1160
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1013
1161
|
}
|
|
1014
|
-
function
|
|
1162
|
+
function wt(e, t) {
|
|
1015
1163
|
if (e === "*" || e === t) return !0;
|
|
1016
|
-
const s = e.split("/"), i = s.map((
|
|
1017
|
-
const
|
|
1018
|
-
return
|
|
1164
|
+
const s = e.split("/"), i = s.map((n, r) => {
|
|
1165
|
+
const o = r === s.length - 1;
|
|
1166
|
+
return n === "*" ? o ? "[^/]+(?:/[^/]+)*" : "[^/]+" : n.startsWith(":") ? "[^/]+" : vt(n);
|
|
1019
1167
|
});
|
|
1020
1168
|
return new RegExp("^" + i.join("/") + "/?$").test(t);
|
|
1021
1169
|
}
|
|
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) =>
|
|
1170
|
+
function Se(e, t) {
|
|
1171
|
+
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
1172
|
}
|
|
1025
|
-
function
|
|
1026
|
-
if (e.route !== void 0 && !
|
|
1173
|
+
function Et(e, t) {
|
|
1174
|
+
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
1175
|
if (e.fieldErrors !== void 0) {
|
|
1028
1176
|
for (const [s, i] of Object.entries(e.fieldErrors)) if ((t.fieldErrors[s] ?? 0) < i) return !1;
|
|
1029
1177
|
}
|
|
1030
|
-
return !(e.pageState !== void 0 && !
|
|
1178
|
+
return !(e.pageState !== void 0 && !Se(e.pageState, t.pageState ?? {}));
|
|
1031
1179
|
}
|
|
1032
|
-
var
|
|
1180
|
+
var bt = 1e3, St = "/api/sdk/v1/config", _t = "/api/sdk/v1/proactive/evaluate", Ct = class {
|
|
1033
1181
|
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 ??
|
|
1182
|
+
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
1183
|
}
|
|
1036
1184
|
start() {
|
|
1037
1185
|
if (this.started) return;
|
|
1038
1186
|
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
|
-
|
|
1187
|
+
const e = (n) => {
|
|
1188
|
+
n.conversationId && (this.lastConversationId = n.conversationId), this.governor.setTurnInFlight(!0);
|
|
1189
|
+
}, t = () => this.governor.setTurnInFlight(!1), s = () => this.governor.setTurnInFlight(!1), i = (n) => {
|
|
1190
|
+
n?.id && (this.lastConversationId = n.id);
|
|
1043
1191
|
};
|
|
1044
1192
|
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
1193
|
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 +1205,17 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1057
1205
|
}
|
|
1058
1206
|
async loadKillSwitch() {
|
|
1059
1207
|
try {
|
|
1060
|
-
const e = await this.client.getHttp().get(
|
|
1208
|
+
const e = await this.client.getHttp().get(St);
|
|
1061
1209
|
this.governor.setKillSwitch(e?.proactive?.enabled === !0);
|
|
1062
1210
|
} catch (e) {
|
|
1063
|
-
|
|
1211
|
+
c.debug("Proactive config fetch failed; staying disabled:", e), this.governor.setKillSwitch(!1);
|
|
1064
1212
|
}
|
|
1065
1213
|
}
|
|
1066
1214
|
evaluate() {
|
|
1067
1215
|
if (this.lastEvaluationAt = Date.now(), typeof document < "u" && document.visibilityState === "hidden" || this.governor.isSlotOccupied()) return;
|
|
1068
1216
|
const e = this.collector.getSnapshot();
|
|
1069
1217
|
for (const t of this.options.triggers)
|
|
1070
|
-
if (
|
|
1218
|
+
if (Et(t.when, e) && this.governor.canFire(t)) {
|
|
1071
1219
|
this.fire(t);
|
|
1072
1220
|
return;
|
|
1073
1221
|
}
|
|
@@ -1078,7 +1226,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1078
1226
|
return;
|
|
1079
1227
|
}
|
|
1080
1228
|
this.setReady({
|
|
1081
|
-
id:
|
|
1229
|
+
id: x(),
|
|
1082
1230
|
triggerId: e.id,
|
|
1083
1231
|
source: "static",
|
|
1084
1232
|
message: e.intervene.message,
|
|
@@ -1089,7 +1237,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1089
1237
|
});
|
|
1090
1238
|
}
|
|
1091
1239
|
async evaluateWithAgent(e) {
|
|
1092
|
-
const t =
|
|
1240
|
+
const t = x(), s = {
|
|
1093
1241
|
client_nudge_id: t,
|
|
1094
1242
|
trigger_id: e.id,
|
|
1095
1243
|
goal: e.goal ?? "",
|
|
@@ -1100,9 +1248,9 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1100
1248
|
};
|
|
1101
1249
|
let i;
|
|
1102
1250
|
try {
|
|
1103
|
-
i = await this.client.getHttp().post(
|
|
1104
|
-
} catch (
|
|
1105
|
-
|
|
1251
|
+
i = await this.client.getHttp().post(_t, s);
|
|
1252
|
+
} catch (n) {
|
|
1253
|
+
c.debug("Proactive evaluate failed (treated as no-intervene):", n), this.governor.releaseSlot();
|
|
1106
1254
|
return;
|
|
1107
1255
|
}
|
|
1108
1256
|
if (!i?.intervene || !i.message) {
|
|
@@ -1114,7 +1262,7 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1114
1262
|
triggerId: e.id,
|
|
1115
1263
|
source: "agent",
|
|
1116
1264
|
message: i.message,
|
|
1117
|
-
action:
|
|
1265
|
+
action: At(i.action),
|
|
1118
1266
|
goal: e.goal,
|
|
1119
1267
|
kickoff: e.kickoff,
|
|
1120
1268
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -1150,10 +1298,10 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1150
1298
|
source: e.source,
|
|
1151
1299
|
type: "accepted",
|
|
1152
1300
|
occurredAt: Date.now()
|
|
1153
|
-
}), this.clearActive(e), this.client.emitProactiveEvent("nudge:accepted", { nudge: e }), (e.source === "agent" || e.goal) && (this.lastConversationId ? this.client.sendMessage(
|
|
1301
|
+
}), this.clearActive(e), this.client.emitProactiveEvent("nudge:accepted", { nudge: e }), (e.source === "agent" || e.goal) && (this.lastConversationId ? this.client.sendMessage(kt(e), {
|
|
1154
1302
|
hidden: !0,
|
|
1155
1303
|
conversationId: this.lastConversationId
|
|
1156
|
-
}).catch((t) =>
|
|
1304
|
+
}).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
1305
|
}
|
|
1158
1306
|
markConverted(e) {
|
|
1159
1307
|
this.tracker.track({
|
|
@@ -1171,11 +1319,11 @@ var lt = 1e3, ut = "/api/sdk/v1/config", dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
1171
1319
|
try {
|
|
1172
1320
|
"functionName" in e ? await this.client.executeClientFunction(e.functionName, e.arguments ?? {}) : await this.client.executeClientFunction("setPageState", e.setPageState);
|
|
1173
1321
|
} catch (t) {
|
|
1174
|
-
|
|
1322
|
+
c.warn("Nudge action failed:", t);
|
|
1175
1323
|
}
|
|
1176
1324
|
}
|
|
1177
1325
|
};
|
|
1178
|
-
function
|
|
1326
|
+
function At(e) {
|
|
1179
1327
|
if (e)
|
|
1180
1328
|
return {
|
|
1181
1329
|
label: e.label,
|
|
@@ -1183,13 +1331,13 @@ function ft(e) {
|
|
|
1183
1331
|
arguments: e.arguments
|
|
1184
1332
|
};
|
|
1185
1333
|
}
|
|
1186
|
-
function
|
|
1334
|
+
function kt(e) {
|
|
1187
1335
|
const t = e.goal ? ` Goal: ${e.goal}.` : "";
|
|
1188
1336
|
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
1337
|
}
|
|
1190
|
-
var
|
|
1338
|
+
var Rt = 5e3, Tt = "/api/sdk/v1/proactive/events", It = class {
|
|
1191
1339
|
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 ??
|
|
1340
|
+
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
1341
|
const t = () => {
|
|
1194
1342
|
document.visibilityState === "hidden" && this.flush({ keepalive: !0 });
|
|
1195
1343
|
};
|
|
@@ -1216,8 +1364,8 @@ var mt = 5e3, pt = "/api/sdk/v1/proactive/events", yt = class {
|
|
|
1216
1364
|
...this.agent ? { agent: this.agent } : {},
|
|
1217
1365
|
occurred_at: new Date(i.occurredAt).toISOString()
|
|
1218
1366
|
})) };
|
|
1219
|
-
this.post(
|
|
1220
|
-
|
|
1367
|
+
this.post(Tt, s, e).catch((i) => {
|
|
1368
|
+
c.debug("Proactive event batch failed:", i);
|
|
1221
1369
|
});
|
|
1222
1370
|
}
|
|
1223
1371
|
destroy() {
|
|
@@ -1227,81 +1375,81 @@ var mt = 5e3, pt = "/api/sdk/v1/proactive/events", yt = class {
|
|
|
1227
1375
|
this.teardowns = [];
|
|
1228
1376
|
}
|
|
1229
1377
|
}
|
|
1230
|
-
},
|
|
1231
|
-
function
|
|
1232
|
-
e.proactive && (
|
|
1233
|
-
const s = new
|
|
1378
|
+
}, oe = "friction_signals";
|
|
1379
|
+
function ae(e, t) {
|
|
1380
|
+
e.proactive && (c.warn("createAgoProactive: a proactive controller is already attached; replacing it."), e.proactive.destroy());
|
|
1381
|
+
const s = new ht({
|
|
1234
1382
|
...t.signals,
|
|
1235
1383
|
getPageState: () => {
|
|
1236
|
-
const
|
|
1237
|
-
if (!
|
|
1238
|
-
const
|
|
1239
|
-
for (const [
|
|
1240
|
-
return Object.keys(
|
|
1384
|
+
const l = e.getContextSnapshot();
|
|
1385
|
+
if (!l) return null;
|
|
1386
|
+
const d = {};
|
|
1387
|
+
for (const [u, g] of Object.entries(l.entries)) u.startsWith("page-state:") && g.data && Object.assign(d, g.data);
|
|
1388
|
+
return Object.keys(d).length > 0 ? d : null;
|
|
1241
1389
|
}
|
|
1242
1390
|
});
|
|
1243
1391
|
s.start();
|
|
1244
|
-
const i = (
|
|
1245
|
-
s.signalJsError(
|
|
1392
|
+
const i = (l) => {
|
|
1393
|
+
s.signalJsError(l.type);
|
|
1246
1394
|
};
|
|
1247
|
-
e.on("error:captured", i), e.addDynamicContext(
|
|
1248
|
-
const { pageState:
|
|
1395
|
+
e.on("error:captured", i), e.addDynamicContext(oe, () => {
|
|
1396
|
+
const { pageState: l, ...d } = s.getSnapshot({ pageState: !1 });
|
|
1249
1397
|
return {
|
|
1250
1398
|
name: "Friction signals",
|
|
1251
1399
|
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
|
-
data:
|
|
1400
|
+
data: d
|
|
1253
1401
|
};
|
|
1254
1402
|
});
|
|
1255
|
-
const
|
|
1403
|
+
const n = new yt({
|
|
1256
1404
|
frequencyCap: t.frequencyCap,
|
|
1257
1405
|
storage: t.storage,
|
|
1258
1406
|
storageKey: t.storageKey
|
|
1259
|
-
}),
|
|
1260
|
-
post: (
|
|
1407
|
+
}), r = new It({
|
|
1408
|
+
post: (l, d, u) => e.getHttp().post(l, d, u),
|
|
1261
1409
|
agent: e.getConfiguredAgent()
|
|
1262
|
-
}),
|
|
1410
|
+
}), o = new Ct({
|
|
1263
1411
|
client: e,
|
|
1264
1412
|
collector: s,
|
|
1265
|
-
governor:
|
|
1266
|
-
tracker:
|
|
1413
|
+
governor: n,
|
|
1414
|
+
tracker: r,
|
|
1267
1415
|
options: t
|
|
1268
1416
|
});
|
|
1269
|
-
|
|
1270
|
-
const
|
|
1271
|
-
optOut: () =>
|
|
1272
|
-
optIn: () =>
|
|
1273
|
-
isOptedOut: () =>
|
|
1274
|
-
setEngaged: (
|
|
1275
|
-
signalFieldError: (
|
|
1417
|
+
o.start();
|
|
1418
|
+
const a = {
|
|
1419
|
+
optOut: () => n.optOut(),
|
|
1420
|
+
optIn: () => n.optIn(),
|
|
1421
|
+
isOptedOut: () => n.isOptedOut(),
|
|
1422
|
+
setEngaged: (l) => n.setEngaged(l),
|
|
1423
|
+
signalFieldError: (l) => s.signalFieldError(l),
|
|
1276
1424
|
getSignalsSnapshot: () => s.getSnapshot(),
|
|
1277
|
-
getActiveNudge: () =>
|
|
1278
|
-
shown: (
|
|
1279
|
-
accept: (
|
|
1280
|
-
dismiss: (
|
|
1281
|
-
markConverted: (
|
|
1425
|
+
getActiveNudge: () => o.getActiveNudge(),
|
|
1426
|
+
shown: (l) => o.shown(l),
|
|
1427
|
+
accept: (l) => o.accept(l),
|
|
1428
|
+
dismiss: (l) => o.dismiss(l),
|
|
1429
|
+
markConverted: (l) => o.markConverted(l),
|
|
1282
1430
|
destroy: () => {
|
|
1283
|
-
|
|
1431
|
+
o.stop(), r.destroy(), e.off("error:captured", i), s.destroy(), e.removeDynamicContext(oe), e.proactive === a && (e.proactive = null);
|
|
1284
1432
|
}
|
|
1285
1433
|
};
|
|
1286
|
-
return e.proactive =
|
|
1434
|
+
return e.proactive = a, a;
|
|
1287
1435
|
}
|
|
1288
|
-
var
|
|
1436
|
+
var xt = class {
|
|
1289
1437
|
constructor() {
|
|
1290
1438
|
this.entries = /* @__PURE__ */ new Map(), this.dynamicProviders = /* @__PURE__ */ new Map();
|
|
1291
1439
|
}
|
|
1292
1440
|
set(e, t) {
|
|
1293
|
-
this.entries.set(e, t),
|
|
1441
|
+
this.entries.set(e, t), c.log(`ClientContext set: ${e}`);
|
|
1294
1442
|
}
|
|
1295
1443
|
remove(e) {
|
|
1296
1444
|
const t = this.entries.delete(e);
|
|
1297
|
-
return t &&
|
|
1445
|
+
return t && c.log(`ClientContext removed: ${e}`), t;
|
|
1298
1446
|
}
|
|
1299
1447
|
addDynamicProvider(e, t) {
|
|
1300
|
-
this.dynamicProviders.set(e, t),
|
|
1448
|
+
this.dynamicProviders.set(e, t), c.log(`DynamicContext provider added: ${e}`);
|
|
1301
1449
|
}
|
|
1302
1450
|
removeDynamicProvider(e) {
|
|
1303
1451
|
const t = this.dynamicProviders.delete(e);
|
|
1304
|
-
return t &&
|
|
1452
|
+
return t && c.log(`DynamicContext provider removed: ${e}`), t;
|
|
1305
1453
|
}
|
|
1306
1454
|
getSnapshot() {
|
|
1307
1455
|
if (this.entries.size === 0 && this.dynamicProviders.size === 0) return null;
|
|
@@ -1311,69 +1459,69 @@ var vt = class {
|
|
|
1311
1459
|
const i = s();
|
|
1312
1460
|
i && (e[t] = i);
|
|
1313
1461
|
} catch (i) {
|
|
1314
|
-
|
|
1462
|
+
c.error(`DynamicContext provider "${t}" threw:`, i);
|
|
1315
1463
|
}
|
|
1316
1464
|
return Object.keys(e).length === 0 ? null : { entries: e };
|
|
1317
1465
|
}
|
|
1318
1466
|
clear() {
|
|
1319
|
-
this.entries.clear(), this.dynamicProviders.clear(),
|
|
1467
|
+
this.entries.clear(), this.dynamicProviders.clear(), c.log("ClientContext cleared");
|
|
1320
1468
|
}
|
|
1321
|
-
},
|
|
1322
|
-
function
|
|
1469
|
+
}, Ft = "page-state:";
|
|
1470
|
+
function Dt(e) {
|
|
1323
1471
|
const t = {};
|
|
1324
|
-
for (const [s, i] of Object.entries(e)) s.startsWith(
|
|
1472
|
+
for (const [s, i] of Object.entries(e)) s.startsWith(Ft) && i.data && Object.assign(t, i.data);
|
|
1325
1473
|
return t;
|
|
1326
1474
|
}
|
|
1327
|
-
function
|
|
1475
|
+
function $t(e) {
|
|
1328
1476
|
const t = e["current-page"]?.data;
|
|
1329
1477
|
return t?.page ? t.page : t?.url ? t.url : e["browser-page"]?.data?.url;
|
|
1330
1478
|
}
|
|
1331
|
-
function
|
|
1479
|
+
function Mt(e, t) {
|
|
1332
1480
|
return e === t ? !0 : JSON.stringify(e) === JSON.stringify(t);
|
|
1333
1481
|
}
|
|
1334
|
-
function
|
|
1482
|
+
function Pt(e, t) {
|
|
1335
1483
|
const s = [];
|
|
1336
1484
|
for (const i of Object.keys(t))
|
|
1337
|
-
i in e && (
|
|
1485
|
+
i in e && (Mt(e[i], t[i]) || s.push({
|
|
1338
1486
|
field: i,
|
|
1339
1487
|
from: e[i],
|
|
1340
1488
|
to: t[i]
|
|
1341
1489
|
}));
|
|
1342
1490
|
return s;
|
|
1343
1491
|
}
|
|
1344
|
-
function
|
|
1345
|
-
const s =
|
|
1492
|
+
function Nt(e, t) {
|
|
1493
|
+
const s = Dt(t), i = $t(t);
|
|
1346
1494
|
return {
|
|
1347
|
-
changes: e && e.page === i ?
|
|
1495
|
+
changes: e && e.page === i ? Pt(e.state, s) : [],
|
|
1348
1496
|
baseline: {
|
|
1349
1497
|
page: i,
|
|
1350
1498
|
state: s
|
|
1351
1499
|
}
|
|
1352
1500
|
};
|
|
1353
1501
|
}
|
|
1354
|
-
function
|
|
1355
|
-
return e === null || typeof e != "object" ? JSON.stringify(e) ?? "null" : Array.isArray(e) ? `[${e.map(
|
|
1502
|
+
function q(e) {
|
|
1503
|
+
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
1504
|
}
|
|
1357
|
-
var
|
|
1505
|
+
var ce = "", Ot = class {
|
|
1358
1506
|
constructor(e, t = {}) {
|
|
1359
1507
|
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
1508
|
}
|
|
1361
1509
|
async processStream(e) {
|
|
1362
|
-
if (!e.body) throw new
|
|
1510
|
+
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
1511
|
const t = e.body.getReader(), s = new TextDecoder();
|
|
1364
1512
|
try {
|
|
1365
1513
|
for (; ; ) {
|
|
1366
|
-
const { done: i, value:
|
|
1514
|
+
const { done: i, value: n } = await t.read();
|
|
1367
1515
|
if (i) break;
|
|
1368
|
-
const
|
|
1369
|
-
this.buffer +=
|
|
1516
|
+
const r = s.decode(n, { stream: !0 });
|
|
1517
|
+
this.buffer += r, this.processBuffer();
|
|
1370
1518
|
}
|
|
1371
1519
|
return this.buffer.trim() && this.processBuffer(), this.buildFinalMessage();
|
|
1372
1520
|
} catch (i) {
|
|
1373
1521
|
if (this.options.signal?.aborted)
|
|
1374
1522
|
return this.message.status = "CANCELED", this.buildFinalMessage();
|
|
1375
|
-
const
|
|
1376
|
-
throw this.callbacks.onError?.(
|
|
1523
|
+
const n = i instanceof Error ? i : new X("Stream processing failed mid-flight. The connection may have dropped; retry the message.");
|
|
1524
|
+
throw this.callbacks.onError?.(n), n;
|
|
1377
1525
|
} finally {
|
|
1378
1526
|
t.releaseLock();
|
|
1379
1527
|
}
|
|
@@ -1389,12 +1537,12 @@ var ne = "", At = class {
|
|
|
1389
1537
|
`);
|
|
1390
1538
|
for (const i of s)
|
|
1391
1539
|
if (!i.startsWith(": ") && i.startsWith("data: ")) {
|
|
1392
|
-
const
|
|
1540
|
+
const n = i.slice(6);
|
|
1393
1541
|
try {
|
|
1394
|
-
const
|
|
1395
|
-
this.handleChunk(
|
|
1396
|
-
} catch (
|
|
1397
|
-
|
|
1542
|
+
const r = JSON.parse(n);
|
|
1543
|
+
this.handleChunk(r);
|
|
1544
|
+
} catch (r) {
|
|
1545
|
+
c.warn("Failed to parse SSE data:", n, r);
|
|
1398
1546
|
}
|
|
1399
1547
|
}
|
|
1400
1548
|
}
|
|
@@ -1422,9 +1570,9 @@ var ne = "", At = class {
|
|
|
1422
1570
|
url: s.use_external_link ? s.external_link_url : s.internal_link_url
|
|
1423
1571
|
};
|
|
1424
1572
|
})), e.type === "client_function" && e.function_name) {
|
|
1425
|
-
const t = `${e.function_name}::${
|
|
1426
|
-
let
|
|
1427
|
-
i ? s && !i.has(s) && (i.has(
|
|
1573
|
+
const t = `${e.function_name}::${q(e.arguments ?? {})}`, s = e.id || "", i = this.firedClientFunctions.get(t);
|
|
1574
|
+
let n = !1;
|
|
1575
|
+
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
1576
|
invocationId: s,
|
|
1429
1577
|
functionName: e.function_name,
|
|
1430
1578
|
arguments: e.arguments || {},
|
|
@@ -1484,11 +1632,11 @@ var ne = "", At = class {
|
|
|
1484
1632
|
return e.status !== "WAITING_CLIENT" && this.callbacks.onComplete?.(e), e;
|
|
1485
1633
|
}
|
|
1486
1634
|
};
|
|
1487
|
-
function
|
|
1635
|
+
function ns(e) {
|
|
1488
1636
|
const t = e.message.toLowerCase();
|
|
1489
1637
|
return t.includes("load failed") || t.includes("failed to fetch") || t.includes("network") || t.includes("abort");
|
|
1490
1638
|
}
|
|
1491
|
-
var
|
|
1639
|
+
var Lt = /* @__PURE__ */ new Set([
|
|
1492
1640
|
"image/jpeg",
|
|
1493
1641
|
"image/png",
|
|
1494
1642
|
"image/gif",
|
|
@@ -1496,7 +1644,7 @@ var kt = /* @__PURE__ */ new Set([
|
|
|
1496
1644
|
"image/bmp",
|
|
1497
1645
|
"image/tiff"
|
|
1498
1646
|
]);
|
|
1499
|
-
function
|
|
1647
|
+
function jt(e) {
|
|
1500
1648
|
if (!e) return;
|
|
1501
1649
|
const t = typeof window < "u" && window.location ? window.location.href : "https://ago.local/";
|
|
1502
1650
|
try {
|
|
@@ -1505,16 +1653,16 @@ function Rt(e) {
|
|
|
1505
1653
|
} catch {
|
|
1506
1654
|
}
|
|
1507
1655
|
}
|
|
1508
|
-
function
|
|
1509
|
-
return e.isSafeImage === !0 && typeof e.contentType == "string" && e.contentType.startsWith("image/") &&
|
|
1656
|
+
function rs(e) {
|
|
1657
|
+
return e.isSafeImage === !0 && typeof e.contentType == "string" && e.contentType.startsWith("image/") && jt(e.url) !== void 0;
|
|
1510
1658
|
}
|
|
1511
|
-
function
|
|
1659
|
+
function os(e) {
|
|
1512
1660
|
if (e == null || e < 0) return "";
|
|
1513
1661
|
if (e < 1024) return `${e} B`;
|
|
1514
1662
|
const t = e / 1024;
|
|
1515
1663
|
return t < 1024 ? `${t.toFixed(1)} KB` : `${(t / 1024).toFixed(1)} MB`;
|
|
1516
1664
|
}
|
|
1517
|
-
function
|
|
1665
|
+
function Ut(e) {
|
|
1518
1666
|
return {
|
|
1519
1667
|
id: String(e.id ?? ""),
|
|
1520
1668
|
name: typeof e.name == "string" && e.name ? e.name : "file",
|
|
@@ -1524,17 +1672,17 @@ function Tt(e) {
|
|
|
1524
1672
|
isSafeImage: e.is_safe_image === !0
|
|
1525
1673
|
};
|
|
1526
1674
|
}
|
|
1527
|
-
function
|
|
1675
|
+
function as(e) {
|
|
1528
1676
|
return e.map((t, s) => ({
|
|
1529
1677
|
id: `local-${s}-${t.name}`,
|
|
1530
1678
|
name: t.name,
|
|
1531
1679
|
contentType: t.type || void 0,
|
|
1532
1680
|
fileSize: t.size,
|
|
1533
1681
|
url: typeof URL < "u" && URL.createObjectURL ? URL.createObjectURL(t) : void 0,
|
|
1534
|
-
isSafeImage:
|
|
1682
|
+
isSafeImage: Lt.has(t.type)
|
|
1535
1683
|
}));
|
|
1536
1684
|
}
|
|
1537
|
-
var
|
|
1685
|
+
var Wt = class {
|
|
1538
1686
|
constructor() {
|
|
1539
1687
|
this.handlers = /* @__PURE__ */ new Map();
|
|
1540
1688
|
}
|
|
@@ -1550,8 +1698,8 @@ var It = class {
|
|
|
1550
1698
|
s && s.forEach((i) => {
|
|
1551
1699
|
try {
|
|
1552
1700
|
i(t);
|
|
1553
|
-
} catch (
|
|
1554
|
-
console.error(`Error in event handler for ${String(e)}:`,
|
|
1701
|
+
} catch (n) {
|
|
1702
|
+
console.error(`Error in event handler for ${String(e)}:`, n);
|
|
1555
1703
|
}
|
|
1556
1704
|
});
|
|
1557
1705
|
}
|
|
@@ -1563,235 +1711,236 @@ var It = class {
|
|
|
1563
1711
|
}
|
|
1564
1712
|
waitFor(e, t) {
|
|
1565
1713
|
return new Promise((s, i) => {
|
|
1566
|
-
let
|
|
1567
|
-
const
|
|
1568
|
-
|
|
1714
|
+
let n;
|
|
1715
|
+
const r = ((o) => {
|
|
1716
|
+
n && clearTimeout(n), s(o);
|
|
1569
1717
|
});
|
|
1570
|
-
this.once(e,
|
|
1571
|
-
this.off(e,
|
|
1718
|
+
this.once(e, r), t?.timeout && (n = setTimeout(() => {
|
|
1719
|
+
this.off(e, r), i(/* @__PURE__ */ new Error(`waitFor("${String(e)}") timed out after ${t.timeout}ms`));
|
|
1572
1720
|
}, t.timeout));
|
|
1573
1721
|
});
|
|
1574
1722
|
}
|
|
1575
1723
|
removeAllListeners(e) {
|
|
1576
1724
|
e ? this.handlers.delete(e) : this.handlers.clear();
|
|
1577
1725
|
}
|
|
1578
|
-
},
|
|
1579
|
-
function
|
|
1726
|
+
}, Bt = 4e3, Gt = 150, qt = 600;
|
|
1727
|
+
function Kt() {
|
|
1580
1728
|
if (!(typeof document > "u"))
|
|
1581
1729
|
return document.modelContext;
|
|
1582
1730
|
}
|
|
1583
|
-
function
|
|
1731
|
+
function Jt(e, t) {
|
|
1584
1732
|
return new Promise((s) => {
|
|
1585
|
-
let i,
|
|
1586
|
-
const
|
|
1587
|
-
if (!
|
|
1588
|
-
|
|
1589
|
-
for (const
|
|
1590
|
-
|
|
1733
|
+
let i, n = !1;
|
|
1734
|
+
const r = () => {
|
|
1735
|
+
if (!n) {
|
|
1736
|
+
n = !0, clearTimeout(i), clearTimeout(l), clearTimeout(a);
|
|
1737
|
+
for (const u of t) u?.removeEventListener("abort", r);
|
|
1738
|
+
d(), s();
|
|
1591
1739
|
}
|
|
1592
|
-
},
|
|
1593
|
-
clearTimeout(
|
|
1594
|
-
},
|
|
1595
|
-
for (const
|
|
1596
|
-
if (
|
|
1597
|
-
|
|
1740
|
+
}, o = () => {
|
|
1741
|
+
clearTimeout(l), clearTimeout(i), i = setTimeout(r, Gt);
|
|
1742
|
+
}, a = setTimeout(r, Bt), l = setTimeout(r, qt), d = e(o);
|
|
1743
|
+
for (const u of t) {
|
|
1744
|
+
if (u?.aborted) return r();
|
|
1745
|
+
u?.addEventListener("abort", r);
|
|
1598
1746
|
}
|
|
1599
1747
|
});
|
|
1600
1748
|
}
|
|
1601
|
-
function
|
|
1602
|
-
const t =
|
|
1749
|
+
function Ht(e) {
|
|
1750
|
+
const t = Kt();
|
|
1603
1751
|
if (!t)
|
|
1604
|
-
return
|
|
1752
|
+
return c.log("WebMCP is not available in this browser; bridge not attached"), () => {
|
|
1605
1753
|
};
|
|
1606
|
-
const s = t, i = /* @__PURE__ */ new Map(),
|
|
1607
|
-
let
|
|
1608
|
-
function
|
|
1754
|
+
const s = t, i = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = new AbortController();
|
|
1755
|
+
let o = !1, a = !1;
|
|
1756
|
+
function l(y) {
|
|
1609
1757
|
return JSON.stringify([
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1758
|
+
y.description,
|
|
1759
|
+
y.inputSchema,
|
|
1760
|
+
y.annotations
|
|
1613
1761
|
]);
|
|
1614
1762
|
}
|
|
1615
|
-
function
|
|
1616
|
-
const p = e.getFunctionRegistrations().find((
|
|
1763
|
+
function d(y, h) {
|
|
1764
|
+
const p = e.getFunctionRegistrations().find((m) => m.name === y)?.webmcp;
|
|
1617
1765
|
return !p || !p.navigates ? !1 : h?.success !== !1;
|
|
1618
1766
|
}
|
|
1619
|
-
function
|
|
1620
|
-
const
|
|
1767
|
+
function u() {
|
|
1768
|
+
const y = /* @__PURE__ */ new Map();
|
|
1621
1769
|
for (const h of e.getFunctionRegistrations()) {
|
|
1622
1770
|
if (h.webmcp === !1) continue;
|
|
1623
|
-
const p = h.webmcp || void 0,
|
|
1624
|
-
name:
|
|
1771
|
+
const p = h.webmcp || void 0, m = h.name, w = {
|
|
1772
|
+
name: m,
|
|
1625
1773
|
description: h.schema.description,
|
|
1626
1774
|
inputSchema: h.schema.parameters,
|
|
1627
1775
|
annotations: p?.annotations,
|
|
1628
|
-
execute: async (
|
|
1629
|
-
const
|
|
1630
|
-
return !
|
|
1776
|
+
execute: async (E, _e) => {
|
|
1777
|
+
const z = await e.runExternalFunction(m, E ?? {});
|
|
1778
|
+
return !o && d(m, z) && await Jt((Ce) => e.onFunctionsChanged(Ce), [_e?.signal, r.signal]), z;
|
|
1631
1779
|
}
|
|
1632
1780
|
};
|
|
1633
|
-
|
|
1634
|
-
tool:
|
|
1635
|
-
signature:
|
|
1781
|
+
y.set(m, {
|
|
1782
|
+
tool: w,
|
|
1783
|
+
signature: l(w)
|
|
1636
1784
|
});
|
|
1637
1785
|
}
|
|
1638
|
-
return
|
|
1786
|
+
return y;
|
|
1639
1787
|
}
|
|
1640
1788
|
function g() {
|
|
1641
|
-
|
|
1642
|
-
|
|
1789
|
+
o || a || (a = !0, queueMicrotask(() => {
|
|
1790
|
+
a = !1, f();
|
|
1643
1791
|
}));
|
|
1644
1792
|
}
|
|
1645
|
-
function
|
|
1646
|
-
if (
|
|
1647
|
-
const
|
|
1793
|
+
function f() {
|
|
1794
|
+
if (o) return;
|
|
1795
|
+
const y = u();
|
|
1648
1796
|
for (const [h, p] of i)
|
|
1649
|
-
|
|
1650
|
-
for (const [h, p] of
|
|
1797
|
+
y.get(h)?.signature !== p.signature && (p.controller.abort(), i.delete(h));
|
|
1798
|
+
for (const [h, p] of y) {
|
|
1651
1799
|
if (i.has(h)) continue;
|
|
1652
|
-
const
|
|
1800
|
+
const m = new AbortController();
|
|
1653
1801
|
i.set(h, {
|
|
1654
1802
|
signature: p.signature,
|
|
1655
|
-
controller:
|
|
1656
|
-
}), Promise.resolve(s.registerTool(p.tool, { signal:
|
|
1657
|
-
if (
|
|
1803
|
+
controller: m
|
|
1804
|
+
}), Promise.resolve(s.registerTool(p.tool, { signal: m.signal })).catch((w) => {
|
|
1805
|
+
if (c.error(`WebMCP rejected the tool "${h}":`, w), i.get(h)?.controller !== m) return;
|
|
1658
1806
|
i.delete(h);
|
|
1659
|
-
const
|
|
1660
|
-
|
|
1807
|
+
const E = JSON.stringify([h, p.signature]);
|
|
1808
|
+
n.has(E) || (n.add(E), g());
|
|
1661
1809
|
});
|
|
1662
1810
|
}
|
|
1663
1811
|
}
|
|
1664
1812
|
const v = e.onFunctionsChanged(g);
|
|
1665
|
-
return
|
|
1666
|
-
if (!
|
|
1667
|
-
|
|
1668
|
-
for (const
|
|
1669
|
-
i.clear(),
|
|
1813
|
+
return f(), c.log("WebMCP bridge attached"), () => {
|
|
1814
|
+
if (!o) {
|
|
1815
|
+
o = !0, r.abort(), v();
|
|
1816
|
+
for (const y of i.values()) y.controller.abort();
|
|
1817
|
+
i.clear(), c.log("WebMCP bridge detached");
|
|
1670
1818
|
}
|
|
1671
1819
|
};
|
|
1672
1820
|
}
|
|
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));
|
|
1821
|
+
var zt = "/api/sdk/v1/client-function-calls", le = "ago_webmcp_tab";
|
|
1822
|
+
function Xt() {
|
|
1823
|
+
try {
|
|
1824
|
+
const e = sessionStorage.getItem(le);
|
|
1825
|
+
if (e) return e;
|
|
1826
|
+
const t = x();
|
|
1827
|
+
return sessionStorage.setItem(le, t), t;
|
|
1828
|
+
} catch {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1685
1831
|
}
|
|
1686
|
-
function
|
|
1687
|
-
const s =
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1832
|
+
function Vt(e, t) {
|
|
1833
|
+
const { name: s } = t.schema, i = Xt(), n = {
|
|
1834
|
+
function_name: s,
|
|
1835
|
+
arguments: t.args,
|
|
1836
|
+
result: t.error === void 0 ? t.result ?? null : null,
|
|
1837
|
+
error: t.error ?? null,
|
|
1838
|
+
duration_ms: t.durationMs,
|
|
1839
|
+
...i ? { tab_id: i } : {},
|
|
1840
|
+
...e.declared.has(s) ? {} : { client_functions: [t.schema] }
|
|
1695
1841
|
};
|
|
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);
|
|
1842
|
+
e.post(zt, n, t.navigates ? { keepalive: !0 } : void 0).then(() => {
|
|
1843
|
+
e.declared.add(s);
|
|
1844
|
+
}).catch((r) => {
|
|
1845
|
+
c.debug("External call report failed:", r);
|
|
1704
1846
|
});
|
|
1705
|
-
return i || t.filter((r) => r.path !== "/" && e.startsWith(r.path)).sort((r, n) => n.path.length - r.path.length)[0];
|
|
1706
1847
|
}
|
|
1707
|
-
var
|
|
1708
|
-
function
|
|
1848
|
+
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;
|
|
1849
|
+
function he(e, t = "AgoClient") {
|
|
1850
|
+
if (typeof e != "object" || e === null) throw new S(`${t}: ${ue}`, "config_missing_base_url");
|
|
1851
|
+
const s = e.baseUrl;
|
|
1852
|
+
if (typeof s != "string" || s.trim() === "") throw new S(`${t}: ${ue}`, "config_missing_base_url");
|
|
1853
|
+
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).`)));
|
|
1854
|
+
}
|
|
1855
|
+
var Qt = "activity:recent", Zt = "state:delta", ge = "errors:recent";
|
|
1856
|
+
function fe(e) {
|
|
1709
1857
|
return e === "setPageState" ? "readPageData" : `read${e.charAt(0).toUpperCase()}${e.slice(1)}Data`;
|
|
1710
1858
|
}
|
|
1711
|
-
var
|
|
1859
|
+
var cs = class R {
|
|
1712
1860
|
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,
|
|
1861
|
+
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
1862
|
this.eventEmitter.emit("functions:changed", this.functionRegistry.getSchemas());
|
|
1715
|
-
}), t.debug &&
|
|
1863
|
+
}), 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
1864
|
}
|
|
1717
1865
|
attachWebMCPBridge() {
|
|
1718
|
-
!this.config.webmcp || this.detachWebMCP || (this.detachWebMCP =
|
|
1866
|
+
!this.config.webmcp || this.detachWebMCP || (this.detachWebMCP = Ht(this));
|
|
1719
1867
|
}
|
|
1720
1868
|
async sendMessage(t, s) {
|
|
1721
|
-
|
|
1869
|
+
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");
|
|
1870
|
+
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, d = {
|
|
1722
1871
|
content: t,
|
|
1723
1872
|
conversation_id: s?.conversationId,
|
|
1724
|
-
agent_id: s?.agentId ||
|
|
1873
|
+
agent_id: s?.agentId || r
|
|
1725
1874
|
};
|
|
1726
|
-
|
|
1727
|
-
const
|
|
1875
|
+
a != null && (d.metadata = a), i.length > 0 && (d.client_functions = i, o === "pause" && (d.client_functions_mode = o)), n && (d.client_context = n), s?.hidden && (d.hidden = !0);
|
|
1876
|
+
const u = this.beginTurn();
|
|
1728
1877
|
let g;
|
|
1729
1878
|
if (s?.files && s.files.length > 0) {
|
|
1730
|
-
const
|
|
1731
|
-
|
|
1732
|
-
for (const v of s.files)
|
|
1733
|
-
g = await this.sendRequest(
|
|
1734
|
-
} else g = await this.sendRequest(
|
|
1735
|
-
return g ? this.processSSEResponse(g,
|
|
1879
|
+
const f = new FormData();
|
|
1880
|
+
f.append("content", t), l !== void 0 && f.append("metadata", l), s.conversationId && f.append("conversation_id", s.conversationId), (s.agentId || r) && f.append("agent_id", s.agentId || r || ""), i.length > 0 && (f.append("client_functions", JSON.stringify(i)), o === "pause" && f.append("client_functions_mode", o)), n && f.append("client_context", JSON.stringify(n)), s.hidden && f.append("hidden", "true");
|
|
1881
|
+
for (const v of s.files) f.append("files", v);
|
|
1882
|
+
g = await this.sendRequest(u, () => this.httpClient.postFormData("/api/sdk/v1/messages", f, { signal: u.controller.signal }));
|
|
1883
|
+
} else g = await this.sendRequest(u, () => this.httpClient.postStream("/api/sdk/v1/messages", d, { signal: u.controller.signal }));
|
|
1884
|
+
return g ? this.processSSEResponse(g, u) : this.buildStoppedMessage(u);
|
|
1736
1885
|
}
|
|
1737
1886
|
async sendRequest(t, s) {
|
|
1738
1887
|
try {
|
|
1739
1888
|
return await s();
|
|
1740
1889
|
} catch (i) {
|
|
1741
|
-
if (this.endTurn(t),
|
|
1890
|
+
if (this.endTurn(t), O(i)) return null;
|
|
1742
1891
|
throw i;
|
|
1743
1892
|
}
|
|
1744
1893
|
}
|
|
1745
1894
|
async processSSEResponse(t, s) {
|
|
1746
1895
|
let i = !1;
|
|
1747
|
-
const
|
|
1748
|
-
onRawChunk: (
|
|
1749
|
-
s && (
|
|
1896
|
+
const n = new Ot({
|
|
1897
|
+
onRawChunk: (r) => {
|
|
1898
|
+
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
1899
|
},
|
|
1751
|
-
onStart: (
|
|
1752
|
-
this.eventEmitter.emit("message:start",
|
|
1900
|
+
onStart: (r) => {
|
|
1901
|
+
this.eventEmitter.emit("message:start", r);
|
|
1753
1902
|
},
|
|
1754
|
-
onChunk: (
|
|
1755
|
-
this.eventEmitter.emit("message:chunk",
|
|
1903
|
+
onChunk: (r) => {
|
|
1904
|
+
this.eventEmitter.emit("message:chunk", r);
|
|
1756
1905
|
},
|
|
1757
|
-
onToolCall: (
|
|
1758
|
-
this.eventEmitter.emit("toolCall:received",
|
|
1906
|
+
onToolCall: (r) => {
|
|
1907
|
+
this.eventEmitter.emit("toolCall:received", r), r.type === "form" && this.eventEmitter.emit("toolCall:form", r);
|
|
1759
1908
|
},
|
|
1760
|
-
onClientFunction: async (
|
|
1761
|
-
if (i = !0, this.eventEmitter.emit("function:invoke",
|
|
1762
|
-
this.pendingApprovals.set(
|
|
1909
|
+
onClientFunction: async (r) => {
|
|
1910
|
+
if (i = !0, this.eventEmitter.emit("function:invoke", r), this.recordAgentAction(r), r.invocationId && this.requiresApproval(r)) {
|
|
1911
|
+
this.pendingApprovals.set(r.invocationId, r), this.eventEmitter.emit("function:awaiting-approval", r);
|
|
1763
1912
|
return;
|
|
1764
1913
|
}
|
|
1765
|
-
await this.handleClientFunctionInvocation(
|
|
1914
|
+
await this.handleClientFunctionInvocation(r);
|
|
1766
1915
|
},
|
|
1767
|
-
onTitle: (
|
|
1768
|
-
this.eventEmitter.emit("conversation:title",
|
|
1916
|
+
onTitle: (r) => {
|
|
1917
|
+
this.eventEmitter.emit("conversation:title", r);
|
|
1769
1918
|
},
|
|
1770
|
-
onAnswerComplete: (
|
|
1771
|
-
this.eventEmitter.emit("message:answer-complete",
|
|
1919
|
+
onAnswerComplete: (r) => {
|
|
1920
|
+
this.eventEmitter.emit("message:answer-complete", r);
|
|
1772
1921
|
},
|
|
1773
|
-
onWaitingClient: (
|
|
1922
|
+
onWaitingClient: (r) => {
|
|
1774
1923
|
this.pausedTurn = {
|
|
1775
|
-
messageId:
|
|
1776
|
-
conversationId:
|
|
1777
|
-
}, this.eventEmitter.emit("message:waiting-client",
|
|
1924
|
+
messageId: r.messageId,
|
|
1925
|
+
conversationId: r.conversationId
|
|
1926
|
+
}, this.eventEmitter.emit("message:waiting-client", r), this.markResumeSignal(r.messageId, r.conversationId, "waitingConfirmed");
|
|
1778
1927
|
},
|
|
1779
|
-
onComplete: (
|
|
1780
|
-
s?.stopRequested && !
|
|
1928
|
+
onComplete: (r) => {
|
|
1929
|
+
s?.stopRequested && !r.id || this.eventEmitter.emit("message:complete", r);
|
|
1781
1930
|
},
|
|
1782
|
-
onError: (
|
|
1931
|
+
onError: (r) => {
|
|
1783
1932
|
this.eventEmitter.emit("message:error", {
|
|
1784
|
-
error:
|
|
1785
|
-
code:
|
|
1933
|
+
error: r.message,
|
|
1934
|
+
code: r instanceof S ? r.code : void 0
|
|
1786
1935
|
});
|
|
1787
1936
|
}
|
|
1788
1937
|
}, { signal: s?.controller.signal });
|
|
1789
1938
|
try {
|
|
1790
|
-
const
|
|
1791
|
-
return s?.stopRequested && (this.postStopForTurn(s, s.messageId ??
|
|
1792
|
-
conversationId: s.conversationId ??
|
|
1793
|
-
messageId: s.messageId ??
|
|
1794
|
-
})),
|
|
1939
|
+
const r = await n.processStream(t);
|
|
1940
|
+
return s?.stopRequested && (this.postStopForTurn(s, s.messageId ?? r.id), this.eventEmitter.emit("message:stopped", {
|
|
1941
|
+
conversationId: s.conversationId ?? r.conversationId ?? "",
|
|
1942
|
+
messageId: s.messageId ?? r.id ?? ""
|
|
1943
|
+
})), r.status !== "WAITING_CLIENT" && this.maybeFlagEmptyReply(r, i), r;
|
|
1795
1944
|
} finally {
|
|
1796
1945
|
s && this.endTurn(s);
|
|
1797
1946
|
}
|
|
@@ -1800,8 +1949,8 @@ var Vt = class k {
|
|
|
1800
1949
|
const t = this.activeTurn;
|
|
1801
1950
|
if (t) {
|
|
1802
1951
|
t.stopRequested = !0;
|
|
1803
|
-
const
|
|
1804
|
-
return t.controller.abort(),
|
|
1952
|
+
const n = t.messageId;
|
|
1953
|
+
return t.controller.abort(), n ? this.postStopForTurn(t, n) : null;
|
|
1805
1954
|
}
|
|
1806
1955
|
const s = this.pausedTurn;
|
|
1807
1956
|
if (!s) return null;
|
|
@@ -1809,8 +1958,8 @@ var Vt = class k {
|
|
|
1809
1958
|
let i = null;
|
|
1810
1959
|
try {
|
|
1811
1960
|
i = await this.stopMessage(s.messageId);
|
|
1812
|
-
} catch (
|
|
1813
|
-
|
|
1961
|
+
} catch (n) {
|
|
1962
|
+
c.warn("Failed to stop the paused turn:", n);
|
|
1814
1963
|
}
|
|
1815
1964
|
return this.eventEmitter.emit("message:stopped", {
|
|
1816
1965
|
conversationId: s.conversationId,
|
|
@@ -1847,7 +1996,7 @@ var Vt = class k {
|
|
|
1847
1996
|
try {
|
|
1848
1997
|
return await this.stopMessage(s);
|
|
1849
1998
|
} catch (i) {
|
|
1850
|
-
return
|
|
1999
|
+
return c.warn("Failed to stop the turn server-side:", i), null;
|
|
1851
2000
|
}
|
|
1852
2001
|
}
|
|
1853
2002
|
buildStoppedMessage(t) {
|
|
@@ -1873,22 +2022,22 @@ var Vt = class k {
|
|
|
1873
2022
|
};
|
|
1874
2023
|
}
|
|
1875
2024
|
async continueMessage(t) {
|
|
1876
|
-
const s = this.functionRegistry.getSchemas(), i = this.buildSendContext(),
|
|
1877
|
-
s.length > 0 && (
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
const
|
|
1881
|
-
return
|
|
2025
|
+
const s = this.functionRegistry.getSchemas(), i = this.buildSendContext(), n = {};
|
|
2026
|
+
s.length > 0 && (n.client_functions = s), i && (n.client_context = i);
|
|
2027
|
+
const r = this.beginTurn();
|
|
2028
|
+
r.messageId = t;
|
|
2029
|
+
const o = await this.sendRequest(r, () => this.httpClient.postStream(`/api/sdk/v1/messages/${t}/continue`, n, { signal: r.controller.signal }));
|
|
2030
|
+
return o ? this.processSSEResponse(o, r) : this.buildStoppedMessage(r);
|
|
1882
2031
|
}
|
|
1883
2032
|
markResumeSignal(t, s, i) {
|
|
1884
2033
|
if (!t) return;
|
|
1885
|
-
const
|
|
2034
|
+
const n = this.pendingResumes.get(t) ?? {
|
|
1886
2035
|
conversationId: s,
|
|
1887
2036
|
waitingConfirmed: !1,
|
|
1888
2037
|
resultsReady: !1,
|
|
1889
2038
|
started: !1
|
|
1890
2039
|
};
|
|
1891
|
-
|
|
2040
|
+
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
2041
|
}
|
|
1893
2042
|
async runAutoResume(t, s) {
|
|
1894
2043
|
try {
|
|
@@ -1897,13 +2046,13 @@ var Vt = class k {
|
|
|
1897
2046
|
messageId: t
|
|
1898
2047
|
});
|
|
1899
2048
|
} catch (i) {
|
|
1900
|
-
|
|
2049
|
+
c.warn("Resume gate threw; resuming anyway:", i);
|
|
1901
2050
|
}
|
|
1902
2051
|
if (this.pendingResumes.delete(t), !this.stoppedTurnIds.delete(t))
|
|
1903
2052
|
try {
|
|
1904
2053
|
await this.continueMessage(t);
|
|
1905
2054
|
} catch (i) {
|
|
1906
|
-
|
|
2055
|
+
c.warn("Auto-resume of paused turn failed:", i);
|
|
1907
2056
|
}
|
|
1908
2057
|
}
|
|
1909
2058
|
maybeFlagEmptyReply(t, s) {
|
|
@@ -1915,26 +2064,26 @@ var Vt = class k {
|
|
|
1915
2064
|
const i = t.conversationId || "(no conversation)";
|
|
1916
2065
|
if (this.warnedEmptyConversations.has(i)) return;
|
|
1917
2066
|
this.warnedEmptyConversations.add(i);
|
|
1918
|
-
const
|
|
1919
|
-
t.id ? console.warn("[AGO] Reply completed with empty content. Possible causes: " + (
|
|
2067
|
+
const n = this.config.agent || this.config.defaultAgentId;
|
|
2068
|
+
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
2069
|
}, 0);
|
|
1921
2070
|
}
|
|
1922
2071
|
async handleClientFunctionInvocation(t) {
|
|
1923
2072
|
let s, i;
|
|
1924
2073
|
try {
|
|
1925
2074
|
s = await this.functionRegistry.execute(t.functionName, t.arguments);
|
|
1926
|
-
} catch (
|
|
1927
|
-
i =
|
|
2075
|
+
} catch (n) {
|
|
2076
|
+
i = n instanceof Error ? n.message : "Unknown error", c.error("Client function execution failed:", n);
|
|
1928
2077
|
}
|
|
1929
2078
|
if (t.invocationId) try {
|
|
1930
|
-
const
|
|
2079
|
+
const n = await this.submitToolCallForm(t.invocationId, {
|
|
1931
2080
|
result: s,
|
|
1932
2081
|
error: i,
|
|
1933
2082
|
_type: "client_function_result"
|
|
1934
2083
|
});
|
|
1935
|
-
|
|
1936
|
-
} catch (
|
|
1937
|
-
|
|
2084
|
+
n?.resume?.ready && this.markResumeSignal(n.resume.message_id, t.conversationId, "resultsReady");
|
|
2085
|
+
} catch (n) {
|
|
2086
|
+
c.error("Failed to submit function result:", n);
|
|
1938
2087
|
}
|
|
1939
2088
|
this.eventEmitter.emit("function:result", {
|
|
1940
2089
|
invocationId: t.invocationId,
|
|
@@ -1947,7 +2096,7 @@ var Vt = class k {
|
|
|
1947
2096
|
if (s) try {
|
|
1948
2097
|
if (s(t)) return !0;
|
|
1949
2098
|
} catch (i) {
|
|
1950
|
-
|
|
2099
|
+
c.warn("approvalPolicy threw; not gating this call:", i);
|
|
1951
2100
|
}
|
|
1952
2101
|
return this.functionRegistry.get(t.functionName)?.requiresApproval === !0;
|
|
1953
2102
|
}
|
|
@@ -1964,13 +2113,13 @@ var Vt = class k {
|
|
|
1964
2113
|
reason: "user_rejected"
|
|
1965
2114
|
};
|
|
1966
2115
|
try {
|
|
1967
|
-
const
|
|
2116
|
+
const n = await this.submitToolCallForm(t, {
|
|
1968
2117
|
result: i,
|
|
1969
2118
|
_type: "client_function_result"
|
|
1970
2119
|
});
|
|
1971
|
-
|
|
1972
|
-
} catch (
|
|
1973
|
-
|
|
2120
|
+
n?.resume?.ready && this.markResumeSignal(n.resume.message_id, s.conversationId, "resultsReady");
|
|
2121
|
+
} catch (n) {
|
|
2122
|
+
c.error("Failed to submit function rejection:", n);
|
|
1974
2123
|
}
|
|
1975
2124
|
this.eventEmitter.emit("function:result", {
|
|
1976
2125
|
invocationId: t,
|
|
@@ -1979,38 +2128,53 @@ var Vt = class k {
|
|
|
1979
2128
|
}
|
|
1980
2129
|
async runExternalFunction(t, s) {
|
|
1981
2130
|
const i = {
|
|
1982
|
-
invocationId: `webmcp-${
|
|
2131
|
+
invocationId: `webmcp-${x()}`,
|
|
1983
2132
|
functionName: t,
|
|
1984
2133
|
arguments: s,
|
|
1985
2134
|
conversationId: ""
|
|
1986
|
-
}, { invocationId:
|
|
2135
|
+
}, { invocationId: n } = i;
|
|
1987
2136
|
this.eventEmitter.emit("function:invoke", i);
|
|
2137
|
+
const r = Date.now();
|
|
1988
2138
|
try {
|
|
1989
|
-
const
|
|
2139
|
+
const o = await this.functionRegistry.execute(t, s);
|
|
1990
2140
|
return this.eventEmitter.emit("function:result", {
|
|
1991
|
-
invocationId:
|
|
1992
|
-
result:
|
|
1993
|
-
}),
|
|
1994
|
-
} catch (
|
|
2141
|
+
invocationId: n,
|
|
2142
|
+
result: o
|
|
2143
|
+
}), this.reportExternalCall(t, s, r, { result: o }), o;
|
|
2144
|
+
} catch (o) {
|
|
2145
|
+
const a = o instanceof Error ? o.message : String(o);
|
|
1995
2146
|
throw this.eventEmitter.emit("function:result", {
|
|
1996
|
-
invocationId:
|
|
2147
|
+
invocationId: n,
|
|
1997
2148
|
result: null,
|
|
1998
|
-
error:
|
|
1999
|
-
}),
|
|
2149
|
+
error: a
|
|
2150
|
+
}), this.reportExternalCall(t, s, r, { error: a }), o;
|
|
2000
2151
|
}
|
|
2001
2152
|
}
|
|
2153
|
+
reportExternalCall(t, s, i, n) {
|
|
2154
|
+
const r = this.functionRegistry.get(t);
|
|
2155
|
+
r && Vt({
|
|
2156
|
+
post: (o, a, l) => this.httpClient.post(o, a, l),
|
|
2157
|
+
declared: this.declaredExternally
|
|
2158
|
+
}, {
|
|
2159
|
+
schema: r.schema,
|
|
2160
|
+
args: s,
|
|
2161
|
+
durationMs: Date.now() - i,
|
|
2162
|
+
navigates: r.webmcp ? r.webmcp.navigates : void 0,
|
|
2163
|
+
...n
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2002
2166
|
async getConversations(t) {
|
|
2003
2167
|
const s = new URLSearchParams();
|
|
2004
2168
|
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(
|
|
2169
|
+
const i = s.toString(), n = await this.httpClient.get(`/api/sdk/v1/conversations${i ? `?${i}` : ""}`), r = (Array.isArray(n.data) ? n.data : []).map((o) => ({
|
|
2170
|
+
id: String(o.id),
|
|
2171
|
+
title: o.title ?? "",
|
|
2172
|
+
lastMessageDate: new Date(o.last_message_at ?? o.created_at ?? 0)
|
|
2009
2173
|
}));
|
|
2010
2174
|
return {
|
|
2011
|
-
data:
|
|
2012
|
-
hasMore:
|
|
2013
|
-
total:
|
|
2175
|
+
data: r,
|
|
2176
|
+
hasMore: n.has_more ?? !1,
|
|
2177
|
+
total: n.total ?? r.length
|
|
2014
2178
|
};
|
|
2015
2179
|
}
|
|
2016
2180
|
async getConversation(t) {
|
|
@@ -2018,22 +2182,22 @@ var Vt = class k {
|
|
|
2018
2182
|
id: s.id,
|
|
2019
2183
|
title: s.title,
|
|
2020
2184
|
lastMessageDate: new Date(s.last_message_at ?? s.created_at ?? 0),
|
|
2021
|
-
messages: s.messages.map((
|
|
2022
|
-
id:
|
|
2185
|
+
messages: s.messages.map((n) => ({
|
|
2186
|
+
id: n.id,
|
|
2023
2187
|
conversationId: s.id,
|
|
2024
|
-
content:
|
|
2025
|
-
role:
|
|
2026
|
-
status:
|
|
2027
|
-
createdAt: new Date(
|
|
2028
|
-
hidden:
|
|
2029
|
-
sources:
|
|
2030
|
-
id:
|
|
2031
|
-
title:
|
|
2032
|
-
url:
|
|
2188
|
+
content: n.content,
|
|
2189
|
+
role: n.role,
|
|
2190
|
+
status: n.status,
|
|
2191
|
+
createdAt: new Date(n.created_at),
|
|
2192
|
+
hidden: n.hidden,
|
|
2193
|
+
sources: n.sources && n.sources.length > 0 ? n.sources.map(({ id: r, title: o, url: a }) => ({
|
|
2194
|
+
id: r,
|
|
2195
|
+
title: o,
|
|
2196
|
+
url: a ?? void 0
|
|
2033
2197
|
})) : void 0,
|
|
2034
|
-
toolCalls:
|
|
2035
|
-
attachments:
|
|
2036
|
-
followUpReplies:
|
|
2198
|
+
toolCalls: R.mapPersistedToolCalls(n.tool_call_data),
|
|
2199
|
+
attachments: n.attachments && n.attachments.length > 0 ? n.attachments.map(Ut) : void 0,
|
|
2200
|
+
followUpReplies: n.follow_up_replies && n.follow_up_replies.length > 0 ? n.follow_up_replies : void 0
|
|
2037
2201
|
}))
|
|
2038
2202
|
};
|
|
2039
2203
|
return this.eventEmitter.emit("conversation:loaded", i), i;
|
|
@@ -2076,8 +2240,8 @@ var Vt = class k {
|
|
|
2076
2240
|
id: i.id,
|
|
2077
2241
|
name: i.name ?? void 0
|
|
2078
2242
|
})),
|
|
2079
|
-
ticketForm: s.ticket_form ?
|
|
2080
|
-
homePage: s.home_page ?
|
|
2243
|
+
ticketForm: s.ticket_form ? R.mapTicketForm(s.ticket_form) : void 0,
|
|
2244
|
+
homePage: s.home_page ? R.mapHomePage(s.home_page) : void 0,
|
|
2081
2245
|
fileAttachmentsEnabled: !!s.file_attachments_enabled,
|
|
2082
2246
|
voiceEnabled: !!s.voice_enabled,
|
|
2083
2247
|
speechToTextEnabled: !!s.speech_to_text_enabled
|
|
@@ -2091,11 +2255,11 @@ var Vt = class k {
|
|
|
2091
2255
|
title: t.title ?? void 0,
|
|
2092
2256
|
subtitle: t.subtitle ?? void 0,
|
|
2093
2257
|
starters: (t.home_starters ?? []).flatMap((i) => {
|
|
2094
|
-
const
|
|
2095
|
-
return !
|
|
2258
|
+
const n = i.description || i.title || "", r = i.initial_message || n;
|
|
2259
|
+
return !n || !r ? [] : [{
|
|
2096
2260
|
id: i.id,
|
|
2097
|
-
label:
|
|
2098
|
-
message:
|
|
2261
|
+
label: n,
|
|
2262
|
+
message: r,
|
|
2099
2263
|
agentId: i.agent_id ?? void 0
|
|
2100
2264
|
}];
|
|
2101
2265
|
}),
|
|
@@ -2151,7 +2315,7 @@ var Vt = class k {
|
|
|
2151
2315
|
async createTicket(t) {
|
|
2152
2316
|
const s = new FormData();
|
|
2153
2317
|
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
|
|
2318
|
+
for (const n of t.files ?? []) s.append("files", n, n.name);
|
|
2155
2319
|
t.ticketFormId && s.append("ticket_form_id", t.ticketFormId);
|
|
2156
2320
|
const i = await (await this.httpClient.postFormData("/api/sdk/v1/tickets", s)).json();
|
|
2157
2321
|
return {
|
|
@@ -2163,41 +2327,41 @@ var Vt = class k {
|
|
|
2163
2327
|
return (await this.getConversation(t)).messages || [];
|
|
2164
2328
|
}
|
|
2165
2329
|
async resumePendingClientFunctions(t) {
|
|
2166
|
-
const s = [...t.messages ?? []].reverse().find((
|
|
2330
|
+
const s = [...t.messages ?? []].reverse().find((a) => a.role === "assistant" && a.status === "WAITING_CLIENT");
|
|
2167
2331
|
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:
|
|
2332
|
+
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));
|
|
2333
|
+
if (r.length > 0)
|
|
2334
|
+
return c.warn("Cannot resume paused turn: function(s) not registered on this page:", r.map((a) => a.functionName)), null;
|
|
2335
|
+
let o = i.length === 0;
|
|
2336
|
+
for (const a of i) {
|
|
2337
|
+
const l = {
|
|
2338
|
+
invocationId: a.id,
|
|
2339
|
+
functionName: a.functionName,
|
|
2340
|
+
arguments: a.arguments ?? {},
|
|
2177
2341
|
conversationId: t.id
|
|
2178
2342
|
};
|
|
2179
|
-
if (this.requiresApproval(
|
|
2180
|
-
this.pendingApprovals.set(
|
|
2343
|
+
if (this.requiresApproval(l)) {
|
|
2344
|
+
this.pendingApprovals.set(a.id, l), this.markResumeSignal(s.id, t.id, "waitingConfirmed"), this.eventEmitter.emit("function:awaiting-approval", l), o = !1;
|
|
2181
2345
|
continue;
|
|
2182
2346
|
}
|
|
2183
|
-
this.eventEmitter.emit("function:invoke",
|
|
2184
|
-
let
|
|
2347
|
+
this.eventEmitter.emit("function:invoke", l);
|
|
2348
|
+
let d, u;
|
|
2185
2349
|
try {
|
|
2186
|
-
|
|
2350
|
+
d = await this.functionRegistry.execute(a.functionName, a.arguments ?? {});
|
|
2187
2351
|
} catch (g) {
|
|
2188
|
-
|
|
2352
|
+
u = g instanceof Error ? g.message : "Unknown error", c.error("Client function execution failed:", g);
|
|
2189
2353
|
}
|
|
2190
2354
|
this.eventEmitter.emit("function:result", {
|
|
2191
|
-
invocationId:
|
|
2192
|
-
result:
|
|
2193
|
-
error:
|
|
2194
|
-
}),
|
|
2195
|
-
result:
|
|
2196
|
-
error:
|
|
2355
|
+
invocationId: a.id,
|
|
2356
|
+
result: d,
|
|
2357
|
+
error: u
|
|
2358
|
+
}), o = (await this.submitToolCallForm(a.id, {
|
|
2359
|
+
result: d,
|
|
2360
|
+
error: u,
|
|
2197
2361
|
_type: "client_function_result"
|
|
2198
|
-
}))?.resume?.ready ??
|
|
2362
|
+
}))?.resume?.ready ?? o;
|
|
2199
2363
|
}
|
|
2200
|
-
return
|
|
2364
|
+
return o ? this.continueMessage(s.id) : null;
|
|
2201
2365
|
}
|
|
2202
2366
|
async submitToolCallForm(t, s) {
|
|
2203
2367
|
return this.httpClient.post(`/api/sdk/v1/tool-calls/${t}/submit`, { formData: s });
|
|
@@ -2224,21 +2388,21 @@ var Vt = class k {
|
|
|
2224
2388
|
});
|
|
2225
2389
|
}
|
|
2226
2390
|
async submitFeedback(t, s, i) {
|
|
2227
|
-
const
|
|
2391
|
+
const n = i?.comment?.trim(), r = i?.reasons?.length ? [...new Set(i.reasons)] : [];
|
|
2228
2392
|
await this.httpClient.post(`/api/sdk/v1/messages/${t}/feedback`, {
|
|
2229
2393
|
rating: s,
|
|
2230
|
-
...
|
|
2231
|
-
...
|
|
2394
|
+
...r.length ? { reasons: r } : {},
|
|
2395
|
+
...n ? { comment: n } : {}
|
|
2232
2396
|
});
|
|
2233
2397
|
}
|
|
2234
2398
|
async submitConversationFeedback(t, s, i) {
|
|
2235
|
-
let
|
|
2236
|
-
if (!
|
|
2237
|
-
const
|
|
2238
|
-
if (!
|
|
2239
|
-
|
|
2399
|
+
let n = i?.lastMessageId;
|
|
2400
|
+
if (!n) {
|
|
2401
|
+
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");
|
|
2402
|
+
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");
|
|
2403
|
+
n = r.id;
|
|
2240
2404
|
}
|
|
2241
|
-
return await this.submitFeedback(
|
|
2405
|
+
return await this.submitFeedback(n, s, i), n;
|
|
2242
2406
|
}
|
|
2243
2407
|
registerFunction(t, s, i) {
|
|
2244
2408
|
typeof t == "object" ? this.functionRegistry.register(t) : this.functionRegistry.register(t, s, i);
|
|
@@ -2262,131 +2426,75 @@ var Vt = class k {
|
|
|
2262
2426
|
async executeClientFunction(t, s) {
|
|
2263
2427
|
return this.functionRegistry.execute(t, s);
|
|
2264
2428
|
}
|
|
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", () => {
|
|
2429
|
+
registerNavigationFunction(t, s, i) {
|
|
2430
|
+
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
2431
|
if (typeof window > "u" || !window.location) return null;
|
|
2324
|
-
const
|
|
2325
|
-
return
|
|
2432
|
+
const n = window.location.href, r = Ye(window.location.pathname, s), o = { url: n };
|
|
2433
|
+
return r && (o.page = r.name), {
|
|
2326
2434
|
name: "Current page",
|
|
2327
2435
|
description: "The page the user is currently viewing.",
|
|
2328
|
-
data:
|
|
2436
|
+
data: o
|
|
2329
2437
|
};
|
|
2330
2438
|
});
|
|
2331
2439
|
}
|
|
2332
2440
|
unregisterNavigationFunction() {
|
|
2333
|
-
this.unregisterFunction(
|
|
2441
|
+
this.unregisterFunction(J), this.listPagesRegistered && (this.unregisterFunction(T), this.listPagesRegistered = !1), this.removeDynamicContext("current-page");
|
|
2334
2442
|
}
|
|
2335
2443
|
registerPageStateFunction(t, s) {
|
|
2336
|
-
const i = s?.functionName ?? "setPageState",
|
|
2337
|
-
this.registerFunction(
|
|
2444
|
+
const i = s?.functionName ?? "setPageState", n = s?.data;
|
|
2445
|
+
this.registerFunction(nt(t, {
|
|
2338
2446
|
name: i,
|
|
2339
2447
|
requiresApproval: s?.requiresApproval,
|
|
2340
|
-
getResultBudget: () =>
|
|
2341
|
-
data:
|
|
2342
|
-
description:
|
|
2343
|
-
maxResultBytes:
|
|
2344
|
-
read: async (
|
|
2448
|
+
getResultBudget: () => n ? this.pageDataBudget(n) : this.functionRegistry.getDefaultMaxResultBytes(),
|
|
2449
|
+
data: n ? {
|
|
2450
|
+
description: n.description,
|
|
2451
|
+
maxResultBytes: n.maxResultBytes,
|
|
2452
|
+
read: async (o) => te(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes(o))
|
|
2345
2453
|
} : void 0
|
|
2346
2454
|
}));
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
description: `Read what the current page is displaying, without changing anything: ${
|
|
2455
|
+
const r = fe(i);
|
|
2456
|
+
n ? (this.warnIfPlaceholderMode(i), this.registerFunction(r, async () => ({ data: te(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes({})) }), {
|
|
2457
|
+
description: `Read what the current page is displaying, without changing anything: ${n.description}`,
|
|
2350
2458
|
parameters: {
|
|
2351
2459
|
type: "object",
|
|
2352
2460
|
properties: {}
|
|
2353
2461
|
},
|
|
2354
|
-
maxResultBytes:
|
|
2355
|
-
}), this.pageDataCompanions.add(
|
|
2356
|
-
const
|
|
2357
|
-
if (
|
|
2358
|
-
const
|
|
2359
|
-
for (const
|
|
2462
|
+
maxResultBytes: n.maxResultBytes
|
|
2463
|
+
}), this.pageDataCompanions.add(r)) : this.pageDataCompanions.delete(r) && this.unregisterFunction(r), this.addDynamicContext(`page-state:${i}`, () => {
|
|
2464
|
+
const o = t.filter((l) => typeof l.get == "function");
|
|
2465
|
+
if (o.length === 0) return null;
|
|
2466
|
+
const a = {};
|
|
2467
|
+
for (const l of o) a[l.name] = l.get();
|
|
2360
2468
|
return {
|
|
2361
2469
|
name: "Page state",
|
|
2362
2470
|
description: "Current, editable state of the page the user is viewing.",
|
|
2363
|
-
data:
|
|
2471
|
+
data: a
|
|
2364
2472
|
};
|
|
2365
2473
|
});
|
|
2366
2474
|
}
|
|
2367
2475
|
unregisterPageStateFunction(t) {
|
|
2368
2476
|
const s = t ?? "setPageState";
|
|
2369
2477
|
this.unregisterFunction(s);
|
|
2370
|
-
const i =
|
|
2478
|
+
const i = fe(s);
|
|
2371
2479
|
this.pageDataCompanions.delete(i) && this.unregisterFunction(i), this.removeDynamicContext(`page-state:${s}`);
|
|
2372
2480
|
}
|
|
2373
2481
|
pageDataBudget(t) {
|
|
2374
2482
|
return t.maxResultBytes ?? this.functionRegistry.getDefaultMaxResultBytes();
|
|
2375
2483
|
}
|
|
2376
2484
|
envelopeBytes(t) {
|
|
2377
|
-
return
|
|
2485
|
+
return b(JSON.stringify({
|
|
2378
2486
|
...t,
|
|
2379
2487
|
data: null
|
|
2380
2488
|
})) - 4;
|
|
2381
2489
|
}
|
|
2382
2490
|
readPageData(t, s, i) {
|
|
2383
|
-
return
|
|
2491
|
+
return qe(() => s, i?.settleTimeoutMs ?? 1e4).catch((n) => (c.warn(`Reading page data for "${t}" failed:`, n), {
|
|
2384
2492
|
error: "page_data_unavailable",
|
|
2385
|
-
message:
|
|
2493
|
+
message: n instanceof Error ? n.message : String(n)
|
|
2386
2494
|
}));
|
|
2387
2495
|
}
|
|
2388
2496
|
warnIfPlaceholderMode(t) {
|
|
2389
|
-
this.warnedPageDataPlaceholder || this.config.clientFunctionsMode === "placeholder" && (this.warnedPageDataPlaceholder = !0,
|
|
2497
|
+
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
2498
|
}
|
|
2391
2499
|
setContext(t, s) {
|
|
2392
2500
|
this.contextRegistry.set(t, s), this.notifyContextChanged();
|
|
@@ -2440,10 +2548,10 @@ ${r}`,
|
|
|
2440
2548
|
return this.contextRegistry.getSnapshot();
|
|
2441
2549
|
}
|
|
2442
2550
|
buildSendContext() {
|
|
2443
|
-
const t = this.contextRegistry.getSnapshot(), s = t?.entries ?? {}, { changes: i, baseline:
|
|
2444
|
-
return this.lastSentPageState =
|
|
2551
|
+
const t = this.contextRegistry.getSnapshot(), s = t?.entries ?? {}, { changes: i, baseline: n } = Nt(this.lastSentPageState, s);
|
|
2552
|
+
return this.lastSentPageState = n, i.length === 0 ? t : { entries: {
|
|
2445
2553
|
...s,
|
|
2446
|
-
[
|
|
2554
|
+
[Zt]: {
|
|
2447
2555
|
name: "State changes",
|
|
2448
2556
|
description: "Fields in the page state that changed since your last message, as field: <old> -> <new>.",
|
|
2449
2557
|
data: { changes: i }
|
|
@@ -2465,54 +2573,54 @@ ${r}`,
|
|
|
2465
2573
|
}
|
|
2466
2574
|
recordAgentAction(t) {
|
|
2467
2575
|
const s = t.functionName, i = t.arguments;
|
|
2468
|
-
let
|
|
2576
|
+
let n, r;
|
|
2469
2577
|
if (s === "navigateToPage") {
|
|
2470
|
-
const
|
|
2471
|
-
|
|
2472
|
-
} else s === "setPageState" ? (
|
|
2578
|
+
const o = i?.page;
|
|
2579
|
+
n = "agent.navigate", r = o ? `Agent navigated to "${String(o)}"` : "Agent navigated";
|
|
2580
|
+
} else s === "setPageState" ? (n = "agent.page_state", r = "Agent changed the page state") : (n = `agent.${s}`, r = `Agent ran "${s}"`);
|
|
2473
2581
|
this.addActivity({
|
|
2474
2582
|
actor: "agent",
|
|
2475
|
-
name:
|
|
2476
|
-
summary:
|
|
2583
|
+
name: n,
|
|
2584
|
+
summary: r,
|
|
2477
2585
|
...i && Object.keys(i).length > 0 ? { data: { arguments: i } } : {}
|
|
2478
2586
|
});
|
|
2479
2587
|
}
|
|
2480
2588
|
registerActivityContext() {
|
|
2481
|
-
this.contextRegistry.addDynamicProvider(
|
|
2589
|
+
this.contextRegistry.addDynamicProvider(Qt, () => {
|
|
2482
2590
|
const t = this.activityLedger.getRecent();
|
|
2483
2591
|
return t.length === 0 ? null : {
|
|
2484
2592
|
name: "Recent activity",
|
|
2485
|
-
description: "Recent actions by the user and the agent in the app, oldest first. Use this to understand what just happened before this message.",
|
|
2593
|
+
description: "Recent actions by the user and the agent in the app, oldest first. Use this to understand what just happened before this message. Use current-page for the user’s current location.",
|
|
2486
2594
|
data: { events: t }
|
|
2487
2595
|
};
|
|
2488
2596
|
});
|
|
2489
2597
|
}
|
|
2490
2598
|
enableErrorWatcher(t) {
|
|
2491
2599
|
this.disableErrorWatcher();
|
|
2492
|
-
const s = new
|
|
2600
|
+
const s = new $e(t);
|
|
2493
2601
|
this.errorWatcher = s, s.start(), s.subscribe((i) => {
|
|
2494
2602
|
this.eventEmitter.emit("error:captured", i), this.notifyContextChanged();
|
|
2495
|
-
}), this.contextRegistry.addDynamicProvider(
|
|
2603
|
+
}), this.contextRegistry.addDynamicProvider(ge, () => {
|
|
2496
2604
|
const i = s.getErrors();
|
|
2497
2605
|
if (i.length === 0) return null;
|
|
2498
|
-
const
|
|
2606
|
+
const n = Date.now();
|
|
2499
2607
|
return {
|
|
2500
2608
|
name: "Recent JavaScript errors",
|
|
2501
2609
|
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
|
-
...
|
|
2610
|
+
data: { errors: i.map(({ firstAt: r, lastAt: o, ...a }) => ({
|
|
2611
|
+
...a,
|
|
2612
|
+
ageMs: Math.max(0, n - o),
|
|
2613
|
+
...r !== o ? { firstSeenAgoMs: Math.max(0, n - r) } : {}
|
|
2506
2614
|
})) }
|
|
2507
2615
|
};
|
|
2508
2616
|
});
|
|
2509
2617
|
}
|
|
2510
2618
|
disableErrorWatcher() {
|
|
2511
|
-
this.errorWatcher && (this.errorWatcher.destroy(), this.errorWatcher = null, this.contextRegistry.removeDynamicProvider(
|
|
2619
|
+
this.errorWatcher && (this.errorWatcher.destroy(), this.errorWatcher = null, this.contextRegistry.removeDynamicProvider(ge));
|
|
2512
2620
|
}
|
|
2513
2621
|
reportError(t, s) {
|
|
2514
2622
|
if (!this.errorWatcher) {
|
|
2515
|
-
|
|
2623
|
+
c.warn("reportError() ignored: enable the error watcher first (errorWatcher: true).");
|
|
2516
2624
|
return;
|
|
2517
2625
|
}
|
|
2518
2626
|
this.errorWatcher.report(t, s);
|
|
@@ -2537,48 +2645,48 @@ ${r}`,
|
|
|
2537
2645
|
}
|
|
2538
2646
|
updateConfig(t) {
|
|
2539
2647
|
const s = {};
|
|
2540
|
-
for (const [
|
|
2648
|
+
for (const [n, r] of Object.entries(t)) r !== void 0 && (s[n] = r);
|
|
2541
2649
|
const i = {
|
|
2542
2650
|
...this.config,
|
|
2543
2651
|
...s
|
|
2544
2652
|
};
|
|
2545
|
-
|
|
2653
|
+
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
2654
|
}
|
|
2547
2655
|
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,
|
|
2656
|
+
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
2657
|
}
|
|
2550
2658
|
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 &&
|
|
2659
|
+
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
2660
|
}
|
|
2553
|
-
},
|
|
2661
|
+
}, ls = [
|
|
2554
2662
|
"inaccurate",
|
|
2555
2663
|
"incomplete",
|
|
2556
2664
|
"information_not_found",
|
|
2557
2665
|
"technical_issue"
|
|
2558
2666
|
];
|
|
2559
2667
|
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
|
-
|
|
2668
|
+
ke as C,
|
|
2669
|
+
c as S,
|
|
2670
|
+
ht as _,
|
|
2671
|
+
as as a,
|
|
2672
|
+
is as b,
|
|
2673
|
+
jt as c,
|
|
2674
|
+
xt as d,
|
|
2675
|
+
ae as f,
|
|
2676
|
+
gt as g,
|
|
2677
|
+
Se as h,
|
|
2678
|
+
Wt as i,
|
|
2679
|
+
Ot as l,
|
|
2680
|
+
Et as m,
|
|
2681
|
+
cs as n,
|
|
2682
|
+
rs as o,
|
|
2683
|
+
wt as p,
|
|
2684
|
+
he as r,
|
|
2685
|
+
os as s,
|
|
2686
|
+
ls as t,
|
|
2687
|
+
ns as u,
|
|
2688
|
+
Le as v,
|
|
2689
|
+
ts as w,
|
|
2690
|
+
$e as x,
|
|
2691
|
+
ss as y
|
|
2584
2692
|
};
|