@xapp/chat-widget 1.105.6 → 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.css +1 -1
- package/dist/index.es.js +99 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +99 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/chatAgentDiscovery.d.ts +0 -0
- package/dist/utils/fingerprint.d.ts +0 -0
- package/dist/xapp/MCPChat.d.ts +0 -0
- package/dist/xapp-chat-widget.css +1 -1
- package/dist/xapp-chat-widget.js +5 -5
- package/dist/xapp-chat-widget.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3490,17 +3490,24 @@ var CLICK_ID_PARAMETERS = [
|
|
|
3490
3490
|
"fbclid"
|
|
3491
3491
|
];
|
|
3492
3492
|
var ATTRIBUTION_PARAMETERS = __spreadArray(__spreadArray([], UTM_PARAMETERS, true), CLICK_ID_PARAMETERS);
|
|
3493
|
+
/**
|
|
3494
|
+
* Params AI surfaces put on the links they send people to: Google AI Overviews
|
|
3495
|
+
* (`st_source=ai_overview`), Google's `srsltid` click id, and the generic `ref` / `source`
|
|
3496
|
+
* that ChatGPT, Perplexity and others use. Read only by the widget `load` event, never stored and
|
|
3497
|
+
* never sent with chat messages.
|
|
3498
|
+
*/
|
|
3499
|
+
var AI_REFERRAL_PARAMETERS = ["st_source", "srsltid", "ref", "source"];
|
|
3493
3500
|
var STORAGE_KEY_PREFIX = "xa_tracking_";
|
|
3494
3501
|
/** Matches the 30 day window the form widget already uses. */
|
|
3495
3502
|
var DEFAULT_PERSISTENCE_DAYS = 30;
|
|
3496
|
-
var MAX_VALUE_LENGTH = 255;
|
|
3503
|
+
var MAX_VALUE_LENGTH$1 = 255;
|
|
3497
3504
|
/**
|
|
3498
3505
|
* Values land in a request body and, downstream, in a CRM. Cap the length and
|
|
3499
3506
|
* reject anything carrying markup or control characters.
|
|
3500
3507
|
*/
|
|
3501
|
-
function isValidValue(value) {
|
|
3508
|
+
function isValidValue$1(value) {
|
|
3502
3509
|
// eslint-disable-next-line no-control-regex
|
|
3503
|
-
return value.length <= MAX_VALUE_LENGTH && !/[<>"'\x00-\x1f]/.test(value);
|
|
3510
|
+
return value.length <= MAX_VALUE_LENGTH$1 && !/[<>"'\x00-\x1f]/.test(value);
|
|
3504
3511
|
}
|
|
3505
3512
|
/**
|
|
3506
3513
|
* Reads the attribution parameters present on a URL. Never throws — a URL we
|
|
@@ -3517,7 +3524,7 @@ function extractAttributionFromUrl(url) {
|
|
|
3517
3524
|
var attribution = {};
|
|
3518
3525
|
ATTRIBUTION_PARAMETERS.forEach(function (parameter) {
|
|
3519
3526
|
var value = parsed.searchParams.get(parameter);
|
|
3520
|
-
if (value && isValidValue(value)) {
|
|
3527
|
+
if (value && isValidValue$1(value)) {
|
|
3521
3528
|
attribution[parameter] = value;
|
|
3522
3529
|
}
|
|
3523
3530
|
});
|
|
@@ -3609,6 +3616,78 @@ function stripQueryString(url) {
|
|
|
3609
3616
|
return undefined;
|
|
3610
3617
|
}
|
|
3611
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
|
+
}
|
|
3688
|
+
|
|
3689
|
+
/** Page params whose VALUES the load event may send, each as its own metadata field. */
|
|
3690
|
+
__spreadArray(__spreadArray([], ATTRIBUTION_PARAMETERS, true), AI_REFERRAL_PARAMETERS);
|
|
3612
3691
|
|
|
3613
3692
|
/**
|
|
3614
3693
|
* Stop the host page scrolling behind an open overlay.
|
|
@@ -15623,11 +15702,26 @@ var ModalContent = function (_a) {
|
|
|
15623
15702
|
/**
|
|
15624
15703
|
* Id the visitor (cookies, browser fingerprint, etc)
|
|
15625
15704
|
*
|
|
15705
|
+
* Kept in localStorage so the widget's load event, which fires before the chat store exists,
|
|
15706
|
+
* reports the same id the store goes on to adopt for a first-time visitor.
|
|
15707
|
+
*
|
|
15626
15708
|
* @export
|
|
15627
15709
|
* @returns {string}
|
|
15628
15710
|
*/
|
|
15711
|
+
var VISITOR_ID_KEY = "xapp_chat_visitorId";
|
|
15629
15712
|
function visitorFingerprint() {
|
|
15630
|
-
|
|
15713
|
+
try {
|
|
15714
|
+
var stored = localStorage.getItem(VISITOR_ID_KEY);
|
|
15715
|
+
if (stored) {
|
|
15716
|
+
return stored;
|
|
15717
|
+
}
|
|
15718
|
+
var id = uuid_1();
|
|
15719
|
+
localStorage.setItem(VISITOR_ID_KEY, id);
|
|
15720
|
+
return id;
|
|
15721
|
+
}
|
|
15722
|
+
catch (_a) {
|
|
15723
|
+
return uuid_1();
|
|
15724
|
+
}
|
|
15631
15725
|
}
|
|
15632
15726
|
|
|
15633
15727
|
var DEFAULT_VISITOR = {
|