@prodact.ai/sdk 0.0.9 → 0.0.11
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/cdn/sdk.global.js +8 -7
- package/dist/cdn/sdk.global.js.map +1 -1
- package/dist/index.js +74 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -4
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +475 -62
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +468 -55
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1239,7 +1239,7 @@ var UserFlowTracker = class {
|
|
|
1239
1239
|
samplingRate: this.config.samplingRate,
|
|
1240
1240
|
currentState: this.state,
|
|
1241
1241
|
apiUrl: this.apiUrl,
|
|
1242
|
-
hasSessionToken: !!this.
|
|
1242
|
+
hasSessionToken: !!this.sdkSessionToken
|
|
1243
1243
|
});
|
|
1244
1244
|
if (!this.config.enabled) {
|
|
1245
1245
|
console.warn("[UserFlow] Tracking disabled by config");
|
|
@@ -1365,6 +1365,57 @@ var UserFlowTracker = class {
|
|
|
1365
1365
|
isTracking() {
|
|
1366
1366
|
return this.state === "tracking";
|
|
1367
1367
|
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Get recent events for context (excludes SDK UI interactions like chat widget)
|
|
1370
|
+
* @param limit - Maximum number of events to return (default: 10)
|
|
1371
|
+
* @param excludeSelectors - CSS selectors to exclude (default: produck SDK elements)
|
|
1372
|
+
*/
|
|
1373
|
+
getRecentEvents(limit = 10, excludeSelectors) {
|
|
1374
|
+
const defaultExcludeSelectors = [
|
|
1375
|
+
"[data-produck-chat]",
|
|
1376
|
+
".produck-chat",
|
|
1377
|
+
".produck-widget",
|
|
1378
|
+
"#produck-chat",
|
|
1379
|
+
"#produck-widget",
|
|
1380
|
+
'[class*="produck"]',
|
|
1381
|
+
'[id*="produck"]'
|
|
1382
|
+
];
|
|
1383
|
+
const selectorsToExclude = excludeSelectors || defaultExcludeSelectors;
|
|
1384
|
+
const filteredEvents = this.events.filter((event) => {
|
|
1385
|
+
if (event.eventType === "navigation") return true;
|
|
1386
|
+
if (event.element?.selector) {
|
|
1387
|
+
const selectorLower = event.element.selector.toLowerCase();
|
|
1388
|
+
const matchesExclude = selectorsToExclude.some((excludeSel) => {
|
|
1389
|
+
const excludeLower = excludeSel.toLowerCase();
|
|
1390
|
+
if (excludeLower.includes("produck")) {
|
|
1391
|
+
return selectorLower.includes("produck");
|
|
1392
|
+
}
|
|
1393
|
+
return selectorLower.includes(excludeLower.replace(/[\[\].*#]/g, ""));
|
|
1394
|
+
});
|
|
1395
|
+
if (matchesExclude) return false;
|
|
1396
|
+
}
|
|
1397
|
+
return true;
|
|
1398
|
+
});
|
|
1399
|
+
return filteredEvents.slice(-limit);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Get recent events as a summary string for chat context
|
|
1403
|
+
*/
|
|
1404
|
+
getRecentEventsAsSummary(limit = 10) {
|
|
1405
|
+
const events = this.getRecentEvents(limit);
|
|
1406
|
+
if (events.length === 0) return "";
|
|
1407
|
+
return events.map((event) => {
|
|
1408
|
+
if (event.eventType === "navigation") {
|
|
1409
|
+
return `Navigated to: ${event.pageTitle || event.pagePath}`;
|
|
1410
|
+
} else if (event.eventType === "click" && event.element) {
|
|
1411
|
+
const elementDesc = event.element.text || event.element.tag || "element";
|
|
1412
|
+
return `Clicked: ${elementDesc}${event.pageTitle ? ` on ${event.pageTitle}` : ""}`;
|
|
1413
|
+
} else if (event.eventType === "form_submit") {
|
|
1414
|
+
return `Submitted form on: ${event.pageTitle || event.pagePath}`;
|
|
1415
|
+
}
|
|
1416
|
+
return `${event.eventType}: ${event.pageTitle || event.pagePath}`;
|
|
1417
|
+
}).join("\n");
|
|
1418
|
+
}
|
|
1368
1419
|
/**
|
|
1369
1420
|
* Add a custom event
|
|
1370
1421
|
*/
|
|
@@ -2010,12 +2061,16 @@ Check the Network tab in DevTools for more details.`
|
|
|
2010
2061
|
});
|
|
2011
2062
|
}
|
|
2012
2063
|
}
|
|
2064
|
+
const userContext = this.getRecentUserFlowSummary(10);
|
|
2013
2065
|
const sessionResponse = await fetch(
|
|
2014
2066
|
`${this.config.apiUrl}/chat/sessions/${this.sessionToken}/message`,
|
|
2015
2067
|
{
|
|
2016
2068
|
method: "POST",
|
|
2017
2069
|
headers: { "Content-Type": "application/json" },
|
|
2018
|
-
body: JSON.stringify({
|
|
2070
|
+
body: JSON.stringify({
|
|
2071
|
+
message,
|
|
2072
|
+
userContext: userContext || void 0
|
|
2073
|
+
})
|
|
2019
2074
|
}
|
|
2020
2075
|
);
|
|
2021
2076
|
if (!sessionResponse.ok) {
|
|
@@ -2026,11 +2081,13 @@ Check the Network tab in DevTools for more details.`
|
|
|
2026
2081
|
role: "assistant",
|
|
2027
2082
|
content: result.message?.content || result.response || "",
|
|
2028
2083
|
visualFlows: result.flows || [],
|
|
2029
|
-
images: result.images || []
|
|
2084
|
+
images: result.images || [],
|
|
2085
|
+
userFlows: result.userFlows || []
|
|
2030
2086
|
};
|
|
2031
2087
|
await this.log("info", "Chat response received", {
|
|
2032
2088
|
hasFlows: (result.flows || []).length > 0,
|
|
2033
|
-
hasImages: (result.images || []).length > 0
|
|
2089
|
+
hasImages: (result.images || []).length > 0,
|
|
2090
|
+
hasUserFlows: (result.userFlows || []).length > 0
|
|
2034
2091
|
});
|
|
2035
2092
|
this.emit("message", chatMessage);
|
|
2036
2093
|
return chatMessage;
|
|
@@ -2704,6 +2761,19 @@ Check the Network tab in DevTools for more details.`
|
|
|
2704
2761
|
getUserFlowStats() {
|
|
2705
2762
|
return this.userFlowTracker?.getStats() ?? null;
|
|
2706
2763
|
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Get recent user flow events (excluding SDK UI interactions)
|
|
2766
|
+
* Useful for providing context to chat
|
|
2767
|
+
*/
|
|
2768
|
+
getRecentUserFlowEvents(limit = 10) {
|
|
2769
|
+
return this.userFlowTracker?.getRecentEvents(limit) ?? [];
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Get recent user flow events as a summary string for chat context
|
|
2773
|
+
*/
|
|
2774
|
+
getRecentUserFlowSummary(limit = 10) {
|
|
2775
|
+
return this.userFlowTracker?.getRecentEventsAsSummary(limit) ?? "";
|
|
2776
|
+
}
|
|
2707
2777
|
/**
|
|
2708
2778
|
* Check if user flow tracking is active
|
|
2709
2779
|
*/
|