@useago/sdk 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +14 -4
- package/dist/angular.d.ts +14 -4
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-Ri3EKIJU.cjs → createConversationSession-Digvn0GQ.cjs} +1 -1
- package/dist/{createConversationSession-D0vks-8C.js → createConversationSession-DrmOaZdO.js} +1 -1
- package/dist/{createFormCollector-BMN-blXs.js → createFormCollector-D6_N8wYq.js} +49 -47
- package/dist/createFormCollector-D_5SDuk9.cjs +1 -0
- package/dist/devtools.d.cts +14 -4
- package/dist/devtools.d.ts +14 -4
- package/dist/helpers.d.cts +9 -4
- package/dist/helpers.d.ts +9 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +39 -35
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +14 -4
- package/dist/react.d.ts +14 -4
- package/dist/react.js +2 -2
- package/dist/testing.d.cts +14 -4
- package/dist/testing.d.ts +14 -4
- package/dist/{types-fX-VoHfa.js → types-D1ZrqVhr.js} +139 -138
- package/dist/{types-Ck3iZG0K.cjs → types-DNr6XEwI.cjs} +5 -5
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +14 -4
- package/dist/vue.d.ts +14 -4
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +6 -6
- package/dist/widget.d.cts +19 -4
- package/dist/widget.d.ts +19 -4
- package/dist/widget.js +886 -886
- package/llms-full.txt +40 -5
- package/package.json +1 -1
- package/dist/createFormCollector-BNCMIUw2.cjs +0 -1
|
@@ -398,13 +398,13 @@ var Pe = 5e4, Ne = 2e4, Oe = 2e3, Le = class {
|
|
|
398
398
|
}
|
|
399
399
|
register(e, t, s) {
|
|
400
400
|
if (typeof e == "object") {
|
|
401
|
-
const { name:
|
|
402
|
-
return this.register(
|
|
403
|
-
description:
|
|
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
404
|
parameters: v,
|
|
405
|
-
maxResultBytes:
|
|
405
|
+
maxResultBytes: y,
|
|
406
406
|
requiresApproval: h,
|
|
407
|
-
webmcp:
|
|
407
|
+
webmcp: p
|
|
408
408
|
});
|
|
409
409
|
}
|
|
410
410
|
const i = e;
|
|
@@ -421,8 +421,8 @@ var Pe = 5e4, Ne = 2e4, Oe = 2e3, Le = class {
|
|
|
421
421
|
requiresApproval: r,
|
|
422
422
|
webmcp: o
|
|
423
423
|
});
|
|
424
|
-
const
|
|
425
|
-
|
|
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();
|
|
426
426
|
}
|
|
427
427
|
unregister(e) {
|
|
428
428
|
const t = this.functions.delete(e);
|
|
@@ -479,11 +479,11 @@ var Pe = 5e4, Ne = 2e4, Oe = 2e3, Le = class {
|
|
|
479
479
|
return this.functions.size;
|
|
480
480
|
}
|
|
481
481
|
}, je = new TextEncoder();
|
|
482
|
-
function
|
|
482
|
+
function b(e) {
|
|
483
483
|
return je.encode(e).length;
|
|
484
484
|
}
|
|
485
485
|
function j(e) {
|
|
486
|
-
return
|
|
486
|
+
return b(JSON.stringify(e)) - 2;
|
|
487
487
|
}
|
|
488
488
|
function ye(e, t) {
|
|
489
489
|
if (t <= 0) return "";
|
|
@@ -546,7 +546,7 @@ function Ke(e) {
|
|
|
546
546
|
function Je(e, t) {
|
|
547
547
|
let s = 2, i = 0;
|
|
548
548
|
for (const n of e) {
|
|
549
|
-
const r =
|
|
549
|
+
const r = b(A(n) ?? "null") + (i > 0 ? 1 : 0);
|
|
550
550
|
if (s + r > t) break;
|
|
551
551
|
s += r, i++;
|
|
552
552
|
}
|
|
@@ -562,14 +562,14 @@ function He(e, t, s, i) {
|
|
|
562
562
|
maxBytes: i,
|
|
563
563
|
preview: "",
|
|
564
564
|
hint: W(e)
|
|
565
|
-
}, r =
|
|
565
|
+
}, r = b(A(n) ?? "{}");
|
|
566
566
|
return {
|
|
567
567
|
...n,
|
|
568
568
|
preview: ye(t, Math.min(Be, i - r))
|
|
569
569
|
};
|
|
570
570
|
}
|
|
571
571
|
function ze(e, t, s, i, n) {
|
|
572
|
-
const r = s === void 0 ? {} : { ...t }, o = s ?? "items", a =
|
|
572
|
+
const r = s === void 0 ? {} : { ...t }, o = s ?? "items", a = b(A({
|
|
573
573
|
...r,
|
|
574
574
|
[o]: [],
|
|
575
575
|
truncation: {
|
|
@@ -595,12 +595,12 @@ function ze(e, t, s, i, n) {
|
|
|
595
595
|
function te(e, t, s) {
|
|
596
596
|
const i = A(t);
|
|
597
597
|
if (i === void 0) return t;
|
|
598
|
-
const n =
|
|
598
|
+
const n = b(i);
|
|
599
599
|
if (n <= s) return t;
|
|
600
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
601
|
const r = Ke(t), o = Array.isArray(t) ? t : r !== void 0 ? t[r] : void 0;
|
|
602
602
|
if (o) {
|
|
603
|
-
const a = ze(e, t, r, o, s), l =
|
|
603
|
+
const a = ze(e, t, r, o, s), l = b(A(a) ?? "");
|
|
604
604
|
if (a !== void 0 && l <= s) return a;
|
|
605
605
|
}
|
|
606
606
|
return He(e, i, n, s);
|
|
@@ -643,63 +643,63 @@ function Qe(e) {
|
|
|
643
643
|
function Ze(e, t, s) {
|
|
644
644
|
const i = s?.catalogue === "onDemand", n = ve(t);
|
|
645
645
|
!i && n.length > 0 && c.log('registerNavigationFunction: routes declare "section" but catalogue is "inline", so it is unused. Set catalogue: "onDemand" to use it.');
|
|
646
|
-
const r = i ? `Navigate the user to a page. Call ${T} for what a page name means
|
|
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
647
|
${t.map(Qe).join(`
|
|
648
|
-
`)}`,
|
|
649
|
-
for (const u of t) for (const
|
|
650
|
-
const
|
|
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
651
|
type: "string",
|
|
652
652
|
description: "The page to navigate to",
|
|
653
|
-
enum:
|
|
653
|
+
enum: l
|
|
654
654
|
} };
|
|
655
|
-
for (const [u,
|
|
655
|
+
for (const [u, g] of a) {
|
|
656
656
|
if (u === "page") {
|
|
657
657
|
c.error('registerNavigationFunction: a ":page" placeholder collides with the "page" argument and is ignored. Rename the placeholder.');
|
|
658
658
|
continue;
|
|
659
659
|
}
|
|
660
|
-
|
|
660
|
+
d[u] = {
|
|
661
661
|
type: "string",
|
|
662
|
-
description: `Value for ":${u}" in the page path. Required when page is ${
|
|
662
|
+
description: `Value for ":${u}" in the page path. Required when page is ${g.map((f) => `"${f}"`).join(" or ")}.`
|
|
663
663
|
};
|
|
664
664
|
}
|
|
665
665
|
return {
|
|
666
666
|
name: J,
|
|
667
|
-
description:
|
|
667
|
+
description: o,
|
|
668
668
|
parameters: {
|
|
669
669
|
type: "object",
|
|
670
|
-
properties:
|
|
670
|
+
properties: d,
|
|
671
671
|
required: ["page"]
|
|
672
672
|
},
|
|
673
673
|
webmcp: { navigates: !0 },
|
|
674
674
|
handler: async (u) => {
|
|
675
|
-
const
|
|
675
|
+
const g = u.page, f = t.find((m) => m.name === g);
|
|
676
676
|
if (!f) return i ? {
|
|
677
677
|
success: !1,
|
|
678
|
-
error: `Unknown page: ${
|
|
679
|
-
pages:
|
|
678
|
+
error: `Unknown page: ${g}`,
|
|
679
|
+
pages: l
|
|
680
680
|
} : {
|
|
681
681
|
success: !1,
|
|
682
|
-
error: `Unknown page: ${
|
|
682
|
+
error: `Unknown page: ${g}`
|
|
683
683
|
};
|
|
684
|
-
let
|
|
684
|
+
let v = {};
|
|
685
685
|
if (typeof u.params == "string") try {
|
|
686
|
-
|
|
686
|
+
v = JSON.parse(u.params);
|
|
687
687
|
} catch {
|
|
688
688
|
}
|
|
689
|
-
else u.params && typeof u.params == "object" && (
|
|
690
|
-
const
|
|
691
|
-
for (const
|
|
692
|
-
const { path:
|
|
693
|
-
if (
|
|
694
|
-
const
|
|
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
695
|
return {
|
|
696
696
|
success: !1,
|
|
697
|
-
error: `Page "${
|
|
697
|
+
error: `Page "${g}" needs ${p.map((w) => `"${w}"`).join(", ")}. Retry with { "page": "${g}", ${m} }.`
|
|
698
698
|
};
|
|
699
699
|
}
|
|
700
|
-
return e(
|
|
700
|
+
return e(h), {
|
|
701
701
|
success: !0,
|
|
702
|
-
navigatedTo:
|
|
702
|
+
navigatedTo: h
|
|
703
703
|
};
|
|
704
704
|
}
|
|
705
705
|
};
|
|
@@ -741,9 +741,9 @@ function I(e, t) {
|
|
|
741
741
|
const s = Object.keys(e), i = Object.keys(t);
|
|
742
742
|
return s.length !== i.length ? !1 : s.every((n) => n in t && I(e[n], t[n]));
|
|
743
743
|
}
|
|
744
|
-
var se = 100, $ = " … [truncated]", we = { truncated: !0 }, tt =
|
|
744
|
+
var se = 100, $ = " … [truncated]", we = { truncated: !0 }, tt = b(',"data":' + JSON.stringify(we));
|
|
745
745
|
function G(e) {
|
|
746
|
-
return
|
|
746
|
+
return b(JSON.stringify(e));
|
|
747
747
|
}
|
|
748
748
|
function ie(e, t) {
|
|
749
749
|
if (G(e) <= t || !e.rejected) return e;
|
|
@@ -755,12 +755,12 @@ function ie(e, t) {
|
|
|
755
755
|
if (r > t) return n;
|
|
756
756
|
const o = j($);
|
|
757
757
|
for (const [a, l] of s) {
|
|
758
|
-
const
|
|
759
|
-
if (
|
|
760
|
-
i[a] = l, r +=
|
|
758
|
+
const d = j(l), u = t - r + o;
|
|
759
|
+
if (d <= u) {
|
|
760
|
+
i[a] = l, r += d - o;
|
|
761
761
|
continue;
|
|
762
762
|
}
|
|
763
|
-
i[a] = ye(l,
|
|
763
|
+
i[a] = ye(l, u - o) + $;
|
|
764
764
|
break;
|
|
765
765
|
}
|
|
766
766
|
return n;
|
|
@@ -776,7 +776,7 @@ function Ee(e) {
|
|
|
776
776
|
return s > 0 ? `${t.join(", ")} (${s} more not shown)` : t.join(", ");
|
|
777
777
|
}
|
|
778
778
|
function re(e, t) {
|
|
779
|
-
return t.includes(e) ? null : `${JSON.stringify(e)} is not an allowed value. Allowed values: ${Ee(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)}.`;
|
|
780
780
|
}
|
|
781
781
|
function st(e, t) {
|
|
782
782
|
const { schema: s } = t;
|
|
@@ -813,11 +813,12 @@ function be(e) {
|
|
|
813
813
|
function it(e) {
|
|
814
814
|
const t = {
|
|
815
815
|
...e.schema,
|
|
816
|
+
...e.schema.items ? { items: { ...e.schema.items } } : {},
|
|
816
817
|
description: e.description
|
|
817
818
|
};
|
|
818
|
-
H(e) && (t.description = `${e.description} Pass "" to clear it.`);
|
|
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.`);
|
|
819
820
|
const s = be(e);
|
|
820
|
-
return s && (t.enum = s), t;
|
|
821
|
+
return s?.length && (t.enum = s), t;
|
|
821
822
|
}
|
|
822
823
|
function nt(e, t) {
|
|
823
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(`
|
|
@@ -826,38 +827,38 @@ function nt(e, t) {
|
|
|
826
827
|
name: t.name,
|
|
827
828
|
handler: async (r) => {
|
|
828
829
|
const o = [], a = [], l = {};
|
|
829
|
-
for (const [h,
|
|
830
|
-
const
|
|
831
|
-
if (!
|
|
830
|
+
for (const [h, p] of Object.entries(r)) {
|
|
831
|
+
const m = s.get(h);
|
|
832
|
+
if (!m) {
|
|
832
833
|
l[h] = `"${h}" is not a registered control. Available controls: ${Ee(i)}.`;
|
|
833
834
|
continue;
|
|
834
835
|
}
|
|
835
|
-
if (
|
|
836
|
-
const
|
|
837
|
-
if (
|
|
838
|
-
l[h] =
|
|
836
|
+
if (p == null || p === "" && !H(m)) continue;
|
|
837
|
+
const w = st(p, m);
|
|
838
|
+
if (w) {
|
|
839
|
+
l[h] = w;
|
|
839
840
|
continue;
|
|
840
841
|
}
|
|
841
|
-
if (
|
|
842
|
+
if (m.get && I(p, m.get())) {
|
|
842
843
|
a.push(h);
|
|
843
844
|
continue;
|
|
844
845
|
}
|
|
845
|
-
const
|
|
846
|
-
|
|
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);
|
|
847
848
|
}
|
|
848
|
-
const
|
|
849
|
-
success: !
|
|
849
|
+
const d = Object.keys(l).length > 0, u = {
|
|
850
|
+
success: !d,
|
|
850
851
|
applied: o,
|
|
851
852
|
unchanged: a,
|
|
852
|
-
...
|
|
853
|
-
},
|
|
854
|
-
if (!t.data) return ie(
|
|
855
|
-
const
|
|
856
|
-
...
|
|
853
|
+
...d ? { rejected: l } : {}
|
|
854
|
+
}, g = t.getResultBudget();
|
|
855
|
+
if (!t.data) return ie(u, g);
|
|
856
|
+
const f = ie(u, g - tt), v = await t.data.read(f), y = {
|
|
857
|
+
...f,
|
|
857
858
|
data: v
|
|
858
859
|
};
|
|
859
|
-
return G(
|
|
860
|
-
...
|
|
860
|
+
return G(y) <= g ? y : {
|
|
861
|
+
...f,
|
|
861
862
|
data: we
|
|
862
863
|
};
|
|
863
864
|
},
|
|
@@ -1382,9 +1383,9 @@ function ae(e, t) {
|
|
|
1382
1383
|
getPageState: () => {
|
|
1383
1384
|
const l = e.getContextSnapshot();
|
|
1384
1385
|
if (!l) return null;
|
|
1385
|
-
const
|
|
1386
|
-
for (const [
|
|
1387
|
-
return Object.keys(
|
|
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;
|
|
1388
1389
|
}
|
|
1389
1390
|
});
|
|
1390
1391
|
s.start();
|
|
@@ -1392,11 +1393,11 @@ function ae(e, t) {
|
|
|
1392
1393
|
s.signalJsError(l.type);
|
|
1393
1394
|
};
|
|
1394
1395
|
e.on("error:captured", i), e.addDynamicContext(oe, () => {
|
|
1395
|
-
const { pageState: l, ...
|
|
1396
|
+
const { pageState: l, ...d } = s.getSnapshot({ pageState: !1 });
|
|
1396
1397
|
return {
|
|
1397
1398
|
name: "Friction signals",
|
|
1398
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).",
|
|
1399
|
-
data:
|
|
1400
|
+
data: d
|
|
1400
1401
|
};
|
|
1401
1402
|
});
|
|
1402
1403
|
const n = new yt({
|
|
@@ -1404,7 +1405,7 @@ function ae(e, t) {
|
|
|
1404
1405
|
storage: t.storage,
|
|
1405
1406
|
storageKey: t.storageKey
|
|
1406
1407
|
}), r = new It({
|
|
1407
|
-
post: (l,
|
|
1408
|
+
post: (l, d, u) => e.getHttp().post(l, d, u),
|
|
1408
1409
|
agent: e.getConfiguredAgent()
|
|
1409
1410
|
}), o = new Ct({
|
|
1410
1411
|
client: e,
|
|
@@ -1733,15 +1734,15 @@ function Jt(e, t) {
|
|
|
1733
1734
|
const r = () => {
|
|
1734
1735
|
if (!n) {
|
|
1735
1736
|
n = !0, clearTimeout(i), clearTimeout(l), clearTimeout(a);
|
|
1736
|
-
for (const
|
|
1737
|
-
|
|
1737
|
+
for (const u of t) u?.removeEventListener("abort", r);
|
|
1738
|
+
d(), s();
|
|
1738
1739
|
}
|
|
1739
1740
|
}, o = () => {
|
|
1740
1741
|
clearTimeout(l), clearTimeout(i), i = setTimeout(r, Gt);
|
|
1741
|
-
}, a = setTimeout(r, Bt), l = setTimeout(r, qt),
|
|
1742
|
-
for (const
|
|
1743
|
-
if (
|
|
1744
|
-
|
|
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);
|
|
1745
1746
|
}
|
|
1746
1747
|
});
|
|
1747
1748
|
}
|
|
@@ -1752,67 +1753,67 @@ function Ht(e) {
|
|
|
1752
1753
|
};
|
|
1753
1754
|
const s = t, i = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = new AbortController();
|
|
1754
1755
|
let o = !1, a = !1;
|
|
1755
|
-
function l(
|
|
1756
|
+
function l(y) {
|
|
1756
1757
|
return JSON.stringify([
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1758
|
+
y.description,
|
|
1759
|
+
y.inputSchema,
|
|
1760
|
+
y.annotations
|
|
1760
1761
|
]);
|
|
1761
1762
|
}
|
|
1762
|
-
function
|
|
1763
|
-
const
|
|
1764
|
-
return !
|
|
1763
|
+
function d(y, h) {
|
|
1764
|
+
const p = e.getFunctionRegistrations().find((m) => m.name === y)?.webmcp;
|
|
1765
|
+
return !p || !p.navigates ? !1 : h?.success !== !1;
|
|
1765
1766
|
}
|
|
1766
|
-
function
|
|
1767
|
-
const
|
|
1767
|
+
function u() {
|
|
1768
|
+
const y = /* @__PURE__ */ new Map();
|
|
1768
1769
|
for (const h of e.getFunctionRegistrations()) {
|
|
1769
1770
|
if (h.webmcp === !1) continue;
|
|
1770
|
-
const
|
|
1771
|
-
name:
|
|
1771
|
+
const p = h.webmcp || void 0, m = h.name, w = {
|
|
1772
|
+
name: m,
|
|
1772
1773
|
description: h.schema.description,
|
|
1773
1774
|
inputSchema: h.schema.parameters,
|
|
1774
|
-
annotations:
|
|
1775
|
-
execute: async (
|
|
1776
|
-
const z = await e.runExternalFunction(
|
|
1777
|
-
return !o &&
|
|
1775
|
+
annotations: p?.annotations,
|
|
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;
|
|
1778
1779
|
}
|
|
1779
1780
|
};
|
|
1780
|
-
|
|
1781
|
-
tool:
|
|
1782
|
-
signature: l(
|
|
1781
|
+
y.set(m, {
|
|
1782
|
+
tool: w,
|
|
1783
|
+
signature: l(w)
|
|
1783
1784
|
});
|
|
1784
1785
|
}
|
|
1785
|
-
return
|
|
1786
|
+
return y;
|
|
1786
1787
|
}
|
|
1787
|
-
function
|
|
1788
|
+
function g() {
|
|
1788
1789
|
o || a || (a = !0, queueMicrotask(() => {
|
|
1789
|
-
a = !1,
|
|
1790
|
+
a = !1, f();
|
|
1790
1791
|
}));
|
|
1791
1792
|
}
|
|
1792
|
-
function
|
|
1793
|
+
function f() {
|
|
1793
1794
|
if (o) return;
|
|
1794
|
-
const
|
|
1795
|
-
for (const [h,
|
|
1796
|
-
|
|
1797
|
-
for (const [h,
|
|
1795
|
+
const y = u();
|
|
1796
|
+
for (const [h, p] of i)
|
|
1797
|
+
y.get(h)?.signature !== p.signature && (p.controller.abort(), i.delete(h));
|
|
1798
|
+
for (const [h, p] of y) {
|
|
1798
1799
|
if (i.has(h)) continue;
|
|
1799
|
-
const
|
|
1800
|
+
const m = new AbortController();
|
|
1800
1801
|
i.set(h, {
|
|
1801
|
-
signature:
|
|
1802
|
-
controller:
|
|
1803
|
-
}), Promise.resolve(s.registerTool(
|
|
1804
|
-
if (c.error(`WebMCP rejected the tool "${h}":`,
|
|
1802
|
+
signature: p.signature,
|
|
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;
|
|
1805
1806
|
i.delete(h);
|
|
1806
|
-
const
|
|
1807
|
-
n.has(
|
|
1807
|
+
const E = JSON.stringify([h, p.signature]);
|
|
1808
|
+
n.has(E) || (n.add(E), g());
|
|
1808
1809
|
});
|
|
1809
1810
|
}
|
|
1810
1811
|
}
|
|
1811
|
-
const v = e.onFunctionsChanged(
|
|
1812
|
-
return
|
|
1812
|
+
const v = e.onFunctionsChanged(g);
|
|
1813
|
+
return f(), c.log("WebMCP bridge attached"), () => {
|
|
1813
1814
|
if (!o) {
|
|
1814
1815
|
o = !0, r.abort(), v();
|
|
1815
|
-
for (const
|
|
1816
|
+
for (const y of i.values()) y.controller.abort();
|
|
1816
1817
|
i.clear(), c.log("WebMCP bridge detached");
|
|
1817
1818
|
}
|
|
1818
1819
|
};
|
|
@@ -1866,21 +1867,21 @@ var cs = class R {
|
|
|
1866
1867
|
}
|
|
1867
1868
|
async sendMessage(t, s) {
|
|
1868
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");
|
|
1869
|
-
const i = this.functionRegistry.getSchemas(), n = this.buildSendContext(), r = this.config.agent || this.config.defaultAgentId, o = this.resolveClientFunctionsMode(s), a = s?.metadata !== void 0 ? s.metadata : this.config.metadata, l = a != null ? JSON.stringify(a) : void 0,
|
|
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 = {
|
|
1870
1871
|
content: t,
|
|
1871
1872
|
conversation_id: s?.conversationId,
|
|
1872
1873
|
agent_id: s?.agentId || r
|
|
1873
1874
|
};
|
|
1874
|
-
a != null && (
|
|
1875
|
-
const
|
|
1876
|
-
let
|
|
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();
|
|
1877
|
+
let g;
|
|
1877
1878
|
if (s?.files && s.files.length > 0) {
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
for (const v of s.files)
|
|
1881
|
-
|
|
1882
|
-
} else
|
|
1883
|
-
return
|
|
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);
|
|
1884
1885
|
}
|
|
1885
1886
|
async sendRequest(t, s) {
|
|
1886
1887
|
try {
|
|
@@ -2344,19 +2345,19 @@ var cs = class R {
|
|
|
2344
2345
|
continue;
|
|
2345
2346
|
}
|
|
2346
2347
|
this.eventEmitter.emit("function:invoke", l);
|
|
2347
|
-
let
|
|
2348
|
+
let d, u;
|
|
2348
2349
|
try {
|
|
2349
|
-
|
|
2350
|
-
} catch (
|
|
2351
|
-
|
|
2350
|
+
d = await this.functionRegistry.execute(a.functionName, a.arguments ?? {});
|
|
2351
|
+
} catch (g) {
|
|
2352
|
+
u = g instanceof Error ? g.message : "Unknown error", c.error("Client function execution failed:", g);
|
|
2352
2353
|
}
|
|
2353
2354
|
this.eventEmitter.emit("function:result", {
|
|
2354
2355
|
invocationId: a.id,
|
|
2355
|
-
result:
|
|
2356
|
-
error:
|
|
2356
|
+
result: d,
|
|
2357
|
+
error: u
|
|
2357
2358
|
}), o = (await this.submitToolCallForm(a.id, {
|
|
2358
|
-
result:
|
|
2359
|
-
error:
|
|
2359
|
+
result: d,
|
|
2360
|
+
error: u,
|
|
2360
2361
|
_type: "client_function_result"
|
|
2361
2362
|
}))?.resume?.ready ?? o;
|
|
2362
2363
|
}
|
|
@@ -2428,11 +2429,11 @@ var cs = class R {
|
|
|
2428
2429
|
registerNavigationFunction(t, s, i) {
|
|
2429
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", () => {
|
|
2430
2431
|
if (typeof window > "u" || !window.location) return null;
|
|
2431
|
-
const n = window.location.href, r =
|
|
2432
|
-
return
|
|
2432
|
+
const n = window.location.href, r = Ye(window.location.pathname, s), o = { url: n };
|
|
2433
|
+
return r && (o.page = r.name), {
|
|
2433
2434
|
name: "Current page",
|
|
2434
2435
|
description: "The page the user is currently viewing.",
|
|
2435
|
-
data:
|
|
2436
|
+
data: o
|
|
2436
2437
|
};
|
|
2437
2438
|
});
|
|
2438
2439
|
}
|
|
@@ -2481,7 +2482,7 @@ var cs = class R {
|
|
|
2481
2482
|
return t.maxResultBytes ?? this.functionRegistry.getDefaultMaxResultBytes();
|
|
2482
2483
|
}
|
|
2483
2484
|
envelopeBytes(t) {
|
|
2484
|
-
return
|
|
2485
|
+
return b(JSON.stringify({
|
|
2485
2486
|
...t,
|
|
2486
2487
|
data: null
|
|
2487
2488
|
})) - 4;
|
|
@@ -2589,7 +2590,7 @@ var cs = class R {
|
|
|
2589
2590
|
const t = this.activityLedger.getRecent();
|
|
2590
2591
|
return t.length === 0 ? null : {
|
|
2591
2592
|
name: "Recent activity",
|
|
2592
|
-
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.",
|
|
2593
2594
|
data: { events: t }
|
|
2594
2595
|
};
|
|
2595
2596
|
});
|