@xbrain-swe/nova-chat-widget 0.1.10 → 0.1.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/index.cjs +35 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
XbNovaTrack: () => XbNovaTrack,
|
|
39
39
|
trackXbNovaEvent: () => trackXbNovaEvent,
|
|
40
40
|
useXbNovaChat: () => useXbNovaChat,
|
|
41
|
+
useXbNovaContext: () => useXbNovaContext,
|
|
41
42
|
useXbNovaFact: () => useXbNovaFact,
|
|
42
43
|
useXbNovaFacts: () => useXbNovaFacts,
|
|
43
44
|
useXbNovaSettings: () => useXbNovaSettings,
|
|
@@ -86,6 +87,17 @@ function resolveVisitorId() {
|
|
|
86
87
|
function resolveFactValue(value) {
|
|
87
88
|
return typeof value === "function" ? value() : value;
|
|
88
89
|
}
|
|
90
|
+
function collectContextEntries(registry) {
|
|
91
|
+
const out = [];
|
|
92
|
+
for (const source of registry.values()) {
|
|
93
|
+
const entries = typeof source === "function" ? source() : source;
|
|
94
|
+
if (!Array.isArray(entries)) continue;
|
|
95
|
+
for (const e of entries) {
|
|
96
|
+
if (e && typeof e.title === "string" && typeof e.description === "string") out.push(e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
89
101
|
function InternalProvider({
|
|
90
102
|
auth,
|
|
91
103
|
clientActionHandlers,
|
|
@@ -94,6 +106,7 @@ function InternalProvider({
|
|
|
94
106
|
}) {
|
|
95
107
|
const trackRegistry = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current;
|
|
96
108
|
const factsRegistry = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current;
|
|
109
|
+
const contextRegistry = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current;
|
|
97
110
|
const emptyHandlers = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current;
|
|
98
111
|
const visitorIdRef = (0, import_react.useRef)(null);
|
|
99
112
|
if (visitorIdRef.current === null) {
|
|
@@ -104,11 +117,12 @@ function InternalProvider({
|
|
|
104
117
|
auth,
|
|
105
118
|
trackRegistry,
|
|
106
119
|
factsRegistry,
|
|
120
|
+
contextRegistry,
|
|
107
121
|
clientActionHandlers: clientActionHandlers ?? emptyHandlers,
|
|
108
122
|
visitorId: visitorIdRef.current,
|
|
109
123
|
theme
|
|
110
124
|
}),
|
|
111
|
-
[auth, trackRegistry, factsRegistry, clientActionHandlers, emptyHandlers, theme]
|
|
125
|
+
[auth, trackRegistry, factsRegistry, contextRegistry, clientActionHandlers, emptyHandlers, theme]
|
|
112
126
|
);
|
|
113
127
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InternalContext.Provider, { value, children });
|
|
114
128
|
}
|
|
@@ -1136,7 +1150,7 @@ async function resumeToolResult(apiBaseUrl, apiKey, body, handlers) {
|
|
|
1136
1150
|
// src/use-chat.ts
|
|
1137
1151
|
var DEFAULT_CLIENT_ACTION_TIMEOUT_MS = 15e3;
|
|
1138
1152
|
function useXbNovaChat(options) {
|
|
1139
|
-
const { auth, trackRegistry, clientActionHandlers, visitorId } = useXbNovaInternal();
|
|
1153
|
+
const { auth, trackRegistry, contextRegistry, clientActionHandlers, visitorId } = useXbNovaInternal();
|
|
1140
1154
|
const botId = options?.botId ?? auth.botId;
|
|
1141
1155
|
const nudgeNodeId = options?.nudgeNodeId;
|
|
1142
1156
|
const { apiKey, apiBaseUrl } = auth;
|
|
@@ -1288,7 +1302,9 @@ function useXbNovaChat(options) {
|
|
|
1288
1302
|
return next;
|
|
1289
1303
|
});
|
|
1290
1304
|
const focused = getFocusedTrackEntry(trackRegistry);
|
|
1291
|
-
const
|
|
1305
|
+
const notes = collectContextEntries(contextRegistry);
|
|
1306
|
+
const screen = focused ? { region: focused.region, data: resolveFactValue(focused.data) } : {};
|
|
1307
|
+
const context = focused || notes.length ? { ...screen, ...notes.length ? { notes } : {} } : void 0;
|
|
1292
1308
|
try {
|
|
1293
1309
|
await streamChat(
|
|
1294
1310
|
apiBaseUrl,
|
|
@@ -1298,7 +1314,8 @@ function useXbNovaChat(options) {
|
|
|
1298
1314
|
message: trimmed,
|
|
1299
1315
|
conversation_id: onboarding?.conversation_id ?? null,
|
|
1300
1316
|
context,
|
|
1301
|
-
nudge_node_id: nudgeNodeId ?? null
|
|
1317
|
+
nudge_node_id: nudgeNodeId ?? null,
|
|
1318
|
+
opening_message: messages.length === 0 ? (options?.openingMessage ?? onboarding?.greeting) || null : null
|
|
1302
1319
|
},
|
|
1303
1320
|
{ onPart: replaceLast, onMessageId: setLastAssistantId, onError: setError }
|
|
1304
1321
|
);
|
|
@@ -1597,6 +1614,7 @@ function XbNovaChat({
|
|
|
1597
1614
|
onFeedback,
|
|
1598
1615
|
botId: activeBotId ?? botId,
|
|
1599
1616
|
nudgeNodeId: activeNudgeNodeId,
|
|
1617
|
+
openingMessage: openingLine ?? void 0,
|
|
1600
1618
|
onDismissSheet: () => setOpen(false)
|
|
1601
1619
|
});
|
|
1602
1620
|
const effectiveBotId = activeBotId ?? botId;
|
|
@@ -2200,6 +2218,18 @@ function useXbNovaFacts(values) {
|
|
|
2200
2218
|
};
|
|
2201
2219
|
}, [factsRegistry]);
|
|
2202
2220
|
}
|
|
2221
|
+
function useXbNovaContext(entries) {
|
|
2222
|
+
const { contextRegistry } = useXbNovaInternal();
|
|
2223
|
+
const id = (0, import_react10.useId)();
|
|
2224
|
+
(0, import_react10.useEffect)(() => {
|
|
2225
|
+
contextRegistry.set(id, entries);
|
|
2226
|
+
});
|
|
2227
|
+
(0, import_react10.useEffect)(() => {
|
|
2228
|
+
return () => {
|
|
2229
|
+
contextRegistry.delete(id);
|
|
2230
|
+
};
|
|
2231
|
+
}, [id, contextRegistry]);
|
|
2232
|
+
}
|
|
2203
2233
|
function useXbNovaVisitor() {
|
|
2204
2234
|
const { visitorId } = useXbNovaInternal();
|
|
2205
2235
|
return visitorId;
|
|
@@ -2221,6 +2251,7 @@ function XbNovaFacts({ values }) {
|
|
|
2221
2251
|
XbNovaTrack,
|
|
2222
2252
|
trackXbNovaEvent,
|
|
2223
2253
|
useXbNovaChat,
|
|
2254
|
+
useXbNovaContext,
|
|
2224
2255
|
useXbNovaFact,
|
|
2225
2256
|
useXbNovaFacts,
|
|
2226
2257
|
useXbNovaSettings,
|