@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.
@@ -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: d, handler: f, description: m, parameters: v, maxResultBytes: p, requiresApproval: h, webmcp: g } = e;
402
- return this.register(d, f, {
403
- description: m,
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: p,
405
+ maxResultBytes: y,
406
406
  requiresApproval: h,
407
- webmcp: g
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 u = Me(l);
425
- u.length > 0 && c.warn(`Function "${i}" is over the per-tool budget on ${u.join(", ")}.`), c.log(`Registered function: ${i}`), this.emitChange();
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 E(e) {
482
+ function b(e) {
483
483
  return je.encode(e).length;
484
484
  }
485
485
  function j(e) {
486
- return E(JSON.stringify(e)) - 2;
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 = E(A(n) ?? "null") + (i > 0 ? 1 : 0);
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 = E(A(n) ?? "{}");
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 = E(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 = E(i);
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 = E(A(a) ?? "");
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.` : `Navigate the user to a page in the application. Available pages:
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
- `)}`, o = /* @__PURE__ */ new Map();
649
- for (const u of t) for (const d of B(u.path)) o.set(d, [...o.get(d) ?? [], u.name]);
650
- const a = t.map((u) => u.name), l = { page: {
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: a
653
+ enum: l
654
654
  } };
655
- for (const [u, d] of o) {
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
- l[u] = {
660
+ d[u] = {
661
661
  type: "string",
662
- description: `Value for ":${u}" in the page path. Required when page is ${d.map((f) => `"${f}"`).join(" or ")}.`
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: r,
667
+ description: o,
668
668
  parameters: {
669
669
  type: "object",
670
- properties: l,
670
+ properties: d,
671
671
  required: ["page"]
672
672
  },
673
673
  webmcp: { navigates: !0 },
674
674
  handler: async (u) => {
675
- const d = u.page, f = t.find((g) => g.name === d);
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: ${d}`,
679
- pages: a
678
+ error: `Unknown page: ${g}`,
679
+ pages: l
680
680
  } : {
681
681
  success: !1,
682
- error: `Unknown page: ${d}`
682
+ error: `Unknown page: ${g}`
683
683
  };
684
- let m = {};
684
+ let v = {};
685
685
  if (typeof u.params == "string") try {
686
- m = JSON.parse(u.params);
686
+ v = JSON.parse(u.params);
687
687
  } catch {
688
688
  }
689
- else u.params && typeof u.params == "object" && (m = u.params);
690
- const v = {};
691
- for (const g of B(f.path)) v[g] = u[g] ?? m[g];
692
- const { path: p, missing: h } = Ve(f.path, v);
693
- if (h.length > 0) {
694
- const g = h.map((y) => `"${y}": "..."`).join(", ");
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 "${d}" needs ${h.map((y) => `"${y}"`).join(", ")}. Retry with { "page": "${d}", ${g} }.`
697
+ error: `Page "${g}" needs ${p.map((w) => `"${w}"`).join(", ")}. Retry with { "page": "${g}", ${m} }.`
698
698
  };
699
699
  }
700
- return e(p), {
700
+ return e(h), {
701
701
  success: !0,
702
- navigatedTo: p
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 = E(',"data":' + JSON.stringify(we));
744
+ var se = 100, $ = " … [truncated]", we = { truncated: !0 }, tt = b(',"data":' + JSON.stringify(we));
745
745
  function G(e) {
746
- return E(JSON.stringify(e));
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 u = j(l), d = t - r + o;
759
- if (u <= d) {
760
- i[a] = l, r += u - o;
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, d - o) + $;
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, g] of Object.entries(r)) {
830
- const y = s.get(h);
831
- if (!y) {
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 (g == null || g === "" && !H(y)) continue;
836
- const b = st(g, y);
837
- if (b) {
838
- l[h] = b;
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 (y.get && I(g, y.get())) {
842
+ if (m.get && I(p, m.get())) {
842
843
  a.push(h);
843
844
  continue;
844
845
  }
845
- const w = await y.set(g);
846
- w ? w.result === "rejected" ? l[h] = w.reason || "The page rejected this field's update." : w.result === "unchanged" ? a.push(h) : o.push(h) : o.push(h);
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 u = Object.keys(l).length > 0, d = {
849
- success: !u,
849
+ const d = Object.keys(l).length > 0, u = {
850
+ success: !d,
850
851
  applied: o,
851
852
  unchanged: a,
852
- ...u ? { rejected: l } : {}
853
- }, f = t.getResultBudget();
854
- if (!t.data) return ie(d, f);
855
- const m = ie(d, f - tt), v = await t.data.read(m), p = {
856
- ...m,
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(p) <= f ? p : {
860
- ...m,
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 u = {};
1386
- for (const [d, f] of Object.entries(l.entries)) d.startsWith("page-state:") && f.data && Object.assign(u, f.data);
1387
- return Object.keys(u).length > 0 ? u : null;
1386
+ const d = {};
1387
+ for (const [u, g] of Object.entries(l.entries)) u.startsWith("page-state:") && g.data && Object.assign(d, g.data);
1388
+ return Object.keys(d).length > 0 ? d : null;
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, ...u } = s.getSnapshot({ pageState: !1 });
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: u
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, u, d) => e.getHttp().post(l, u, d),
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 d of t) d?.removeEventListener("abort", r);
1737
- u(), s();
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), u = e(o);
1742
- for (const d of t) {
1743
- if (d?.aborted) return r();
1744
- d?.addEventListener("abort", r);
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(p) {
1756
+ function l(y) {
1756
1757
  return JSON.stringify([
1757
- p.description,
1758
- p.inputSchema,
1759
- p.annotations
1758
+ y.description,
1759
+ y.inputSchema,
1760
+ y.annotations
1760
1761
  ]);
1761
1762
  }
1762
- function u(p, h) {
1763
- const g = e.getFunctionRegistrations().find((y) => y.name === p)?.webmcp;
1764
- return !g || !g.navigates ? !1 : h?.success !== !1;
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 d() {
1767
- const p = /* @__PURE__ */ new Map();
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 g = h.webmcp || void 0, y = h.name, b = {
1771
- name: y,
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: g?.annotations,
1775
- execute: async (w, _e) => {
1776
- const z = await e.runExternalFunction(y, w ?? {});
1777
- return !o && u(y, z) && await Jt((Ce) => e.onFunctionsChanged(Ce), [_e?.signal, r.signal]), z;
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
- p.set(y, {
1781
- tool: b,
1782
- signature: l(b)
1781
+ y.set(m, {
1782
+ tool: w,
1783
+ signature: l(w)
1783
1784
  });
1784
1785
  }
1785
- return p;
1786
+ return y;
1786
1787
  }
1787
- function f() {
1788
+ function g() {
1788
1789
  o || a || (a = !0, queueMicrotask(() => {
1789
- a = !1, m();
1790
+ a = !1, f();
1790
1791
  }));
1791
1792
  }
1792
- function m() {
1793
+ function f() {
1793
1794
  if (o) return;
1794
- const p = d();
1795
- for (const [h, g] of i)
1796
- p.get(h)?.signature !== g.signature && (g.controller.abort(), i.delete(h));
1797
- for (const [h, g] of p) {
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 y = new AbortController();
1800
+ const m = new AbortController();
1800
1801
  i.set(h, {
1801
- signature: g.signature,
1802
- controller: y
1803
- }), Promise.resolve(s.registerTool(g.tool, { signal: y.signal })).catch((b) => {
1804
- if (c.error(`WebMCP rejected the tool "${h}":`, b), i.get(h)?.controller !== y) return;
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 w = JSON.stringify([h, g.signature]);
1807
- n.has(w) || (n.add(w), f());
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(f);
1812
- return m(), c.log("WebMCP bridge attached"), () => {
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 p of i.values()) p.controller.abort();
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, u = {
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 && (u.metadata = a), i.length > 0 && (u.client_functions = i, o === "pause" && (u.client_functions_mode = o)), n && (u.client_context = n), s?.hidden && (u.hidden = !0);
1875
- const d = this.beginTurn();
1876
- let f;
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 m = new FormData();
1879
- m.append("content", t), l !== void 0 && m.append("metadata", l), s.conversationId && m.append("conversation_id", s.conversationId), (s.agentId || r) && m.append("agent_id", s.agentId || r || ""), i.length > 0 && (m.append("client_functions", JSON.stringify(i)), o === "pause" && m.append("client_functions_mode", o)), n && m.append("client_context", JSON.stringify(n)), s.hidden && m.append("hidden", "true");
1880
- for (const v of s.files) m.append("files", v);
1881
- f = await this.sendRequest(d, () => this.httpClient.postFormData("/api/sdk/v1/messages", m, { signal: d.controller.signal }));
1882
- } else f = await this.sendRequest(d, () => this.httpClient.postStream("/api/sdk/v1/messages", u, { signal: d.controller.signal }));
1883
- return f ? this.processSSEResponse(f, d) : this.buildStoppedMessage(d);
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 u, d;
2348
+ let d, u;
2348
2349
  try {
2349
- u = await this.functionRegistry.execute(a.functionName, a.arguments ?? {});
2350
- } catch (f) {
2351
- d = f instanceof Error ? f.message : "Unknown error", c.error("Client function execution failed:", f);
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: u,
2356
- error: d
2356
+ result: d,
2357
+ error: u
2357
2358
  }), o = (await this.submitToolCallForm(a.id, {
2358
- result: u,
2359
- error: d,
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 = typeof document < "u" ? document.title : void 0, o = Ye(window.location.pathname, s), a = { url: n };
2432
- return o && (a.page = o.name), r && (a.title = r), {
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: a
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 E(JSON.stringify({
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
  });