@useago/sdk 1.7.2 → 1.9.0
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 +71 -0
- package/README.md +43 -1
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +89 -5
- package/dist/angular.d.ts +89 -5
- package/dist/angular.js +11 -7
- package/dist/{createConversationSession-DP90nY71.js → createConversationSession-BaaXBQ5b.js} +3 -3
- package/dist/createConversationSession-CU0b-t1W.cjs +1 -0
- package/dist/{createFormCollector-BivHRIAe.js → createFormCollector-Cf7kGhCB.js} +1 -1
- package/dist/createFormCollector-DfN1xZBy.cjs +1 -0
- package/dist/{createMockClient-BDLW6tVc.js → createMockClient-5YF-ZbVu.js} +22 -21
- package/dist/createMockClient-BZbOe-23.cjs +1 -0
- package/dist/devtools.cjs +61 -12
- package/dist/devtools.d.cts +90 -5
- package/dist/devtools.d.ts +90 -5
- package/dist/devtools.js +225 -73
- package/dist/errors-BLfjXnLB.js +32 -0
- package/dist/errors-o1IB5fEu.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +100 -3
- package/dist/index.d.ts +100 -3
- package/dist/index.js +77 -75
- package/dist/react.cjs +4 -4
- package/dist/react.d.cts +197 -3
- package/dist/react.d.ts +197 -3
- package/dist/react.js +1034 -752
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +80 -3
- package/dist/testing.d.ts +80 -3
- package/dist/testing.js +1 -1
- package/dist/{AgoClient-DTkBRGFE.js → types-CPga11Of.js} +489 -386
- package/dist/types-D3YQl1jx.cjs +9 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +110 -3
- package/dist/vue.d.ts +110 -3
- package/dist/vue.js +202 -154
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +148 -3
- package/dist/widget.d.ts +148 -3
- package/dist/widget.js +871 -651
- package/llms-full.txt +139 -25
- package/package.json +1 -1
- package/dist/AgoClient-7yXQ6R3O.cjs +0 -9
- package/dist/createConversationSession-Bv6a15E0.cjs +0 -1
- package/dist/createFormCollector-CwfiYn0V.cjs +0 -1
- package/dist/createMockClient-BSNuN3ys.cjs +0 -1
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { a as L, i as R, n as A, r as j, t as C } from "./errors-BLfjXnLB.js";
|
|
2
|
+
var Ee = 10, B = 1e3;
|
|
3
|
+
function lt(t) {
|
|
3
4
|
if (typeof t != "object" || t === null) return !1;
|
|
4
5
|
const e = Object.getPrototypeOf(t);
|
|
5
6
|
return e === Object.prototype || e === null;
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function x(t, e) {
|
|
8
9
|
if (typeof t == "string") {
|
|
9
10
|
if (t.length <= 1e3) return t;
|
|
10
|
-
const s = t.length -
|
|
11
|
-
return t.slice(0,
|
|
11
|
+
const s = t.length - B;
|
|
12
|
+
return t.slice(0, B) + `…[truncated ${s} chars]`;
|
|
12
13
|
}
|
|
13
14
|
if (Array.isArray(t)) {
|
|
14
15
|
if (e.has(t)) return "…[circular]";
|
|
15
16
|
e.add(t);
|
|
16
|
-
const s = t.slice(0, 50).map((i) =>
|
|
17
|
+
const s = t.slice(0, 50).map((i) => x(i, e));
|
|
17
18
|
return t.length > 50 && s.push(`…[+${t.length - 50} more]`), e.delete(t), s;
|
|
18
19
|
}
|
|
19
|
-
if (
|
|
20
|
+
if (lt(t)) {
|
|
20
21
|
if (e.has(t)) return "…[circular]";
|
|
21
22
|
e.add(t);
|
|
22
23
|
const s = {};
|
|
23
|
-
for (const [i, n] of Object.entries(t)) s[i] =
|
|
24
|
+
for (const [i, n] of Object.entries(t)) s[i] = x(n, e);
|
|
24
25
|
return e.delete(t), s;
|
|
25
26
|
}
|
|
26
27
|
return t;
|
|
27
28
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
29
|
+
function ut(t) {
|
|
30
|
+
return x(t, /* @__PURE__ */ new WeakSet());
|
|
30
31
|
}
|
|
31
|
-
var
|
|
32
|
+
var ht = class {
|
|
32
33
|
constructor(t = 10) {
|
|
33
34
|
this.entries = [];
|
|
34
35
|
const e = Math.floor(t);
|
|
@@ -40,7 +41,7 @@ var X = class {
|
|
|
40
41
|
actor: t.actor ?? "user",
|
|
41
42
|
name: t.name,
|
|
42
43
|
summary: t.summary,
|
|
43
|
-
...t.data !== void 0 ? { data:
|
|
44
|
+
...t.data !== void 0 ? { data: ut(t.data) } : {}
|
|
44
45
|
};
|
|
45
46
|
this.entries.push(e);
|
|
46
47
|
const s = this.entries.length - this.maxEntries;
|
|
@@ -55,31 +56,7 @@ var X = class {
|
|
|
55
56
|
clear() {
|
|
56
57
|
this.entries = [];
|
|
57
58
|
}
|
|
58
|
-
},
|
|
59
|
-
constructor(t, e, s) {
|
|
60
|
-
super(t), this.code = e, this.statusCode = s, this.name = "AgoError";
|
|
61
|
-
}
|
|
62
|
-
}, y = class K extends g {
|
|
63
|
-
constructor(e, s, i, n, r, c) {
|
|
64
|
-
super(e, s, i), this.type = n, this.param = r, this.docUrl = c, this.name = "AgoApiError";
|
|
65
|
-
}
|
|
66
|
-
static fromResponse(e, s) {
|
|
67
|
-
const i = e.error;
|
|
68
|
-
return new K(i.doc_url ? `${i.message} See ${i.doc_url}` : i.message, i.code, s, i.type, i.param, i.doc_url);
|
|
69
|
-
}
|
|
70
|
-
}, S = class extends g {
|
|
71
|
-
constructor(t, e) {
|
|
72
|
-
super(t, "network_error"), this.originalError = e, this.name = "AgoNetworkError";
|
|
73
|
-
}
|
|
74
|
-
}, F = class extends g {
|
|
75
|
-
constructor(t, e = "stream_error") {
|
|
76
|
-
super(t, e), this.name = "AgoStreamError";
|
|
77
|
-
}
|
|
78
|
-
}, D = class extends g {
|
|
79
|
-
constructor(t, e, s) {
|
|
80
|
-
super(t, "function_error"), this.functionName = e, this.originalError = s, this.name = "AgoFunctionError";
|
|
81
|
-
}
|
|
82
|
-
}, Y = class {
|
|
59
|
+
}, dt = class {
|
|
83
60
|
constructor(t = !1) {
|
|
84
61
|
this.enabled = t;
|
|
85
62
|
}
|
|
@@ -101,25 +78,25 @@ var X = class {
|
|
|
101
78
|
debug(...t) {
|
|
102
79
|
this.enabled && console.debug("[AGO SDK]", ...t);
|
|
103
80
|
}
|
|
104
|
-
}, l = new
|
|
105
|
-
function
|
|
81
|
+
}, l = new dt(), q = "ago_widget_id";
|
|
82
|
+
function F(t) {
|
|
106
83
|
return typeof DOMException < "u" && t instanceof DOMException && t.name === "AbortError" || t instanceof Error && t.name === "AbortError";
|
|
107
84
|
}
|
|
108
|
-
function
|
|
85
|
+
function ft() {
|
|
109
86
|
if (typeof localStorage < "u") {
|
|
110
|
-
const e = localStorage.getItem(
|
|
87
|
+
const e = localStorage.getItem(q);
|
|
111
88
|
if (e) return e;
|
|
112
89
|
}
|
|
113
90
|
const t = typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `ago-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
114
91
|
if (typeof localStorage < "u") try {
|
|
115
|
-
localStorage.setItem(
|
|
92
|
+
localStorage.setItem(q, t);
|
|
116
93
|
} catch {
|
|
117
94
|
}
|
|
118
95
|
return t;
|
|
119
96
|
}
|
|
120
|
-
var
|
|
97
|
+
var gt = class {
|
|
121
98
|
constructor(t) {
|
|
122
|
-
this.baseUrl = t.baseUrl.replace(/\/$/, ""), this.headers = { "X-User-Anon-Id": t.widgetId ||
|
|
99
|
+
this.baseUrl = t.baseUrl.replace(/\/$/, ""), this.headers = { "X-User-Anon-Id": t.widgetId || ft() }, t.userEmail && (this.headers["X-User-Email"] = t.userEmail), t.userJwt && (this.headers.Authorization = `Bearer ${t.userJwt}`), t.permission && (this.headers["X-Widget-Permission"] = t.permission);
|
|
123
100
|
}
|
|
124
101
|
updateConfig(t) {
|
|
125
102
|
t.baseUrl && (this.baseUrl = t.baseUrl.replace(/\/$/, "")), t.widgetId && (this.headers["X-User-Anon-Id"] = t.widgetId), t.userEmail && (this.headers["X-User-Email"] = t.userEmail), t.userJwt && (this.headers.Authorization = `Bearer ${t.userJwt}`), t.permission !== void 0 && (t.permission ? this.headers["X-Widget-Permission"] = t.permission : delete this.headers["X-Widget-Permission"]);
|
|
@@ -145,7 +122,7 @@ var Q = class {
|
|
|
145
122
|
});
|
|
146
123
|
return n.ok || await this.handleErrorResponse(n), n;
|
|
147
124
|
} catch (n) {
|
|
148
|
-
throw n instanceof
|
|
125
|
+
throw n instanceof C || F(n) ? n : new R(`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);
|
|
149
126
|
}
|
|
150
127
|
}
|
|
151
128
|
async postFormData(t, e, s) {
|
|
@@ -161,7 +138,7 @@ var Q = class {
|
|
|
161
138
|
});
|
|
162
139
|
return r.ok || await this.handleErrorResponse(r), r;
|
|
163
140
|
} catch (r) {
|
|
164
|
-
throw r instanceof
|
|
141
|
+
throw r instanceof C || F(r) ? r : new R(`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);
|
|
165
142
|
}
|
|
166
143
|
}
|
|
167
144
|
async request(t, e, s, i) {
|
|
@@ -179,7 +156,7 @@ var Q = class {
|
|
|
179
156
|
});
|
|
180
157
|
return r.ok || await this.handleErrorResponse(r), r.status === 204 ? void 0 : r.json();
|
|
181
158
|
} catch (r) {
|
|
182
|
-
throw r instanceof
|
|
159
|
+
throw r instanceof C ? r : new R(`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);
|
|
183
160
|
}
|
|
184
161
|
}
|
|
185
162
|
async handleErrorResponse(t) {
|
|
@@ -188,13 +165,13 @@ var Q = class {
|
|
|
188
165
|
e = await t.json();
|
|
189
166
|
} catch {
|
|
190
167
|
}
|
|
191
|
-
if (e?.error) throw
|
|
168
|
+
if (e?.error) throw C.fromResponse(e, t.status);
|
|
192
169
|
let s = "";
|
|
193
|
-
throw t.status === 401 || t.status === 403 ? s = " Check `userJwt` (and that it has not expired)." : t.status === 404 && (s = " Check that `baseUrl` points at your AGO API root."), new
|
|
170
|
+
throw t.status === 401 || t.status === 403 ? s = " Check `userJwt` (and that it has not expired)." : t.status === 404 && (s = " Check that `baseUrl` points at your AGO API root."), new C(`HTTP ${t.status}: ${t.statusText}.${s}`, "http_error", t.status, "api_error");
|
|
194
171
|
}
|
|
195
|
-
},
|
|
172
|
+
}, pt = 5e4, mt = 2e4, yt = 2e3, vt = class {
|
|
196
173
|
constructor(t) {
|
|
197
|
-
this.functions = /* @__PURE__ */ new Map(), this.defaultMaxResultBytes = t?.maxResultBytes ??
|
|
174
|
+
this.functions = /* @__PURE__ */ new Map(), this.defaultMaxResultBytes = t?.maxResultBytes ?? pt;
|
|
198
175
|
}
|
|
199
176
|
setDefaultMaxResultBytes(t) {
|
|
200
177
|
this.defaultMaxResultBytes = t;
|
|
@@ -204,21 +181,21 @@ var Q = class {
|
|
|
204
181
|
}
|
|
205
182
|
register(t, e, s) {
|
|
206
183
|
if (typeof t == "object") {
|
|
207
|
-
const { name:
|
|
208
|
-
return this.register(
|
|
184
|
+
const { name: a, handler: c, description: h, parameters: u, maxResultBytes: d, requiresApproval: m } = t;
|
|
185
|
+
return this.register(a, c, {
|
|
209
186
|
description: h,
|
|
210
187
|
parameters: u,
|
|
211
188
|
maxResultBytes: d,
|
|
212
|
-
requiresApproval:
|
|
189
|
+
requiresApproval: m
|
|
213
190
|
});
|
|
214
191
|
}
|
|
215
192
|
const i = t;
|
|
216
|
-
if (!e || !s) throw new
|
|
193
|
+
if (!e || !s) throw new A(`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");
|
|
217
194
|
this.functions.has(i) && l.warn(`Function "${i}" is being overwritten`);
|
|
218
|
-
const { maxResultBytes: n, requiresApproval: r, ...
|
|
195
|
+
const { maxResultBytes: n, requiresApproval: r, ...o } = s;
|
|
219
196
|
this.functions.set(i, {
|
|
220
197
|
schema: {
|
|
221
|
-
...
|
|
198
|
+
...o,
|
|
222
199
|
name: i
|
|
223
200
|
},
|
|
224
201
|
handler: e,
|
|
@@ -241,13 +218,13 @@ var Q = class {
|
|
|
241
218
|
}
|
|
242
219
|
async execute(t, e) {
|
|
243
220
|
const s = this.functions.get(t);
|
|
244
|
-
if (!s) throw new
|
|
221
|
+
if (!s) throw new j(`Function "${t}" is not registered`, t);
|
|
245
222
|
l.log(`Executing function: ${t}`, e);
|
|
246
223
|
try {
|
|
247
224
|
const i = await s.handler(e);
|
|
248
225
|
return l.log(`Function ${t} completed:`, i), this.guardResultSize(t, i, s.maxResultBytes);
|
|
249
226
|
} catch (i) {
|
|
250
|
-
throw l.error(`Function ${t} failed:`, i), new
|
|
227
|
+
throw l.error(`Function ${t} failed:`, i), new j(`Function "${t}" execution failed: ${i instanceof Error ? i.message : "Unknown error"}`, t, i instanceof Error ? i : void 0);
|
|
251
228
|
}
|
|
252
229
|
}
|
|
253
230
|
guardResultSize(t, e, s) {
|
|
@@ -263,9 +240,9 @@ var Q = class {
|
|
|
263
240
|
truncated: !0,
|
|
264
241
|
originalBytes: n,
|
|
265
242
|
maxBytes: r,
|
|
266
|
-
preview: i.slice(0,
|
|
243
|
+
preview: i.slice(0, yt),
|
|
267
244
|
hint: `The result of "${t}" 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.`
|
|
268
|
-
}) : (n >
|
|
245
|
+
}) : (n > mt && l.warn(`Function "${t}" 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.`), e);
|
|
269
246
|
}
|
|
270
247
|
clear() {
|
|
271
248
|
this.functions.clear(), l.log("Cleared all registered functions");
|
|
@@ -273,22 +250,36 @@ var Q = class {
|
|
|
273
250
|
get size() {
|
|
274
251
|
return this.functions.size;
|
|
275
252
|
}
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
253
|
+
}, wt = new TextEncoder();
|
|
254
|
+
function p(t) {
|
|
255
|
+
return wt.encode(t).length;
|
|
256
|
+
}
|
|
257
|
+
function $(t) {
|
|
258
|
+
return p(JSON.stringify(t)) - 2;
|
|
280
259
|
}
|
|
281
|
-
function
|
|
260
|
+
function it(t, e) {
|
|
261
|
+
if (e <= 0) return "";
|
|
262
|
+
let s = "", i = 0;
|
|
263
|
+
for (const n of t) {
|
|
264
|
+
const r = $(n);
|
|
265
|
+
if (i + r > e) break;
|
|
266
|
+
s += n, i += r;
|
|
267
|
+
}
|
|
268
|
+
return s;
|
|
269
|
+
}
|
|
270
|
+
var St = 50, Ct = 2;
|
|
271
|
+
var At = 2e3;
|
|
272
|
+
function E(t) {
|
|
282
273
|
try {
|
|
283
274
|
return JSON.stringify(t);
|
|
284
275
|
} catch {
|
|
285
276
|
return;
|
|
286
277
|
}
|
|
287
278
|
}
|
|
288
|
-
var
|
|
289
|
-
function
|
|
290
|
-
return e <= 0 ? Promise.resolve(
|
|
291
|
-
const n = setTimeout(() => s(
|
|
279
|
+
var D = /* @__PURE__ */ Symbol("ago.pageData.timeout");
|
|
280
|
+
function Et(t, e) {
|
|
281
|
+
return e <= 0 ? Promise.resolve(D) : new Promise((s, i) => {
|
|
282
|
+
const n = setTimeout(() => s(D), e);
|
|
292
283
|
t.then((r) => {
|
|
293
284
|
clearTimeout(n), s(r);
|
|
294
285
|
}, (r) => {
|
|
@@ -296,25 +287,25 @@ function at(t, e) {
|
|
|
296
287
|
});
|
|
297
288
|
});
|
|
298
289
|
}
|
|
299
|
-
async function
|
|
290
|
+
async function bt(t, e) {
|
|
300
291
|
const s = Date.now() + e;
|
|
301
292
|
let i = 0;
|
|
302
|
-
for (; Date.now() < s && i <
|
|
303
|
-
i = t().isLoading?.() ? 0 : i + 1, await new Promise((
|
|
293
|
+
for (; Date.now() < s && i < Ct; )
|
|
294
|
+
i = t().isLoading?.() ? 0 : i + 1, await new Promise((a) => setTimeout(a, St));
|
|
304
295
|
const n = t().get();
|
|
305
|
-
if (!
|
|
306
|
-
const r = await
|
|
307
|
-
if (r !==
|
|
296
|
+
if (!G(n)) return n;
|
|
297
|
+
const r = await Et(Promise.resolve(n), s - Date.now());
|
|
298
|
+
if (r !== D) return r;
|
|
308
299
|
l.warn("Page data did not resolve within the settle timeout; returning what the page has now. Raise settleTimeoutMs if the work legitimately takes longer.");
|
|
309
|
-
const
|
|
310
|
-
if (!
|
|
311
|
-
Promise.resolve(
|
|
300
|
+
const o = t().get();
|
|
301
|
+
if (!G(o)) return o;
|
|
302
|
+
Promise.resolve(o).catch(() => {
|
|
312
303
|
});
|
|
313
304
|
}
|
|
314
|
-
function
|
|
305
|
+
function G(t) {
|
|
315
306
|
return typeof t == "object" && t !== null && typeof t.then == "function";
|
|
316
307
|
}
|
|
317
|
-
function
|
|
308
|
+
function _t(t) {
|
|
318
309
|
if (typeof t != "object" || t === null || Array.isArray(t)) return;
|
|
319
310
|
const e = t;
|
|
320
311
|
let s;
|
|
@@ -324,85 +315,217 @@ function lt(t) {
|
|
|
324
315
|
}
|
|
325
316
|
return s;
|
|
326
317
|
}
|
|
327
|
-
function
|
|
318
|
+
function Rt(t, e) {
|
|
328
319
|
let s = 2, i = 0;
|
|
329
320
|
for (const n of t) {
|
|
330
|
-
const r =
|
|
321
|
+
const r = p(E(n) ?? "null") + (i > 0 ? 1 : 0);
|
|
331
322
|
if (s + r > e) break;
|
|
332
323
|
s += r, i++;
|
|
333
324
|
}
|
|
334
325
|
return i;
|
|
335
326
|
}
|
|
336
|
-
function
|
|
337
|
-
if (e <= 0) return "";
|
|
338
|
-
const s = (r) => m(JSON.stringify(r)) - 2;
|
|
339
|
-
let i = t.slice(0, e), n = s(i);
|
|
340
|
-
for (; n > e && i.length > 0; )
|
|
341
|
-
i = i.slice(0, Math.max(0, Math.floor(i.length * e / n) - 1)), n = s(i);
|
|
342
|
-
return i;
|
|
343
|
-
}
|
|
344
|
-
function R(t) {
|
|
327
|
+
function N(t) {
|
|
345
328
|
return `The page data returned by "${t}" 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.`;
|
|
346
329
|
}
|
|
347
|
-
function
|
|
330
|
+
function It(t, e, s, i) {
|
|
348
331
|
const n = {
|
|
349
332
|
truncated: !0,
|
|
350
333
|
originalBytes: s,
|
|
351
334
|
maxBytes: i,
|
|
352
335
|
preview: "",
|
|
353
|
-
hint:
|
|
354
|
-
}, r =
|
|
336
|
+
hint: N(t)
|
|
337
|
+
}, r = p(E(n) ?? "{}");
|
|
355
338
|
return {
|
|
356
339
|
...n,
|
|
357
|
-
preview:
|
|
340
|
+
preview: it(e, Math.min(At, i - r))
|
|
358
341
|
};
|
|
359
342
|
}
|
|
360
|
-
function
|
|
361
|
-
const r = s === void 0 ? {} : { ...e },
|
|
343
|
+
function kt(t, e, s, i, n) {
|
|
344
|
+
const r = s === void 0 ? {} : { ...e }, o = s ?? "items", a = p(E({
|
|
362
345
|
...r,
|
|
363
|
-
[
|
|
346
|
+
[o]: [],
|
|
364
347
|
truncation: {
|
|
365
348
|
truncated: !0,
|
|
366
349
|
returnedItems: i.length,
|
|
367
350
|
totalItems: i.length,
|
|
368
|
-
hint:
|
|
351
|
+
hint: N(t)
|
|
369
352
|
}
|
|
370
353
|
}) ?? "{}") - 2;
|
|
371
|
-
if (
|
|
372
|
-
const
|
|
354
|
+
if (a >= n) return;
|
|
355
|
+
const c = i.slice(0, Rt(i, n - a));
|
|
373
356
|
return {
|
|
374
357
|
...r,
|
|
375
|
-
[
|
|
358
|
+
[o]: c,
|
|
376
359
|
truncation: {
|
|
377
360
|
truncated: !0,
|
|
378
|
-
returnedItems:
|
|
361
|
+
returnedItems: c.length,
|
|
379
362
|
totalItems: i.length,
|
|
380
|
-
hint:
|
|
363
|
+
hint: N(t)
|
|
381
364
|
}
|
|
382
365
|
};
|
|
383
366
|
}
|
|
384
|
-
function
|
|
385
|
-
const i =
|
|
367
|
+
function W(t, e, s) {
|
|
368
|
+
const i = E(e);
|
|
386
369
|
if (i === void 0) return e;
|
|
387
|
-
const n =
|
|
370
|
+
const n = p(i);
|
|
388
371
|
if (n <= s) return e;
|
|
389
372
|
l.warn(`Page data for "${t}" 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.`);
|
|
390
|
-
const r =
|
|
391
|
-
if (
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
373
|
+
const r = _t(e), o = Array.isArray(e) ? e : r !== void 0 ? e[r] : void 0;
|
|
374
|
+
if (o) {
|
|
375
|
+
const a = kt(t, e, r, o, s), c = p(E(a) ?? "");
|
|
376
|
+
if (a !== void 0 && c <= s) return a;
|
|
377
|
+
}
|
|
378
|
+
return It(t, i, n, s);
|
|
379
|
+
}
|
|
380
|
+
function _(t, e) {
|
|
381
|
+
if (t === e) return !0;
|
|
382
|
+
if (t === null || e === null || typeof t != "object" || typeof e != "object" || Array.isArray(t) !== Array.isArray(e)) return !1;
|
|
383
|
+
if (Array.isArray(t))
|
|
384
|
+
return t.length !== e.length ? !1 : t.every((n, r) => _(n, e[r]));
|
|
385
|
+
const s = Object.keys(t), i = Object.keys(e);
|
|
386
|
+
return s.length !== i.length ? !1 : s.every((n) => n in e && _(t[n], e[n]));
|
|
387
|
+
}
|
|
388
|
+
var K = 100, I = " … [truncated]", nt = { truncated: !0 }, Tt = p(',"data":' + JSON.stringify(nt));
|
|
389
|
+
function P(t) {
|
|
390
|
+
return p(JSON.stringify(t));
|
|
391
|
+
}
|
|
392
|
+
function J(t, e) {
|
|
393
|
+
if (P(t) <= e || !t.rejected) return t;
|
|
394
|
+
const s = Object.entries(t.rejected), i = Object.fromEntries(s.map(([a]) => [a, I])), n = {
|
|
395
|
+
...t,
|
|
396
|
+
rejected: i
|
|
397
|
+
};
|
|
398
|
+
let r = P(n);
|
|
399
|
+
if (r > e) return n;
|
|
400
|
+
const o = $(I);
|
|
401
|
+
for (const [a, c] of s) {
|
|
402
|
+
const h = $(c), u = e - r + o;
|
|
403
|
+
if (h <= u) {
|
|
404
|
+
i[a] = c, r += h - o;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
i[a] = it(c, u - o) + I;
|
|
408
|
+
break;
|
|
394
409
|
}
|
|
395
|
-
return
|
|
410
|
+
return n;
|
|
411
|
+
}
|
|
412
|
+
function w(t) {
|
|
413
|
+
return Array.isArray(t) ? "array" : typeof t;
|
|
414
|
+
}
|
|
415
|
+
function H(t) {
|
|
416
|
+
return typeof t != "number" ? `Expected type "number", got "${w(t)}".` : Number.isFinite(t) ? null : "Expected a finite number.";
|
|
417
|
+
}
|
|
418
|
+
function rt(t) {
|
|
419
|
+
const e = t.slice(0, K).map((i) => JSON.stringify(i)), s = t.length - K;
|
|
420
|
+
return s > 0 ? `${e.join(", ")} (${s} more not shown)` : e.join(", ");
|
|
421
|
+
}
|
|
422
|
+
function z(t, e) {
|
|
423
|
+
return e.includes(t) ? null : `${JSON.stringify(t)} is not an allowed value. Allowed values: ${rt(e)}.`;
|
|
424
|
+
}
|
|
425
|
+
function xt(t, e) {
|
|
426
|
+
const { schema: s } = e;
|
|
427
|
+
if (s.type === "array") {
|
|
428
|
+
if (!Array.isArray(t)) return `Expected type "array", got "${w(t)}".`;
|
|
429
|
+
for (let n = 0; n < t.length; n++) {
|
|
430
|
+
const r = t[n];
|
|
431
|
+
if (s.items?.type) {
|
|
432
|
+
const o = s.items.type === "number" ? H(r) : w(r) !== s.items.type ? `Expected type "${s.items.type}", got "${w(r)}".` : null;
|
|
433
|
+
if (o) return `Array item at index ${n}: ${o[0].toLowerCase()}${o.slice(1)}`;
|
|
434
|
+
}
|
|
435
|
+
if (s.items?.enum) {
|
|
436
|
+
const o = z(r, s.items.enum);
|
|
437
|
+
if (o) return `Array item ${o}`;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
if (s.type === "number") {
|
|
443
|
+
const n = H(t);
|
|
444
|
+
if (n) return n;
|
|
445
|
+
} else if (w(t) !== s.type) return `Expected type "${s.type}", got "${w(t)}".`;
|
|
446
|
+
const i = at(e);
|
|
447
|
+
return i ? z(t, i) : null;
|
|
448
|
+
}
|
|
449
|
+
function M(t) {
|
|
450
|
+
return t.clearable === !0 && t.schema.type === "string";
|
|
451
|
+
}
|
|
452
|
+
function at(t) {
|
|
453
|
+
const e = t.schema.enum;
|
|
454
|
+
if (e)
|
|
455
|
+
return M(t) && !e.includes("") ? [...e, ""] : e;
|
|
456
|
+
}
|
|
457
|
+
function Ft(t) {
|
|
458
|
+
const e = {
|
|
459
|
+
...t.schema,
|
|
460
|
+
description: t.description
|
|
461
|
+
};
|
|
462
|
+
M(t) && (e.description = `${t.description} Pass "" to clear it.`);
|
|
463
|
+
const s = at(t);
|
|
464
|
+
return s && (e.enum = s), e;
|
|
465
|
+
}
|
|
466
|
+
function $t(t, e) {
|
|
467
|
+
const s = new Map(t.map((r) => [r.name, r])), i = t.map((r) => r.name), n = t.map((r) => `- "${r.name}": ${r.description}`).join(`
|
|
468
|
+
`);
|
|
469
|
+
return {
|
|
470
|
+
name: e.name,
|
|
471
|
+
handler: async (r) => {
|
|
472
|
+
const o = [], a = [], c = {};
|
|
473
|
+
for (const [f, y] of Object.entries(r)) {
|
|
474
|
+
const v = s.get(f);
|
|
475
|
+
if (!v) {
|
|
476
|
+
c[f] = `"${f}" is not a registered control. Available controls: ${rt(i)}.`;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (y == null || y === "" && !M(v)) continue;
|
|
480
|
+
const U = xt(y, v);
|
|
481
|
+
if (U) {
|
|
482
|
+
c[f] = U;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (v.get && _(y, v.get())) {
|
|
486
|
+
a.push(f);
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
const b = await v.set(y);
|
|
490
|
+
b ? b.result === "rejected" ? c[f] = b.reason || "The page rejected this field's update." : b.result === "unchanged" ? a.push(f) : o.push(f) : o.push(f);
|
|
491
|
+
}
|
|
492
|
+
const h = Object.keys(c).length > 0, u = {
|
|
493
|
+
success: !h,
|
|
494
|
+
applied: o,
|
|
495
|
+
unchanged: a,
|
|
496
|
+
...h ? { rejected: c } : {}
|
|
497
|
+
}, d = e.getResultBudget();
|
|
498
|
+
if (!e.data) return J(u, d);
|
|
499
|
+
const m = J(u, d - Tt), S = await e.data.read(m), g = {
|
|
500
|
+
...m,
|
|
501
|
+
data: S
|
|
502
|
+
};
|
|
503
|
+
return P(g) <= d ? g : {
|
|
504
|
+
...m,
|
|
505
|
+
data: nt
|
|
506
|
+
};
|
|
507
|
+
},
|
|
508
|
+
description: (t.length > 0 ? `Change the state of the current page. Set ONLY the controls the user explicitly asked for; leave the others unset. Available controls:
|
|
509
|
+
${n}` : "The current page has no editable state — nothing to change here.") + (e.data ? `
|
|
510
|
+
Returns the resulting page data once it has loaded: ${e.data.description}` : ""),
|
|
511
|
+
parameters: {
|
|
512
|
+
type: "object",
|
|
513
|
+
properties: Object.fromEntries(t.map((r) => [r.name, Ft(r)])),
|
|
514
|
+
required: []
|
|
515
|
+
},
|
|
516
|
+
requiresApproval: e.requiresApproval,
|
|
517
|
+
maxResultBytes: e.data?.maxResultBytes
|
|
518
|
+
};
|
|
396
519
|
}
|
|
397
|
-
var
|
|
520
|
+
var Dt = 250, Nt = 3, Pt = 1e3, Ot = 24, Mt = 10, Ut = 50, Lt = [
|
|
398
521
|
"mousemove",
|
|
399
522
|
"mousedown",
|
|
400
523
|
"keydown",
|
|
401
524
|
"scroll",
|
|
402
525
|
"touchstart"
|
|
403
|
-
],
|
|
526
|
+
], jt = class {
|
|
404
527
|
constructor(t = {}) {
|
|
405
|
-
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.fieldErrors = {}, this.recentClicks = [], this.signals = [], this.listeners = /* @__PURE__ */ new Set(), this.getPageState = t.getPageState, this.activityThrottleMs = t.activityThrottleMs ??
|
|
528
|
+
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.fieldErrors = {}, this.recentClicks = [], this.signals = [], this.listeners = /* @__PURE__ */ new Set(), this.getPageState = t.getPageState, this.activityThrottleMs = t.activityThrottleMs ?? Dt, this.rageClickCount = t.rageClickCount ?? Nt, this.rageClickWindowMs = t.rageClickWindowMs ?? Pt, this.rageClickRadiusPx = t.rageClickRadiusPx ?? Ot, this.maxRecentRoutes = t.maxRecentRoutes ?? Mt, this.maxSignals = t.maxSignals ?? Ut;
|
|
406
529
|
}
|
|
407
530
|
start() {
|
|
408
531
|
if (this.started || typeof window > "u" || typeof document > "u") return;
|
|
@@ -412,7 +535,7 @@ var ft = 250, pt = 3, mt = 1e3, yt = 24, vt = 10, wt = 50, Ct = [
|
|
|
412
535
|
const e = (i, n, r) => {
|
|
413
536
|
i.addEventListener(n, r, { passive: !0 }), this.teardowns.push(() => i.removeEventListener(n, r));
|
|
414
537
|
}, s = () => this.recordActivity();
|
|
415
|
-
for (const i of
|
|
538
|
+
for (const i of Lt) e(window, i, s);
|
|
416
539
|
e(document, "visibilitychange", () => {
|
|
417
540
|
document.visibilityState === "visible" && this.recordActivity();
|
|
418
541
|
}), e(window, "popstate", () => this.checkRoute()), e(window, "hashchange", () => this.checkRoute()), e(window, "click", (i) => this.onClick(i)), l.log("SignalCollector started");
|
|
@@ -497,9 +620,9 @@ var ft = 250, pt = 3, mt = 1e3, yt = 24, vt = 10, wt = 50, Ct = [
|
|
|
497
620
|
y: t.clientY,
|
|
498
621
|
stateKey: s
|
|
499
622
|
};
|
|
500
|
-
this.recentClicks = this.recentClicks.filter((
|
|
501
|
-
const n = this.recentClicks[0], r = !n || Math.abs(i.x - n.x) <= this.rageClickRadiusPx && Math.abs(i.y - n.y) <= this.rageClickRadiusPx,
|
|
502
|
-
if (!r || !
|
|
623
|
+
this.recentClicks = this.recentClicks.filter((a) => e - a.at <= this.rageClickWindowMs);
|
|
624
|
+
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;
|
|
625
|
+
if (!r || !o) {
|
|
503
626
|
this.recentClicks = [i];
|
|
504
627
|
return;
|
|
505
628
|
}
|
|
@@ -528,16 +651,16 @@ var ft = 250, pt = 3, mt = 1e3, yt = 24, vt = 10, wt = 50, Ct = [
|
|
|
528
651
|
}
|
|
529
652
|
}
|
|
530
653
|
};
|
|
531
|
-
function
|
|
654
|
+
function Bt(t, e) {
|
|
532
655
|
const s = e ? e.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
|
|
533
656
|
let i = t;
|
|
534
657
|
if (e && s) try {
|
|
535
|
-
const
|
|
536
|
-
|
|
658
|
+
const a = s.getItem(e.key);
|
|
659
|
+
a != null && (i = JSON.parse(a));
|
|
537
660
|
} catch {
|
|
538
661
|
}
|
|
539
|
-
const n = /* @__PURE__ */ new Set(), r = () => n.forEach((
|
|
540
|
-
function
|
|
662
|
+
const n = /* @__PURE__ */ new Set(), r = () => n.forEach((a) => a(i));
|
|
663
|
+
function o() {
|
|
541
664
|
if (e && s) try {
|
|
542
665
|
s.setItem(e.key, JSON.stringify(i));
|
|
543
666
|
} catch {
|
|
@@ -545,31 +668,31 @@ function At(t, e) {
|
|
|
545
668
|
}
|
|
546
669
|
return {
|
|
547
670
|
get: () => i,
|
|
548
|
-
set: (
|
|
549
|
-
i =
|
|
671
|
+
set: (a) => {
|
|
672
|
+
i = a, o(), r();
|
|
550
673
|
},
|
|
551
|
-
subscribe: (
|
|
552
|
-
n.delete(
|
|
674
|
+
subscribe: (a) => (n.add(a), () => {
|
|
675
|
+
n.delete(a);
|
|
553
676
|
})
|
|
554
677
|
};
|
|
555
678
|
}
|
|
556
|
-
var
|
|
557
|
-
function
|
|
679
|
+
var qt = 6e4, Gt = 1440 * 60 * 1e3, Wt = "ago_proactive";
|
|
680
|
+
function k(t) {
|
|
558
681
|
const e = new Date(t), s = String(e.getMonth() + 1).padStart(2, "0"), i = String(e.getDate()).padStart(2, "0");
|
|
559
682
|
return `${e.getFullYear()}-${s}-${i}`;
|
|
560
683
|
}
|
|
561
|
-
var
|
|
684
|
+
var Kt = class {
|
|
562
685
|
constructor(t = {}) {
|
|
563
|
-
this.killSwitchEnabled = !1, this.engaged = !1, this.turnInFlight = !1, this.slotOccupied = !1, this.sessionCount = 0, this.perSessionCap = t.frequencyCap?.perSession, this.perDayCap = t.frequencyCap?.perDay, this.store =
|
|
686
|
+
this.killSwitchEnabled = !1, this.engaged = !1, this.turnInFlight = !1, this.slotOccupied = !1, this.sessionCount = 0, this.perSessionCap = t.frequencyCap?.perSession, this.perDayCap = t.frequencyCap?.perDay, this.store = Bt({
|
|
564
687
|
optOut: !1,
|
|
565
688
|
lastFiredAt: {},
|
|
566
689
|
dismissedAt: {},
|
|
567
690
|
day: {
|
|
568
|
-
date:
|
|
691
|
+
date: k(Date.now()),
|
|
569
692
|
count: 0
|
|
570
693
|
}
|
|
571
694
|
}, {
|
|
572
|
-
key: t.storageKey ??
|
|
695
|
+
key: t.storageKey ?? Wt,
|
|
573
696
|
storage: t.storage
|
|
574
697
|
});
|
|
575
698
|
}
|
|
@@ -613,10 +736,10 @@ var It = class {
|
|
|
613
736
|
if (this.engaged) return this.deny(t, "user engaged (widget open)");
|
|
614
737
|
if (this.turnInFlight) return this.deny(t, "message turn in flight");
|
|
615
738
|
if (this.slotOccupied) return this.deny(t, "nudge slot occupied");
|
|
616
|
-
const i = s.lastFiredAt[t.id], n = t.cooldownMs ??
|
|
739
|
+
const i = s.lastFiredAt[t.id], n = t.cooldownMs ?? qt;
|
|
617
740
|
if (i !== void 0 && e - i < n) return this.deny(t, "cooldown");
|
|
618
|
-
const r = s.dismissedAt[t.id],
|
|
619
|
-
return r !== void 0 && e - r <
|
|
741
|
+
const r = s.dismissedAt[t.id], o = t.resurfaceAfterMs ?? Gt;
|
|
742
|
+
return r !== void 0 && e - r < o ? this.deny(t, "dismissed recently") : this.perSessionCap !== void 0 && this.sessionCount >= this.perSessionCap ? this.deny(t, "perSession cap") : this.perDayCap !== void 0 && this.dayCount(e) >= this.perDayCap ? this.deny(t, "perDay cap") : !0;
|
|
620
743
|
}
|
|
621
744
|
recordFired(t, e = Date.now()) {
|
|
622
745
|
const s = this.store.get();
|
|
@@ -630,7 +753,7 @@ var It = class {
|
|
|
630
753
|
}
|
|
631
754
|
recordNudgeShown(t = Date.now()) {
|
|
632
755
|
this.sessionCount += 1;
|
|
633
|
-
const e = this.store.get(), s =
|
|
756
|
+
const e = this.store.get(), s = k(t), i = e.day.date === s ? {
|
|
634
757
|
date: s,
|
|
635
758
|
count: e.day.count + 1
|
|
636
759
|
} : {
|
|
@@ -654,53 +777,42 @@ var It = class {
|
|
|
654
777
|
}
|
|
655
778
|
dayCount(t) {
|
|
656
779
|
const e = this.store.get();
|
|
657
|
-
return e.day.date ===
|
|
780
|
+
return e.day.date === k(t) ? e.day.count : 0;
|
|
658
781
|
}
|
|
659
782
|
deny(t, e) {
|
|
660
783
|
return l.debug(`NudgeGovernor: trigger "${t.id}" blocked — ${e}`), !1;
|
|
661
784
|
}
|
|
662
785
|
};
|
|
663
|
-
function
|
|
786
|
+
function X() {
|
|
664
787
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
|
|
665
788
|
const e = Math.floor(Math.random() * 16);
|
|
666
789
|
return (t === "x" ? e : e & 3 | 8).toString(16);
|
|
667
790
|
});
|
|
668
791
|
}
|
|
669
|
-
function
|
|
792
|
+
function Jt(t) {
|
|
670
793
|
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
671
794
|
}
|
|
672
|
-
function
|
|
795
|
+
function Ht(t, e) {
|
|
673
796
|
if (t === "*" || t === e) return !0;
|
|
674
797
|
const s = t.split("/"), i = s.map((n, r) => {
|
|
675
|
-
const
|
|
676
|
-
return n === "*" ?
|
|
798
|
+
const o = r === s.length - 1;
|
|
799
|
+
return n === "*" ? o ? "[^/]+(?:/[^/]+)*" : "[^/]+" : n.startsWith(":") ? "[^/]+" : Jt(n);
|
|
677
800
|
});
|
|
678
801
|
return new RegExp("^" + i.join("/") + "/?$").test(e);
|
|
679
802
|
}
|
|
680
|
-
function
|
|
681
|
-
return t === e ? !0 : t === null || e === null ? !1 : Array.isArray(t) ? !Array.isArray(e) || e.length !== t.length ? !1 : t.every((s, i) =>
|
|
682
|
-
}
|
|
683
|
-
function k(t, e) {
|
|
684
|
-
if (t === e) return !0;
|
|
685
|
-
if (t === null || e === null || typeof t != typeof e) return !1;
|
|
686
|
-
if (Array.isArray(t))
|
|
687
|
-
return !Array.isArray(e) || t.length !== e.length ? !1 : t.every((s, i) => k(s, e[i]));
|
|
688
|
-
if (typeof t == "object") {
|
|
689
|
-
const s = Object.keys(t), i = Object.keys(e);
|
|
690
|
-
return s.length !== i.length ? !1 : s.every((n) => k(t[n], e[n]));
|
|
691
|
-
}
|
|
692
|
-
return !1;
|
|
803
|
+
function ot(t, e) {
|
|
804
|
+
return t === e ? !0 : t === null || e === null ? !1 : Array.isArray(t) ? !Array.isArray(e) || e.length !== t.length ? !1 : t.every((s, i) => _(s, e[i])) : typeof t == "object" ? typeof e != "object" || Array.isArray(e) ? !1 : Object.entries(t).every(([s, i]) => ot(i, e[s])) : !1;
|
|
693
805
|
}
|
|
694
|
-
function
|
|
695
|
-
if (t.route !== void 0 && !
|
|
806
|
+
function zt(t, e) {
|
|
807
|
+
if (t.route !== void 0 && !Ht(t.route, e.route) || t.idleMs !== void 0 && e.idleMs < t.idleMs || t.dwellMs !== void 0 && e.dwellMs < t.dwellMs || t.rageClicks !== void 0 && e.rageClicks < t.rageClicks || t.routeBounces !== void 0 && e.routeBounces < t.routeBounces) return !1;
|
|
696
808
|
if (t.fieldErrors !== void 0) {
|
|
697
809
|
for (const [s, i] of Object.entries(t.fieldErrors)) if ((e.fieldErrors[s] ?? 0) < i) return !1;
|
|
698
810
|
}
|
|
699
|
-
return !(t.pageState !== void 0 && !
|
|
811
|
+
return !(t.pageState !== void 0 && !ot(t.pageState, e.pageState ?? {}));
|
|
700
812
|
}
|
|
701
|
-
var
|
|
813
|
+
var Xt = 1e3, Vt = "/api/sdk/v1/config", Yt = "/api/sdk/v1/proactive/evaluate", Qt = class {
|
|
702
814
|
constructor(t) {
|
|
703
|
-
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 = t.client, this.collector = t.collector, this.governor = t.governor, this.tracker = t.tracker, this.options = t.options, this.tickMs = t.options.tickMs ??
|
|
815
|
+
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 = t.client, this.collector = t.collector, this.governor = t.governor, this.tracker = t.tracker, this.options = t.options, this.tickMs = t.options.tickMs ?? Xt;
|
|
704
816
|
}
|
|
705
817
|
start() {
|
|
706
818
|
if (this.started) return;
|
|
@@ -726,7 +838,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
726
838
|
}
|
|
727
839
|
async loadKillSwitch() {
|
|
728
840
|
try {
|
|
729
|
-
const t = await this.client.getHttp().get(
|
|
841
|
+
const t = await this.client.getHttp().get(Vt);
|
|
730
842
|
this.governor.setKillSwitch(t?.proactive?.enabled === !0);
|
|
731
843
|
} catch (t) {
|
|
732
844
|
l.debug("Proactive config fetch failed; staying disabled:", t), this.governor.setKillSwitch(!1);
|
|
@@ -736,7 +848,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
736
848
|
if (this.lastEvaluationAt = Date.now(), typeof document < "u" && document.visibilityState === "hidden" || this.governor.isSlotOccupied()) return;
|
|
737
849
|
const t = this.collector.getSnapshot();
|
|
738
850
|
for (const e of this.options.triggers)
|
|
739
|
-
if (
|
|
851
|
+
if (zt(e.when, t) && this.governor.canFire(e)) {
|
|
740
852
|
this.fire(e);
|
|
741
853
|
return;
|
|
742
854
|
}
|
|
@@ -747,7 +859,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
747
859
|
return;
|
|
748
860
|
}
|
|
749
861
|
this.setReady({
|
|
750
|
-
id:
|
|
862
|
+
id: X(),
|
|
751
863
|
triggerId: t.id,
|
|
752
864
|
source: "static",
|
|
753
865
|
message: t.intervene.message,
|
|
@@ -758,7 +870,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
758
870
|
});
|
|
759
871
|
}
|
|
760
872
|
async evaluateWithAgent(t) {
|
|
761
|
-
const e =
|
|
873
|
+
const e = X(), s = {
|
|
762
874
|
client_nudge_id: e,
|
|
763
875
|
trigger_id: t.id,
|
|
764
876
|
goal: t.goal ?? "",
|
|
@@ -769,7 +881,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
769
881
|
};
|
|
770
882
|
let i;
|
|
771
883
|
try {
|
|
772
|
-
i = await this.client.getHttp().post(
|
|
884
|
+
i = await this.client.getHttp().post(Yt, s);
|
|
773
885
|
} catch (n) {
|
|
774
886
|
l.debug("Proactive evaluate failed (treated as no-intervene):", n), this.governor.releaseSlot();
|
|
775
887
|
return;
|
|
@@ -783,7 +895,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
783
895
|
triggerId: t.id,
|
|
784
896
|
source: "agent",
|
|
785
897
|
message: i.message,
|
|
786
|
-
action:
|
|
898
|
+
action: Zt(i.action),
|
|
787
899
|
goal: t.goal,
|
|
788
900
|
kickoff: t.kickoff,
|
|
789
901
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -819,7 +931,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
819
931
|
source: t.source,
|
|
820
932
|
type: "accepted",
|
|
821
933
|
occurredAt: Date.now()
|
|
822
|
-
}), this.clearActive(t), this.client.emitProactiveEvent("nudge:accepted", { nudge: t }), (t.source === "agent" || t.goal) && (this.lastConversationId ? this.client.sendMessage(
|
|
934
|
+
}), this.clearActive(t), this.client.emitProactiveEvent("nudge:accepted", { nudge: t }), (t.source === "agent" || t.goal) && (this.lastConversationId ? this.client.sendMessage(te(t), {
|
|
823
935
|
hidden: !0,
|
|
824
936
|
conversationId: this.lastConversationId
|
|
825
937
|
}).catch((e) => l.debug("Nudge kickoff message failed:", e)) : t.kickoff ? this.client.sendMessage(t.kickoff).catch((e) => l.debug("Nudge kickoff message failed:", e)) : l.debug("Nudge accepted with no open conversation and no trigger.kickoff; skipping the chat pre-seed (a hidden message cannot open a conversation).")), t.action && await this.runAction(t.action));
|
|
@@ -844,7 +956,7 @@ var xt = 1e3, Ft = "/api/sdk/v1/config", Dt = "/api/sdk/v1/proactive/evaluate",
|
|
|
844
956
|
}
|
|
845
957
|
}
|
|
846
958
|
};
|
|
847
|
-
function
|
|
959
|
+
function Zt(t) {
|
|
848
960
|
if (t)
|
|
849
961
|
return {
|
|
850
962
|
label: t.label,
|
|
@@ -852,13 +964,13 @@ function Pt(t) {
|
|
|
852
964
|
arguments: t.arguments
|
|
853
965
|
};
|
|
854
966
|
}
|
|
855
|
-
function
|
|
967
|
+
function te(t) {
|
|
856
968
|
const e = t.goal ? ` Goal: ${t.goal}.` : "";
|
|
857
969
|
return `The user accepted a proactive nudge that said: "${t.message}".${e} 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.`;
|
|
858
970
|
}
|
|
859
|
-
var
|
|
971
|
+
var ee = 5e3, se = "/api/sdk/v1/proactive/events", ie = class {
|
|
860
972
|
constructor(t) {
|
|
861
|
-
if (this.queue = [], this.flushTimer = null, this.teardowns = [], this.destroyed = !1, this.post = t.post, this.agent = t.agent, this.flushIntervalMs = t.flushIntervalMs ??
|
|
973
|
+
if (this.queue = [], this.flushTimer = null, this.teardowns = [], this.destroyed = !1, this.post = t.post, this.agent = t.agent, this.flushIntervalMs = t.flushIntervalMs ?? ee, typeof document < "u") {
|
|
862
974
|
const e = () => {
|
|
863
975
|
document.visibilityState === "hidden" && this.flush({ keepalive: !0 });
|
|
864
976
|
};
|
|
@@ -885,7 +997,7 @@ var Mt = 5e3, Ot = "/api/sdk/v1/proactive/events", Ut = class {
|
|
|
885
997
|
...this.agent ? { agent: this.agent } : {},
|
|
886
998
|
occurred_at: new Date(i.occurredAt).toISOString()
|
|
887
999
|
})) };
|
|
888
|
-
this.post(
|
|
1000
|
+
this.post(se, s, t).catch((i) => {
|
|
889
1001
|
l.debug("Proactive event batch failed:", i);
|
|
890
1002
|
});
|
|
891
1003
|
}
|
|
@@ -896,35 +1008,35 @@ var Mt = 5e3, Ot = "/api/sdk/v1/proactive/events", Ut = class {
|
|
|
896
1008
|
this.teardowns = [];
|
|
897
1009
|
}
|
|
898
1010
|
}
|
|
899
|
-
},
|
|
900
|
-
function
|
|
1011
|
+
}, V = "friction_signals";
|
|
1012
|
+
function Y(t, e) {
|
|
901
1013
|
t.proactive && (l.warn("createAgoProactive: a proactive controller is already attached; replacing it."), t.proactive.destroy());
|
|
902
|
-
const s = new
|
|
1014
|
+
const s = new jt({
|
|
903
1015
|
...e.signals,
|
|
904
1016
|
getPageState: () => {
|
|
905
|
-
const
|
|
906
|
-
if (!
|
|
907
|
-
const
|
|
908
|
-
for (const [h, u] of Object.entries(
|
|
909
|
-
return Object.keys(
|
|
1017
|
+
const a = t.getContextSnapshot();
|
|
1018
|
+
if (!a) return null;
|
|
1019
|
+
const c = {};
|
|
1020
|
+
for (const [h, u] of Object.entries(a.entries)) h.startsWith("page-state:") && u.data && Object.assign(c, u.data);
|
|
1021
|
+
return Object.keys(c).length > 0 ? c : null;
|
|
910
1022
|
}
|
|
911
1023
|
});
|
|
912
|
-
s.start(), t.addDynamicContext(
|
|
913
|
-
const { pageState:
|
|
1024
|
+
s.start(), t.addDynamicContext(V, () => {
|
|
1025
|
+
const { pageState: a, ...c } = s.getSnapshot({ pageState: !1 });
|
|
914
1026
|
return {
|
|
915
1027
|
name: "Friction signals",
|
|
916
1028
|
description: "Behavioral friction observed on the current page: dwell/idle times, rage clicks, route bounces, repeated field errors (names and counters only).",
|
|
917
|
-
data:
|
|
1029
|
+
data: c
|
|
918
1030
|
};
|
|
919
1031
|
});
|
|
920
|
-
const i = new
|
|
1032
|
+
const i = new Kt({
|
|
921
1033
|
frequencyCap: e.frequencyCap,
|
|
922
1034
|
storage: e.storage,
|
|
923
1035
|
storageKey: e.storageKey
|
|
924
|
-
}), n = new
|
|
925
|
-
post: (
|
|
1036
|
+
}), n = new ie({
|
|
1037
|
+
post: (a, c, h) => t.getHttp().post(a, c, h),
|
|
926
1038
|
agent: t.getConfiguredAgent()
|
|
927
|
-
}), r = new
|
|
1039
|
+
}), r = new Qt({
|
|
928
1040
|
client: t,
|
|
929
1041
|
collector: s,
|
|
930
1042
|
governor: i,
|
|
@@ -932,25 +1044,25 @@ function U(t, e) {
|
|
|
932
1044
|
options: e
|
|
933
1045
|
});
|
|
934
1046
|
r.start();
|
|
935
|
-
const
|
|
1047
|
+
const o = {
|
|
936
1048
|
optOut: () => i.optOut(),
|
|
937
1049
|
optIn: () => i.optIn(),
|
|
938
1050
|
isOptedOut: () => i.isOptedOut(),
|
|
939
|
-
setEngaged: (
|
|
940
|
-
signalFieldError: (
|
|
1051
|
+
setEngaged: (a) => i.setEngaged(a),
|
|
1052
|
+
signalFieldError: (a) => s.signalFieldError(a),
|
|
941
1053
|
getSignalsSnapshot: () => s.getSnapshot(),
|
|
942
1054
|
getActiveNudge: () => r.getActiveNudge(),
|
|
943
|
-
shown: (
|
|
944
|
-
accept: (
|
|
945
|
-
dismiss: (
|
|
946
|
-
markConverted: (
|
|
1055
|
+
shown: (a) => r.shown(a),
|
|
1056
|
+
accept: (a) => r.accept(a),
|
|
1057
|
+
dismiss: (a) => r.dismiss(a),
|
|
1058
|
+
markConverted: (a) => r.markConverted(a),
|
|
947
1059
|
destroy: () => {
|
|
948
|
-
r.stop(), n.destroy(), s.destroy(), t.removeDynamicContext(
|
|
1060
|
+
r.stop(), n.destroy(), s.destroy(), t.removeDynamicContext(V), t.proactive === o && (t.proactive = null);
|
|
949
1061
|
}
|
|
950
1062
|
};
|
|
951
|
-
return t.proactive =
|
|
1063
|
+
return t.proactive = o, o;
|
|
952
1064
|
}
|
|
953
|
-
var
|
|
1065
|
+
var ne = class {
|
|
954
1066
|
constructor() {
|
|
955
1067
|
this.entries = /* @__PURE__ */ new Map(), this.dynamicProviders = /* @__PURE__ */ new Map();
|
|
956
1068
|
}
|
|
@@ -983,48 +1095,48 @@ var Lt = class {
|
|
|
983
1095
|
clear() {
|
|
984
1096
|
this.entries.clear(), this.dynamicProviders.clear(), l.log("ClientContext cleared");
|
|
985
1097
|
}
|
|
986
|
-
},
|
|
987
|
-
function
|
|
1098
|
+
}, re = "page-state:";
|
|
1099
|
+
function ae(t) {
|
|
988
1100
|
const e = {};
|
|
989
|
-
for (const [s, i] of Object.entries(t)) s.startsWith(
|
|
1101
|
+
for (const [s, i] of Object.entries(t)) s.startsWith(re) && i.data && Object.assign(e, i.data);
|
|
990
1102
|
return e;
|
|
991
1103
|
}
|
|
992
|
-
function
|
|
1104
|
+
function oe(t) {
|
|
993
1105
|
const e = t["current-page"]?.data;
|
|
994
1106
|
return e?.page ? e.page : e?.url ? e.url : t["browser-page"]?.data?.url;
|
|
995
1107
|
}
|
|
996
|
-
function
|
|
1108
|
+
function ce(t, e) {
|
|
997
1109
|
return t === e ? !0 : JSON.stringify(t) === JSON.stringify(e);
|
|
998
1110
|
}
|
|
999
|
-
function
|
|
1111
|
+
function le(t, e) {
|
|
1000
1112
|
const s = [];
|
|
1001
1113
|
for (const i of Object.keys(e))
|
|
1002
|
-
i in t && (
|
|
1114
|
+
i in t && (ce(t[i], e[i]) || s.push({
|
|
1003
1115
|
field: i,
|
|
1004
1116
|
from: t[i],
|
|
1005
1117
|
to: e[i]
|
|
1006
1118
|
}));
|
|
1007
1119
|
return s;
|
|
1008
1120
|
}
|
|
1009
|
-
function
|
|
1010
|
-
const s =
|
|
1121
|
+
function ue(t, e) {
|
|
1122
|
+
const s = ae(e), i = oe(e);
|
|
1011
1123
|
return {
|
|
1012
|
-
changes: t && t.page === i ?
|
|
1124
|
+
changes: t && t.page === i ? le(t.state, s) : [],
|
|
1013
1125
|
baseline: {
|
|
1014
1126
|
page: i,
|
|
1015
1127
|
state: s
|
|
1016
1128
|
}
|
|
1017
1129
|
};
|
|
1018
1130
|
}
|
|
1019
|
-
function
|
|
1020
|
-
return t === null || typeof t != "object" ? JSON.stringify(t) ?? "null" : Array.isArray(t) ? `[${t.map(
|
|
1131
|
+
function O(t) {
|
|
1132
|
+
return t === null || typeof t != "object" ? JSON.stringify(t) ?? "null" : Array.isArray(t) ? `[${t.map(O).join(",")}]` : `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${O(t[e])}`).join(",")}}`;
|
|
1021
1133
|
}
|
|
1022
|
-
var
|
|
1134
|
+
var Q = "", he = class {
|
|
1023
1135
|
constructor(t, e = {}) {
|
|
1024
1136
|
this.callbacks = t, this.options = e, this.buffer = "", this.message = {}, this.toolCalls = [], this.sources = [], this.followUpReplies = [], this.isFirstChunk = !0, this.answerCompleteEmitted = !1, this.waitingClientEmitted = !1, this.firedClientFunctions = /* @__PURE__ */ new Map();
|
|
1025
1137
|
}
|
|
1026
1138
|
async processStream(t) {
|
|
1027
|
-
if (!t.body) throw new
|
|
1139
|
+
if (!t.body) throw new L("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");
|
|
1028
1140
|
const e = t.body.getReader(), s = new TextDecoder();
|
|
1029
1141
|
try {
|
|
1030
1142
|
for (; ; ) {
|
|
@@ -1037,7 +1149,7 @@ var L = "", Ht = class {
|
|
|
1037
1149
|
} catch (i) {
|
|
1038
1150
|
if (this.options.signal?.aborted)
|
|
1039
1151
|
return this.message.status = "CANCELED", this.buildFinalMessage();
|
|
1040
|
-
const n = i instanceof Error ? i : new
|
|
1152
|
+
const n = i instanceof Error ? i : new L("Stream processing failed mid-flight. The connection may have dropped; retry the message.");
|
|
1041
1153
|
throw this.callbacks.onError?.(n), n;
|
|
1042
1154
|
} finally {
|
|
1043
1155
|
e.releaseLock();
|
|
@@ -1087,9 +1199,9 @@ var L = "", Ht = class {
|
|
|
1087
1199
|
url: s.use_external_link ? s.external_link_url : s.internal_link_url
|
|
1088
1200
|
};
|
|
1089
1201
|
})), t.type === "client_function" && t.function_name) {
|
|
1090
|
-
const e = `${t.function_name}::${
|
|
1202
|
+
const e = `${t.function_name}::${O(t.arguments ?? {})}`, s = t.id || "", i = this.firedClientFunctions.get(e);
|
|
1091
1203
|
let n = !1;
|
|
1092
|
-
i ? s && !i.has(s) && (i.has(
|
|
1204
|
+
i ? s && !i.has(s) && (i.has(Q) ? (i.delete(Q), i.add(s)) : (i.add(s), n = !0)) : (this.firedClientFunctions.set(e, /* @__PURE__ */ new Set([s])), n = !0), n && this.callbacks.onClientFunction?.({
|
|
1093
1205
|
invocationId: s,
|
|
1094
1206
|
functionName: t.function_name,
|
|
1095
1207
|
arguments: t.arguments || {},
|
|
@@ -1141,11 +1253,11 @@ var L = "", Ht = class {
|
|
|
1141
1253
|
return t.status !== "WAITING_CLIENT" && this.callbacks.onComplete?.(t), t;
|
|
1142
1254
|
}
|
|
1143
1255
|
};
|
|
1144
|
-
function
|
|
1256
|
+
function be(t) {
|
|
1145
1257
|
const e = t.message.toLowerCase();
|
|
1146
1258
|
return e.includes("load failed") || e.includes("failed to fetch") || e.includes("network") || e.includes("abort");
|
|
1147
1259
|
}
|
|
1148
|
-
var
|
|
1260
|
+
var de = /* @__PURE__ */ new Set([
|
|
1149
1261
|
"image/jpeg",
|
|
1150
1262
|
"image/png",
|
|
1151
1263
|
"image/gif",
|
|
@@ -1153,7 +1265,7 @@ var Jt = /* @__PURE__ */ new Set([
|
|
|
1153
1265
|
"image/bmp",
|
|
1154
1266
|
"image/tiff"
|
|
1155
1267
|
]);
|
|
1156
|
-
function
|
|
1268
|
+
function fe(t) {
|
|
1157
1269
|
if (!t) return;
|
|
1158
1270
|
const e = typeof window < "u" && window.location ? window.location.href : "https://ago.local/";
|
|
1159
1271
|
try {
|
|
@@ -1162,16 +1274,16 @@ function zt(t) {
|
|
|
1162
1274
|
} catch {
|
|
1163
1275
|
}
|
|
1164
1276
|
}
|
|
1165
|
-
function
|
|
1166
|
-
return t.isSafeImage === !0 && typeof t.contentType == "string" && t.contentType.startsWith("image/") &&
|
|
1277
|
+
function _e(t) {
|
|
1278
|
+
return t.isSafeImage === !0 && typeof t.contentType == "string" && t.contentType.startsWith("image/") && fe(t.url) !== void 0;
|
|
1167
1279
|
}
|
|
1168
|
-
function
|
|
1280
|
+
function Re(t) {
|
|
1169
1281
|
if (t == null || t < 0) return "";
|
|
1170
1282
|
if (t < 1024) return `${t} B`;
|
|
1171
1283
|
const e = t / 1024;
|
|
1172
1284
|
return e < 1024 ? `${e.toFixed(1)} KB` : `${(e / 1024).toFixed(1)} MB`;
|
|
1173
1285
|
}
|
|
1174
|
-
function
|
|
1286
|
+
function ge(t) {
|
|
1175
1287
|
return {
|
|
1176
1288
|
id: String(t.id ?? ""),
|
|
1177
1289
|
name: typeof t.name == "string" && t.name ? t.name : "file",
|
|
@@ -1181,17 +1293,17 @@ function Xt(t) {
|
|
|
1181
1293
|
isSafeImage: t.is_safe_image === !0
|
|
1182
1294
|
};
|
|
1183
1295
|
}
|
|
1184
|
-
function
|
|
1296
|
+
function Ie(t) {
|
|
1185
1297
|
return t.map((e, s) => ({
|
|
1186
1298
|
id: `local-${s}-${e.name}`,
|
|
1187
1299
|
name: e.name,
|
|
1188
1300
|
contentType: e.type || void 0,
|
|
1189
1301
|
fileSize: e.size,
|
|
1190
1302
|
url: typeof URL < "u" && URL.createObjectURL ? URL.createObjectURL(e) : void 0,
|
|
1191
|
-
isSafeImage:
|
|
1303
|
+
isSafeImage: de.has(e.type)
|
|
1192
1304
|
}));
|
|
1193
1305
|
}
|
|
1194
|
-
var
|
|
1306
|
+
var pe = class {
|
|
1195
1307
|
constructor() {
|
|
1196
1308
|
this.handlers = /* @__PURE__ */ new Map();
|
|
1197
1309
|
}
|
|
@@ -1221,8 +1333,8 @@ var Yt = class {
|
|
|
1221
1333
|
waitFor(t, e) {
|
|
1222
1334
|
return new Promise((s, i) => {
|
|
1223
1335
|
let n;
|
|
1224
|
-
const r = ((
|
|
1225
|
-
n && clearTimeout(n), s(
|
|
1336
|
+
const r = ((o) => {
|
|
1337
|
+
n && clearTimeout(n), s(o);
|
|
1226
1338
|
});
|
|
1227
1339
|
this.once(t, r), e?.timeout && (n = setTimeout(() => {
|
|
1228
1340
|
this.off(t, r), i(/* @__PURE__ */ new Error(`waitFor("${String(t)}") timed out after ${e.timeout}ms`));
|
|
@@ -1232,20 +1344,20 @@ var Yt = class {
|
|
|
1232
1344
|
removeAllListeners(t) {
|
|
1233
1345
|
t ? this.handlers.delete(t) : this.handlers.clear();
|
|
1234
1346
|
}
|
|
1235
|
-
},
|
|
1236
|
-
function
|
|
1237
|
-
if (typeof t != "object" || t === null) throw new
|
|
1347
|
+
}, Z = '`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).', me = /^[a-z][a-z0-9+.-]*:\/\//i, tt = !1;
|
|
1348
|
+
function et(t, e = "AgoClient") {
|
|
1349
|
+
if (typeof t != "object" || t === null) throw new A(`${e}: ${Z}`, "config_missing_base_url");
|
|
1238
1350
|
const s = t.baseUrl;
|
|
1239
|
-
if (typeof s != "string" || s.trim() === "") throw new
|
|
1240
|
-
!s.startsWith("/") && !
|
|
1351
|
+
if (typeof s != "string" || s.trim() === "") throw new A(`${e}: ${Z}`, "config_missing_base_url");
|
|
1352
|
+
!s.startsWith("/") && !me.test(s) && (tt || (tt = !0, console.warn(`[AGO] ${e}: \`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).`)));
|
|
1241
1353
|
}
|
|
1242
|
-
function
|
|
1354
|
+
function ye(t) {
|
|
1243
1355
|
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1244
1356
|
}
|
|
1245
|
-
function
|
|
1357
|
+
function T(t) {
|
|
1246
1358
|
return t.split("/").filter((e) => e.startsWith(":")).map((e) => e.slice(1));
|
|
1247
1359
|
}
|
|
1248
|
-
function
|
|
1360
|
+
function ve(t, e) {
|
|
1249
1361
|
const s = [];
|
|
1250
1362
|
return {
|
|
1251
1363
|
path: t.split("/").map((i) => {
|
|
@@ -1256,52 +1368,52 @@ function Zt(t, e) {
|
|
|
1256
1368
|
missing: s
|
|
1257
1369
|
};
|
|
1258
1370
|
}
|
|
1259
|
-
function
|
|
1371
|
+
function we(t, e) {
|
|
1260
1372
|
const s = e.find((n) => n.path === t);
|
|
1261
1373
|
if (s) return s;
|
|
1262
1374
|
const i = e.find((n) => {
|
|
1263
1375
|
if (!n.path.includes(":")) return !1;
|
|
1264
|
-
const r = "^" + n.path.split("/").map((
|
|
1376
|
+
const r = "^" + n.path.split("/").map((o) => o.startsWith(":") ? "[^/]+" : ye(o)).join("/") + "/?$";
|
|
1265
1377
|
return new RegExp(r).test(t);
|
|
1266
1378
|
});
|
|
1267
1379
|
return i || e.filter((n) => n.path !== "/" && t.startsWith(n.path)).sort((n, r) => r.path.length - n.path.length)[0];
|
|
1268
1380
|
}
|
|
1269
|
-
var
|
|
1270
|
-
function
|
|
1381
|
+
var Se = "activity:recent", Ce = "state:delta";
|
|
1382
|
+
function st(t) {
|
|
1271
1383
|
return t === "setPageState" ? "readPageData" : `read${t.charAt(0).toUpperCase()}${t.slice(1)}Data`;
|
|
1272
1384
|
}
|
|
1273
|
-
var
|
|
1385
|
+
var ke = class ct {
|
|
1274
1386
|
constructor(e) {
|
|
1275
|
-
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,
|
|
1387
|
+
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, et(e, "AgoClient"), this.config = e, this.activityLedger = new ht(e.maxActivityEntries), this.httpClient = new gt(e), this.functionRegistry = new vt({ maxResultBytes: e.maxFunctionResultBytes }), this.contextRegistry = new ne(), this.eventEmitter = new pe(), this.registerActivityContext(), e.debug && l.enable(), e.proactive && Y(this, e.proactive), l.log("AgoClient initialized");
|
|
1276
1388
|
}
|
|
1277
1389
|
async sendMessage(e, s) {
|
|
1278
|
-
const i = this.functionRegistry.getSchemas(), n = this.buildSendContext(), r = this.config.agent || this.config.defaultAgentId,
|
|
1390
|
+
const i = this.functionRegistry.getSchemas(), n = this.buildSendContext(), r = this.config.agent || this.config.defaultAgentId, o = this.resolveClientFunctionsMode(s), a = {
|
|
1279
1391
|
content: e,
|
|
1280
1392
|
conversation_id: s?.conversationId,
|
|
1281
1393
|
agent_id: s?.agentId || r
|
|
1282
1394
|
};
|
|
1283
|
-
i.length > 0 && (
|
|
1284
|
-
const
|
|
1395
|
+
i.length > 0 && (a.client_functions = i, o === "pause" && (a.client_functions_mode = o)), n && (a.client_context = n), s?.hidden && (a.hidden = !0);
|
|
1396
|
+
const c = this.beginTurn();
|
|
1285
1397
|
let h;
|
|
1286
1398
|
if (s?.files && s.files.length > 0) {
|
|
1287
1399
|
const u = new FormData();
|
|
1288
|
-
u.append("content", e), s.conversationId && u.append("conversation_id", s.conversationId), (s.agentId || r) && u.append("agent_id", s.agentId || r || ""), i.length > 0 && (u.append("client_functions", JSON.stringify(i)),
|
|
1400
|
+
u.append("content", e), s.conversationId && u.append("conversation_id", s.conversationId), (s.agentId || r) && u.append("agent_id", s.agentId || r || ""), i.length > 0 && (u.append("client_functions", JSON.stringify(i)), o === "pause" && u.append("client_functions_mode", o)), n && u.append("client_context", JSON.stringify(n)), s.hidden && u.append("hidden", "true");
|
|
1289
1401
|
for (const d of s.files) u.append("files", d);
|
|
1290
|
-
h = await this.sendRequest(
|
|
1291
|
-
} else h = await this.sendRequest(
|
|
1292
|
-
return h ? this.processSSEResponse(h,
|
|
1402
|
+
h = await this.sendRequest(c, () => this.httpClient.postFormData("/api/sdk/v1/messages", u, { signal: c.controller.signal }));
|
|
1403
|
+
} else h = await this.sendRequest(c, () => this.httpClient.postStream("/api/sdk/v1/messages", a, { signal: c.controller.signal }));
|
|
1404
|
+
return h ? this.processSSEResponse(h, c) : this.buildStoppedMessage(c);
|
|
1293
1405
|
}
|
|
1294
1406
|
async sendRequest(e, s) {
|
|
1295
1407
|
try {
|
|
1296
1408
|
return await s();
|
|
1297
1409
|
} catch (i) {
|
|
1298
|
-
if (this.endTurn(e),
|
|
1410
|
+
if (this.endTurn(e), F(i)) return null;
|
|
1299
1411
|
throw i;
|
|
1300
1412
|
}
|
|
1301
1413
|
}
|
|
1302
1414
|
async processSSEResponse(e, s) {
|
|
1303
1415
|
let i = !1;
|
|
1304
|
-
const n = new
|
|
1416
|
+
const n = new he({
|
|
1305
1417
|
onRawChunk: (r) => {
|
|
1306
1418
|
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);
|
|
1307
1419
|
},
|
|
@@ -1339,7 +1451,7 @@ var ce = class H {
|
|
|
1339
1451
|
onError: (r) => {
|
|
1340
1452
|
this.eventEmitter.emit("message:error", {
|
|
1341
1453
|
error: r.message,
|
|
1342
|
-
code: r instanceof
|
|
1454
|
+
code: r instanceof A ? r.code : void 0
|
|
1343
1455
|
});
|
|
1344
1456
|
}
|
|
1345
1457
|
}, { signal: s?.controller.signal });
|
|
@@ -1434,8 +1546,8 @@ var ce = class H {
|
|
|
1434
1546
|
s.length > 0 && (n.client_functions = s), i && (n.client_context = i);
|
|
1435
1547
|
const r = this.beginTurn();
|
|
1436
1548
|
r.messageId = e;
|
|
1437
|
-
const
|
|
1438
|
-
return
|
|
1549
|
+
const o = await this.sendRequest(r, () => this.httpClient.postStream(`/api/sdk/v1/messages/${e}/continue`, n, { signal: r.controller.signal }));
|
|
1550
|
+
return o ? this.processSSEResponse(o, r) : this.buildStoppedMessage(r);
|
|
1439
1551
|
}
|
|
1440
1552
|
markResumeSignal(e, s, i) {
|
|
1441
1553
|
if (!e) return;
|
|
@@ -1537,10 +1649,10 @@ var ce = class H {
|
|
|
1537
1649
|
async getConversations(e) {
|
|
1538
1650
|
const s = new URLSearchParams();
|
|
1539
1651
|
e?.page !== void 0 && s.set("page", String(e.page)), e?.pageSize !== void 0 && s.set("page_size", String(e.pageSize));
|
|
1540
|
-
const i = s.toString(), n = await this.httpClient.get(`/api/sdk/v1/conversations${i ? `?${i}` : ""}`), r = (Array.isArray(n.data) ? n.data : []).map((
|
|
1541
|
-
id: String(
|
|
1542
|
-
title:
|
|
1543
|
-
lastMessageDate: new Date(
|
|
1652
|
+
const i = s.toString(), n = await this.httpClient.get(`/api/sdk/v1/conversations${i ? `?${i}` : ""}`), r = (Array.isArray(n.data) ? n.data : []).map((o) => ({
|
|
1653
|
+
id: String(o.id),
|
|
1654
|
+
title: o.title ?? "",
|
|
1655
|
+
lastMessageDate: new Date(o.last_message_at ?? o.created_at ?? 0)
|
|
1544
1656
|
}));
|
|
1545
1657
|
return {
|
|
1546
1658
|
data: r,
|
|
@@ -1561,8 +1673,8 @@ var ce = class H {
|
|
|
1561
1673
|
status: n.status,
|
|
1562
1674
|
createdAt: new Date(n.created_at),
|
|
1563
1675
|
hidden: n.hidden,
|
|
1564
|
-
toolCalls:
|
|
1565
|
-
attachments: n.attachments && n.attachments.length > 0 ? n.attachments.map(
|
|
1676
|
+
toolCalls: ct.mapPersistedToolCalls(n.tool_call_data),
|
|
1677
|
+
attachments: n.attachments && n.attachments.length > 0 ? n.attachments.map(ge) : void 0,
|
|
1566
1678
|
followUpReplies: n.follow_up_replies && n.follow_up_replies.length > 0 ? n.follow_up_replies : void 0
|
|
1567
1679
|
}))
|
|
1568
1680
|
};
|
|
@@ -1587,41 +1699,41 @@ var ce = class H {
|
|
|
1587
1699
|
return (await this.getConversation(e)).messages || [];
|
|
1588
1700
|
}
|
|
1589
1701
|
async resumePendingClientFunctions(e) {
|
|
1590
|
-
const s = [...e.messages ?? []].reverse().find((
|
|
1702
|
+
const s = [...e.messages ?? []].reverse().find((a) => a.role === "assistant" && a.status === "WAITING_CLIENT");
|
|
1591
1703
|
if (!s) return null;
|
|
1592
|
-
const i = (s.toolCalls ?? []).filter((
|
|
1704
|
+
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));
|
|
1593
1705
|
if (r.length > 0)
|
|
1594
|
-
return l.warn("Cannot resume paused turn: function(s) not registered on this page:", r.map((
|
|
1595
|
-
let
|
|
1596
|
-
for (const
|
|
1597
|
-
const
|
|
1598
|
-
invocationId:
|
|
1599
|
-
functionName:
|
|
1600
|
-
arguments:
|
|
1706
|
+
return l.warn("Cannot resume paused turn: function(s) not registered on this page:", r.map((a) => a.functionName)), null;
|
|
1707
|
+
let o = i.length === 0;
|
|
1708
|
+
for (const a of i) {
|
|
1709
|
+
const c = {
|
|
1710
|
+
invocationId: a.id,
|
|
1711
|
+
functionName: a.functionName,
|
|
1712
|
+
arguments: a.arguments ?? {},
|
|
1601
1713
|
conversationId: e.id
|
|
1602
1714
|
};
|
|
1603
|
-
if (this.requiresApproval(
|
|
1604
|
-
this.pendingApprovals.set(
|
|
1715
|
+
if (this.requiresApproval(c)) {
|
|
1716
|
+
this.pendingApprovals.set(a.id, c), this.markResumeSignal(s.id, e.id, "waitingConfirmed"), this.eventEmitter.emit("function:awaiting-approval", c), o = !1;
|
|
1605
1717
|
continue;
|
|
1606
1718
|
}
|
|
1607
|
-
this.eventEmitter.emit("function:invoke",
|
|
1719
|
+
this.eventEmitter.emit("function:invoke", c);
|
|
1608
1720
|
let h, u;
|
|
1609
1721
|
try {
|
|
1610
|
-
h = await this.functionRegistry.execute(
|
|
1722
|
+
h = await this.functionRegistry.execute(a.functionName, a.arguments ?? {});
|
|
1611
1723
|
} catch (d) {
|
|
1612
1724
|
u = d instanceof Error ? d.message : "Unknown error", l.error("Client function execution failed:", d);
|
|
1613
1725
|
}
|
|
1614
1726
|
this.eventEmitter.emit("function:result", {
|
|
1615
|
-
invocationId:
|
|
1727
|
+
invocationId: a.id,
|
|
1616
1728
|
result: h,
|
|
1617
1729
|
error: u
|
|
1618
|
-
}),
|
|
1730
|
+
}), o = (await this.submitToolCallForm(a.id, {
|
|
1619
1731
|
result: h,
|
|
1620
1732
|
error: u,
|
|
1621
1733
|
_type: "client_function_result"
|
|
1622
|
-
}))?.resume?.ready ??
|
|
1734
|
+
}))?.resume?.ready ?? o;
|
|
1623
1735
|
}
|
|
1624
|
-
return
|
|
1736
|
+
return o ? this.continueMessage(s.id) : null;
|
|
1625
1737
|
}
|
|
1626
1738
|
async submitToolCallForm(e, s) {
|
|
1627
1739
|
return this.httpClient.post(`/api/sdk/v1/tool-calls/${e}/submit`, { formData: s });
|
|
@@ -1647,8 +1759,22 @@ var ce = class H {
|
|
|
1647
1759
|
values: s
|
|
1648
1760
|
});
|
|
1649
1761
|
}
|
|
1650
|
-
async submitFeedback(e, s) {
|
|
1651
|
-
|
|
1762
|
+
async submitFeedback(e, s, i) {
|
|
1763
|
+
const n = i?.comment?.trim(), r = i?.reasons?.length ? [...new Set(i.reasons)] : [];
|
|
1764
|
+
await this.httpClient.post(`/api/sdk/v1/messages/${e}/feedback`, {
|
|
1765
|
+
rating: s,
|
|
1766
|
+
...r.length ? { reasons: r } : {},
|
|
1767
|
+
...n ? { comment: n } : {}
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
async submitConversationFeedback(e, s, i) {
|
|
1771
|
+
let n = i?.lastMessageId;
|
|
1772
|
+
if (!n) {
|
|
1773
|
+
const r = [...(await this.getConversation(e)).messages ?? []].reverse().find((o) => o.role === "assistant" && !o.hidden && !!o.content && o.status !== "IN_PROGRESS" && o.status !== "WAITING_CLIENT");
|
|
1774
|
+
if (!r) throw new A(`Conversation ${e} has no finished answer to report feedback on. Wait for the turn to complete, or pass \`lastMessageId\`.`, "feedback_no_message");
|
|
1775
|
+
n = r.id;
|
|
1776
|
+
}
|
|
1777
|
+
return await this.submitFeedback(n, s, i), n;
|
|
1652
1778
|
}
|
|
1653
1779
|
registerFunction(e, s, i) {
|
|
1654
1780
|
typeof e == "object" ? this.functionRegistry.register(e) : this.functionRegistry.register(e, s, i);
|
|
@@ -1667,65 +1793,65 @@ var ce = class H {
|
|
|
1667
1793
|
return this.functionRegistry.execute(e, s);
|
|
1668
1794
|
}
|
|
1669
1795
|
registerNavigationFunction(e, s) {
|
|
1670
|
-
const i = s.map((
|
|
1671
|
-
const
|
|
1672
|
-
return `- "${
|
|
1796
|
+
const i = s.map((a) => a.name), n = s.map((a) => {
|
|
1797
|
+
const c = T(a.path), h = c.length > 0 ? ` (requires ${c.map((u) => `"${u}"`).join(", ")})` : "";
|
|
1798
|
+
return `- "${a.name}"${h}: ${a.description}`;
|
|
1673
1799
|
}).join(`
|
|
1674
1800
|
`), r = /* @__PURE__ */ new Map();
|
|
1675
|
-
for (const
|
|
1676
|
-
const
|
|
1801
|
+
for (const a of s) for (const c of T(a.path)) r.set(c, [...r.get(c) ?? [], a.name]);
|
|
1802
|
+
const o = { page: {
|
|
1677
1803
|
type: "string",
|
|
1678
1804
|
description: "The page to navigate to",
|
|
1679
1805
|
enum: i
|
|
1680
1806
|
} };
|
|
1681
|
-
for (const [
|
|
1682
|
-
if (
|
|
1807
|
+
for (const [a, c] of r) {
|
|
1808
|
+
if (a === "page") {
|
|
1683
1809
|
l.error('registerNavigationFunction: a ":page" placeholder collides with the "page" argument and is ignored. Rename the placeholder.');
|
|
1684
1810
|
continue;
|
|
1685
1811
|
}
|
|
1686
|
-
|
|
1812
|
+
o[a] = {
|
|
1687
1813
|
type: "string",
|
|
1688
|
-
description: `Value for ":${
|
|
1814
|
+
description: `Value for ":${a}" in the page path. Required when page is ${c.map((h) => `"${h}"`).join(" or ")}.`
|
|
1689
1815
|
};
|
|
1690
1816
|
}
|
|
1691
|
-
this.registerFunction("navigateToPage", async (
|
|
1692
|
-
const
|
|
1817
|
+
this.registerFunction("navigateToPage", async (a) => {
|
|
1818
|
+
const c = a.page, h = s.find((g) => g.name === c);
|
|
1693
1819
|
if (!h) return {
|
|
1694
1820
|
success: !1,
|
|
1695
|
-
error: `Unknown page: ${
|
|
1821
|
+
error: `Unknown page: ${c}`
|
|
1696
1822
|
};
|
|
1697
1823
|
let u = {};
|
|
1698
|
-
if (typeof
|
|
1699
|
-
u = JSON.parse(
|
|
1824
|
+
if (typeof a.params == "string") try {
|
|
1825
|
+
u = JSON.parse(a.params);
|
|
1700
1826
|
} catch {
|
|
1701
1827
|
}
|
|
1702
|
-
else
|
|
1828
|
+
else a.params && typeof a.params == "object" && (u = a.params);
|
|
1703
1829
|
const d = {};
|
|
1704
|
-
for (const
|
|
1705
|
-
const { path:
|
|
1706
|
-
if (
|
|
1707
|
-
const
|
|
1830
|
+
for (const g of T(h.path)) d[g] = a[g] ?? u[g];
|
|
1831
|
+
const { path: m, missing: S } = ve(h.path, d);
|
|
1832
|
+
if (S.length > 0) {
|
|
1833
|
+
const g = S.map((f) => `"${f}": "..."`).join(", ");
|
|
1708
1834
|
return {
|
|
1709
1835
|
success: !1,
|
|
1710
|
-
error: `Page "${
|
|
1836
|
+
error: `Page "${c}" needs ${S.map((f) => `"${f}"`).join(", ")}. Retry with { "page": "${c}", ${g} }.`
|
|
1711
1837
|
};
|
|
1712
1838
|
}
|
|
1713
|
-
return e(
|
|
1839
|
+
return e(m), {
|
|
1714
1840
|
success: !0,
|
|
1715
|
-
navigatedTo:
|
|
1841
|
+
navigatedTo: m
|
|
1716
1842
|
};
|
|
1717
1843
|
}, {
|
|
1718
1844
|
description: `Navigate the user to a page in the application. Available pages:
|
|
1719
1845
|
${n}`,
|
|
1720
1846
|
parameters: {
|
|
1721
1847
|
type: "object",
|
|
1722
|
-
properties:
|
|
1848
|
+
properties: o,
|
|
1723
1849
|
required: ["page"]
|
|
1724
1850
|
}
|
|
1725
1851
|
}), this.addDynamicContext("current-page", () => {
|
|
1726
1852
|
if (typeof window > "u" || !window.location) return null;
|
|
1727
|
-
const
|
|
1728
|
-
return h && (u.page = h.name),
|
|
1853
|
+
const a = window.location.href, c = typeof document < "u" ? document.title : void 0, h = we(window.location.pathname, s), u = { url: a };
|
|
1854
|
+
return h && (u.page = h.name), c && (u.title = c), {
|
|
1729
1855
|
name: "Current page",
|
|
1730
1856
|
description: "The page the user is currently viewing.",
|
|
1731
1857
|
data: u
|
|
@@ -1736,78 +1862,54 @@ ${n}`,
|
|
|
1736
1862
|
this.unregisterFunction("navigateToPage"), this.removeDynamicContext("current-page");
|
|
1737
1863
|
}
|
|
1738
1864
|
registerPageStateFunction(e, s) {
|
|
1739
|
-
const i = s?.functionName ?? "setPageState", n =
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
const h = {};
|
|
1743
|
-
for (const [u, d] of Object.entries(a)) {
|
|
1744
|
-
if (d === void 0) continue;
|
|
1745
|
-
const f = n.get(u);
|
|
1746
|
-
f && (await f.set(d), h[u] = d);
|
|
1747
|
-
}
|
|
1748
|
-
return r ? {
|
|
1749
|
-
success: !0,
|
|
1750
|
-
applied: h,
|
|
1751
|
-
data: N(i, await this.readPageData(i, r, s), this.pageDataBudget(r) - this.envelopeBytes({
|
|
1752
|
-
success: !0,
|
|
1753
|
-
applied: h
|
|
1754
|
-
}))
|
|
1755
|
-
} : {
|
|
1756
|
-
success: !0,
|
|
1757
|
-
applied: h
|
|
1758
|
-
};
|
|
1759
|
-
}, {
|
|
1760
|
-
description: `Change the state of the current page. Set ONLY the controls the user explicitly asked for; leave the others unset. Available controls:
|
|
1761
|
-
${c}` + (r ? `
|
|
1762
|
-
Returns the resulting page data once it has loaded: ${r.description}` : ""),
|
|
1763
|
-
parameters: {
|
|
1764
|
-
type: "object",
|
|
1765
|
-
properties: Object.fromEntries(e.map((a) => [a.name, {
|
|
1766
|
-
...a.schema,
|
|
1767
|
-
description: a.description
|
|
1768
|
-
}])),
|
|
1769
|
-
required: []
|
|
1770
|
-
},
|
|
1865
|
+
const i = s?.functionName ?? "setPageState", n = s?.data;
|
|
1866
|
+
this.registerFunction($t(e, {
|
|
1867
|
+
name: i,
|
|
1771
1868
|
requiresApproval: s?.requiresApproval,
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1869
|
+
getResultBudget: () => n ? this.pageDataBudget(n) : this.functionRegistry.getDefaultMaxResultBytes(),
|
|
1870
|
+
data: n ? {
|
|
1871
|
+
description: n.description,
|
|
1872
|
+
maxResultBytes: n.maxResultBytes,
|
|
1873
|
+
read: async (o) => W(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes(o))
|
|
1874
|
+
} : void 0
|
|
1875
|
+
}));
|
|
1876
|
+
const r = st(i);
|
|
1877
|
+
n ? (this.warnIfPlaceholderMode(i), this.registerFunction(r, async () => ({ data: W(i, await this.readPageData(i, n, s), this.pageDataBudget(n) - this.envelopeBytes({})) }), {
|
|
1878
|
+
description: `Read what the current page is displaying, without changing anything: ${n.description}`,
|
|
1777
1879
|
parameters: {
|
|
1778
1880
|
type: "object",
|
|
1779
1881
|
properties: {}
|
|
1780
1882
|
},
|
|
1781
|
-
maxResultBytes:
|
|
1782
|
-
}), this.pageDataCompanions.add(
|
|
1783
|
-
const
|
|
1784
|
-
if (
|
|
1785
|
-
const
|
|
1786
|
-
for (const
|
|
1883
|
+
maxResultBytes: n.maxResultBytes
|
|
1884
|
+
}), this.pageDataCompanions.add(r)) : this.pageDataCompanions.delete(r) && this.unregisterFunction(r), this.addDynamicContext(`page-state:${i}`, () => {
|
|
1885
|
+
const o = e.filter((c) => typeof c.get == "function");
|
|
1886
|
+
if (o.length === 0) return null;
|
|
1887
|
+
const a = {};
|
|
1888
|
+
for (const c of o) a[c.name] = c.get();
|
|
1787
1889
|
return {
|
|
1788
1890
|
name: "Page state",
|
|
1789
1891
|
description: "Current, editable state of the page the user is viewing.",
|
|
1790
|
-
data:
|
|
1892
|
+
data: a
|
|
1791
1893
|
};
|
|
1792
1894
|
});
|
|
1793
1895
|
}
|
|
1794
1896
|
unregisterPageStateFunction(e) {
|
|
1795
1897
|
const s = e ?? "setPageState";
|
|
1796
1898
|
this.unregisterFunction(s);
|
|
1797
|
-
const i =
|
|
1899
|
+
const i = st(s);
|
|
1798
1900
|
this.pageDataCompanions.delete(i) && this.unregisterFunction(i), this.removeDynamicContext(`page-state:${s}`);
|
|
1799
1901
|
}
|
|
1800
1902
|
pageDataBudget(e) {
|
|
1801
1903
|
return e.maxResultBytes ?? this.functionRegistry.getDefaultMaxResultBytes();
|
|
1802
1904
|
}
|
|
1803
1905
|
envelopeBytes(e) {
|
|
1804
|
-
return
|
|
1906
|
+
return p(JSON.stringify({
|
|
1805
1907
|
...e,
|
|
1806
1908
|
data: null
|
|
1807
1909
|
})) - 4;
|
|
1808
1910
|
}
|
|
1809
1911
|
readPageData(e, s, i) {
|
|
1810
|
-
return
|
|
1912
|
+
return bt(() => s, i?.settleTimeoutMs ?? 1e4).catch((n) => (l.warn(`Reading page data for "${e}" failed:`, n), {
|
|
1811
1913
|
error: "page_data_unavailable",
|
|
1812
1914
|
message: n instanceof Error ? n.message : String(n)
|
|
1813
1915
|
}));
|
|
@@ -1861,10 +1963,10 @@ Returns the resulting page data once it has loaded: ${r.description}` : ""),
|
|
|
1861
1963
|
return this.contextRegistry.getSnapshot();
|
|
1862
1964
|
}
|
|
1863
1965
|
buildSendContext() {
|
|
1864
|
-
const e = this.contextRegistry.getSnapshot(), s = e?.entries ?? {}, { changes: i, baseline: n } =
|
|
1966
|
+
const e = this.contextRegistry.getSnapshot(), s = e?.entries ?? {}, { changes: i, baseline: n } = ue(this.lastSentPageState, s);
|
|
1865
1967
|
return this.lastSentPageState = n, i.length === 0 ? e : { entries: {
|
|
1866
1968
|
...s,
|
|
1867
|
-
[
|
|
1969
|
+
[Ce]: {
|
|
1868
1970
|
name: "State changes",
|
|
1869
1971
|
description: "Fields in the page state that changed since your last message, as field: <old> -> <new>.",
|
|
1870
1972
|
data: { changes: i }
|
|
@@ -1888,8 +1990,8 @@ Returns the resulting page data once it has loaded: ${r.description}` : ""),
|
|
|
1888
1990
|
const s = e.functionName, i = e.arguments;
|
|
1889
1991
|
let n, r;
|
|
1890
1992
|
if (s === "navigateToPage") {
|
|
1891
|
-
const
|
|
1892
|
-
n = "agent.navigate", r =
|
|
1993
|
+
const o = i?.page;
|
|
1994
|
+
n = "agent.navigate", r = o ? `Agent navigated to "${String(o)}"` : "Agent navigated";
|
|
1893
1995
|
} else s === "setPageState" ? (n = "agent.page_state", r = "Agent changed the page state") : (n = `agent.${s}`, r = `Agent ran "${s}"`);
|
|
1894
1996
|
this.addActivity({
|
|
1895
1997
|
actor: "agent",
|
|
@@ -1899,7 +2001,7 @@ Returns the resulting page data once it has loaded: ${r.description}` : ""),
|
|
|
1899
2001
|
});
|
|
1900
2002
|
}
|
|
1901
2003
|
registerActivityContext() {
|
|
1902
|
-
this.contextRegistry.addDynamicProvider(
|
|
2004
|
+
this.contextRegistry.addDynamicProvider(Se, () => {
|
|
1903
2005
|
const e = this.activityLedger.getRecent();
|
|
1904
2006
|
return e.length === 0 ? null : {
|
|
1905
2007
|
name: "Recent activity",
|
|
@@ -1927,39 +2029,40 @@ Returns the resulting page data once it has loaded: ${r.description}` : ""),
|
|
|
1927
2029
|
...this.config,
|
|
1928
2030
|
...s
|
|
1929
2031
|
};
|
|
1930
|
-
|
|
2032
|
+
et(i, "AgoClient.updateConfig"), this.config = i, this.httpClient.updateConfig(s), s.debug !== void 0 && (s.debug ? l.enable() : l.disable()), s.maxFunctionResultBytes !== void 0 && this.functionRegistry.setDefaultMaxResultBytes(s.maxFunctionResultBytes);
|
|
1931
2033
|
}
|
|
1932
2034
|
destroy() {
|
|
1933
2035
|
this.proactive?.destroy(), this.proactive = 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, l.log("AgoClient destroyed");
|
|
1934
2036
|
}
|
|
1935
2037
|
reviveAfterDestroy() {
|
|
1936
|
-
this.registerActivityContext(), this.config.proactive && !this.proactive &&
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
2038
|
+
this.registerActivityContext(), this.config.proactive && !this.proactive && Y(this, this.config.proactive);
|
|
2039
|
+
}
|
|
2040
|
+
}, Te = [
|
|
2041
|
+
"inaccurate",
|
|
2042
|
+
"incomplete",
|
|
2043
|
+
"information_not_found",
|
|
2044
|
+
"technical_issue"
|
|
2045
|
+
];
|
|
1939
2046
|
export {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
l as v,
|
|
1962
|
-
X as w,
|
|
1963
|
-
D as x,
|
|
1964
|
-
y
|
|
2047
|
+
jt as _,
|
|
2048
|
+
Ie as a,
|
|
2049
|
+
ht as b,
|
|
2050
|
+
fe as c,
|
|
2051
|
+
ne as d,
|
|
2052
|
+
Y as f,
|
|
2053
|
+
Bt as g,
|
|
2054
|
+
ot as h,
|
|
2055
|
+
pe as i,
|
|
2056
|
+
he as l,
|
|
2057
|
+
zt as m,
|
|
2058
|
+
ke as n,
|
|
2059
|
+
_e as o,
|
|
2060
|
+
Ht as p,
|
|
2061
|
+
et as r,
|
|
2062
|
+
Re as s,
|
|
2063
|
+
Te as t,
|
|
2064
|
+
be as u,
|
|
2065
|
+
vt as v,
|
|
2066
|
+
Ee as x,
|
|
2067
|
+
l as y
|
|
1965
2068
|
};
|