@xapp/chat-widget 1.106.0 → 1.107.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/dist/index.js CHANGED
@@ -3616,6 +3616,75 @@ function stripQueryString(url) {
3616
3616
  return undefined;
3617
3617
  }
3618
3618
  }
3619
+ /**
3620
+ * A minimal client for the tenant's homeowner MCP endpoint: one `tools/call` per request, no
3621
+ * session. The endpoint is public and the server keeps no state we need, so the MCP
3622
+ * initialize handshake would only add a round trip (and a session the next App Runner
3623
+ * instance has never heard of).
3624
+ */
3625
+ /** @class */ ((function () {
3626
+ function HomeownerMcpClient(mcpUrl, fetchImpl) {
3627
+ this.mcpUrl = mcpUrl;
3628
+ this.nextId = 1;
3629
+ this.fetchImpl = fetchImpl || (typeof fetch === "function" ? fetch : undefined);
3630
+ }
3631
+ HomeownerMcpClient.prototype.callTool = function (name, args) {
3632
+ return __awaiter(this, void 0, void 0, function () {
3633
+ var response, body;
3634
+ return __generator(this, function (_a) {
3635
+ switch (_a.label) {
3636
+ case 0:
3637
+ if (typeof this.fetchImpl !== "function") {
3638
+ throw new Error("fetch is not available");
3639
+ }
3640
+ return [4 /*yield*/, this.fetchImpl(this.mcpUrl, {
3641
+ method: "POST",
3642
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
3643
+ body: JSON.stringify({
3644
+ jsonrpc: "2.0",
3645
+ id: this.nextId++,
3646
+ method: "tools/call",
3647
+ params: { name: name, arguments: args },
3648
+ }),
3649
+ })];
3650
+ case 1:
3651
+ response = _a.sent();
3652
+ if (!response.ok) {
3653
+ throw new Error("MCP endpoint answered ".concat(response.status));
3654
+ }
3655
+ return [4 /*yield*/, response.json()];
3656
+ case 2:
3657
+ body = (_a.sent());
3658
+ if (body.error) {
3659
+ throw new Error(body.error.message || "MCP error ".concat(body.error.code));
3660
+ }
3661
+ return [2 /*return*/, toolResultToValue(body.result)];
3662
+ }
3663
+ });
3664
+ });
3665
+ };
3666
+ return HomeownerMcpClient;
3667
+ })());
3668
+ /**
3669
+ * MCP tool results are text parts; agents want a value. JSON text becomes the object it
3670
+ * encodes, prose stays `{ text }`, and a tool-level error becomes `{ ok: false, message }` so
3671
+ * the agent can read the validation message and try again rather than seeing a thrown call.
3672
+ */
3673
+ function toolResultToValue(result) {
3674
+ var text = ((result === null || result === void 0 ? void 0 : result.content) || [])
3675
+ .filter(function (part) { return part.type === "text" && typeof part.text === "string"; })
3676
+ .map(function (part) { return part.text; })
3677
+ .join("\n");
3678
+ if (result === null || result === void 0 ? void 0 : result.isError) {
3679
+ return { ok: false, message: text };
3680
+ }
3681
+ try {
3682
+ return JSON.parse(text);
3683
+ }
3684
+ catch (_a) {
3685
+ return { text: text };
3686
+ }
3687
+ }
3619
3688
 
3620
3689
  /** Page params whose VALUES the load event may send, each as its own metadata field. */
3621
3690
  __spreadArray(__spreadArray([], ATTRIBUTION_PARAMETERS, true), AI_REFERRAL_PARAMETERS);