@inkeep/cxkit-primitives 0.5.49 → 0.5.50
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/components/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/components/embedded-chat/use-inkeep-chat.js +52 -52
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/dist/providers/chat-events-provider.cjs +1 -1
- package/dist/providers/chat-events-provider.js +29 -31
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("openai"),t=require("react"),Re=require("../../providers/config-provider.cjs"),Le=require("../../providers/conversation-provider.cjs"),xe=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),Be=require("../../utils/misc.cjs"),ae=require("../../utils/reset-query-params.cjs"),De=require("../../providers/chat-form-provider.cjs"),Oe=require("../../providers/widget-provider.cjs"),Fe=require("../../hooks/use-media-query.cjs"),Te=require("./use-captcha.cjs"),Ke=require("../modal/modal-provider.cjs"),l=require("../../utils/generate-uid.cjs"),Qe=require("../../utils/tools/links-tool.cjs"),We=require("../../atoms/api/analytics/conversation.cjs"),Je=()=>{const{chatId:f,setConversation:re,conversation:N,resetConversation:ie}=Le.useInkeepConversation(),{baseSettings:b,aiChatSettings:O}=Re.useInkeepConfig(),{aiApiBaseUrl:F,shouldBypassCaptcha:T,filters:K}=b,Q=Ke.useModal(),{getSolution:ce,prefetchSolution:q,invalidateSolution:W}=Te.useCaptcha({fetchUrl:`${F}/v1/challenge`,shouldBypassCaptcha:T,shouldMakeInitialRequest:Q?Q.isOpen:!0}),ue=new Ae({baseURL:`${F}/v1`,apiKey:b.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:le,getTools:ge,prompts:de,model:me,filters:J,onToolCall:fe}=O,[p,_]=t.useState(""),z=t.useRef(null);t.useEffect(()=>{le?.(p)},[p]);const[g,u]=t.useState([]),[H,h]=t.useState(!1),[pe,v]=t.useState(!1),[he,j]=t.useState(null),[A,G]=t.useState(null),[y,S]=t.useState([]),ve=e=>{S(s=>[...s,e])},[ye,V]=t.useState({}),r=t.useRef([]),C=t.useRef(null),{logEvent:P}=xe.useChatEvents(),X=de?.map((e,s)=>({id:`system-${Date.now().toString()}-${l.generateUid(4)}-${s}`,role:"system",content:e})),[Se,Ce]=t.useState(!!f);t.useEffect(()=>{if(f){const{apiKey:e,analyticsApiBaseUrl:s}=b;We.getConversation(f,e,s).then(o=>{if(o){P({eventName:"shared_chat_loaded",properties:{conversation:o}}),Ce(!1),re({...o,id:""});const a=o.messages.map(c=>({id:Date.now().toString()+l.generateUid(4)+c.id,content:Be.parseIfJson(c.content),role:c.role,links:c.links}));u(a),r.current=a}})}},[f]);const Me=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${b.organizationDisplayName??"Administrator"}`;default:return`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),u(s=>{const o=[...s],a=o[o.length-1];return a&&(a.content=Me(e)),o}),h(!1),v(!1),W(),q()},R=!
|
|
4
|
-
${D.serializeWorkflow(e)}`},...X,a,c];u(E),S([])},{openForm:
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),u(s=>{const o=[...s],a=o[o.length-1];return a&&(a.content=Me(e)),o}),h(!1),v(!1),W(),q()},R=!p.trim()&&!y.length||H,we=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),L())},Ie=e=>{const s=e.target.value;_(s)},L=async(e=p)=>{if(R&&(!e||e.trim().length===0))return;h(!0);const s=A?g.length===2:g.length===0,o=D.getMessageMetadata(A,y,s);let a;const c=D.serializeAttachments(y);y.length&&c?a=[{type:"text",text:c}]:a=e;const ee={id:`${Date.now().toString()}-${l.generateUid(4)}-1`,role:"user",content:a,metadata:o},E=[...g.length?[]:X,ee];f&&ae.resetQueryParams(),u(M=>[...M,...E]),r.current=[...r.current,...E],S([]),_(""),P({eventName:"user_message_submitted",properties:{}},r.current);const te=[Qe.provideLinksTool,...ge?.({conversation:N})||[]];try{const M={model:me,messages:r.current,stream:!0,tools:te,tool_choice:"auto"},se=await ce(),ne=se?btoa(JSON.stringify(se)):null,oe=K||J?JSON.stringify({...K,...J}):void 0,U={};!T&&ne&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=ne),oe&&(U["inkeep-filters"]=oe);const d=ue.beta.chat.completions.stream(M,Object.keys(U).length>0?{headers:U}:void 0),n={id:`${Date.now().toString()}-${l.generateUid(4)}-2`,role:"assistant",content:"",links:[],toolCalls:[]};u(w=>[...w,n]),d.on("content",(w,I)=>{v(!0),n.content=I,u($=>{const i=[...$],x=i.findIndex(k=>k.id===n.id);return x===-1?[...i,n]:(i[x]={...n},i)})}),d.on("tool_calls.function.arguments.done",async w=>{const{name:I,arguments:$}=w,i=te?.find(m=>m.function.name===I);if(!i)return;const k=("parse"in i.function?i.function.parse:JSON.parse)($),Ue=i.function.function?.(k,d),$e=i.renderMessageButtons?.({args:k,execution:Ue})??[];I==="provideLinks"?n.links=k.links??[]:V(m=>({...m,[n.id]:[...m[n.id]??[],...$e]})),n.toolCalls?.push({id:"call_"+l.generateUid(24),type:"function",function:{name:I,arguments:$}}),u(m=>{const B=[...m],Ne=B.findIndex(_e=>_e.id===n.id);return B[Ne]={...n},B}),fe?.(w,{conversation:{...N,messages:[...r.current,n]}})}),d.on("error",Y),d.finalChatCompletion().then(()=>{r.current=[...r.current,n],C.current=null,h(!1),v(!1),q(),P({eventName:"assistant_message_received",properties:{}},r.current)}),C.current=d.controller}catch(M){Y(M),h(!1),v(!1)}},ke=()=>{C.current&&(C.current.abort(),C.current=null),h(!1),v(!1),q()},Z=()=>{j(null),u([]),r.current=[],ie(),V({}),S([]),ae.resetQueryParams(),G(null),W(),q(),P({eventName:"chat_clear_button_clicked",properties:{conversation:N}})},be=e=>{G(e);const{initialReplyMessage:s,displayName:o}=e,a={id:g.length.toString()+l.generateUid(4),role:"user",content:o},c={id:(g.length+1).toString()+l.generateUid(4),role:"assistant",content:s,links:[]},E=[{id:`system-${Date.now().toString()}-${l.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
|
+
${D.serializeWorkflow(e)}`},...X,a,c];u(E),S([])},{openForm:qe}=De.useChatForm(),Pe=Oe.useWidget();t.useImperativeHandle(O.chatFunctionsRef,()=>({submitMessage:L,updateInputMessage(e){_(e)},clearChat:Z,openForm:e=>{Pe?.setView("chat"),qe(e)},focusInput:()=>{z.current?.focus()}}));const Ee=Fe.useMediaQuery("(max-width: 768px)");return{messages:g,input:p,isLoading:H,isStreaming:pe,isLoadingConversation:Se,error:he,isSubmitDisabled:R,handleInputChange:Ie,handleInputKeyDown:we,handleSubmit:L,stop:ke,clear:Z,handleWorkflow:be,selectedWorkflow:A,messageAttachments:y,setMessageAttachments:S,addAttachment:ve,messageButtons:ye,isEmpty:g.length===0,inputRef:z,isMobile:Ee}};exports.useInkeepChat=Je;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import { useState as c, useRef as U, useEffect as ae, useImperativeHandle as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import { useInkeepConversation as
|
|
6
|
-
import { useChatEvents as
|
|
7
|
-
import { getMessageMetadata as
|
|
8
|
-
import { parseIfJson as
|
|
2
|
+
import De from "openai";
|
|
3
|
+
import { useState as c, useRef as U, useEffect as ae, useImperativeHandle as Oe } from "react";
|
|
4
|
+
import { useInkeepConfig as Re } from "../../providers/config-provider.js";
|
|
5
|
+
import { useInkeepConversation as Pe } from "../../providers/conversation-provider.js";
|
|
6
|
+
import { useChatEvents as Ue } from "../../providers/chat-events-provider.js";
|
|
7
|
+
import { getMessageMetadata as Fe, serializeAttachments as Ke, serializeWorkflow as Te } from "../../utils/get-message-metadata.js";
|
|
8
|
+
import { parseIfJson as We } from "../../utils/misc.js";
|
|
9
9
|
import { resetQueryParams as re } from "../../utils/reset-query-params.js";
|
|
10
|
-
import { useChatForm as
|
|
11
|
-
import { useWidget as
|
|
12
|
-
import { useMediaQuery as
|
|
13
|
-
import { useCaptcha as
|
|
14
|
-
import { useModal as
|
|
10
|
+
import { useChatForm as Je } from "../../providers/chat-form-provider.js";
|
|
11
|
+
import { useWidget as ze } from "../../providers/widget-provider.js";
|
|
12
|
+
import { useMediaQuery as He } from "../../hooks/use-media-query.js";
|
|
13
|
+
import { useCaptcha as Qe } from "./use-captcha.js";
|
|
14
|
+
import { useModal as je } from "../modal/modal-provider.js";
|
|
15
15
|
import { generateUid as u } from "../../utils/generate-uid.js";
|
|
16
|
-
import { provideLinksTool as
|
|
17
|
-
import { getConversation as
|
|
18
|
-
const
|
|
19
|
-
const { chatId: d, setConversation: ie, conversation: x, resetConversation: ce } =
|
|
16
|
+
import { provideLinksTool as qe } from "../../utils/tools/links-tool.js";
|
|
17
|
+
import { getConversation as Ge } from "../../atoms/api/analytics/conversation.js";
|
|
18
|
+
const gt = () => {
|
|
19
|
+
const { chatId: d, setConversation: ie, conversation: x, resetConversation: ce } = Pe(), { baseSettings: b, aiChatSettings: F } = Re(), { aiApiBaseUrl: K, shouldBypassCaptcha: T, filters: W } = b, J = je(), { getSolution: le, prefetchSolution: $, invalidateSolution: z } = Qe({
|
|
20
20
|
fetchUrl: `${K}/v1/challenge`,
|
|
21
21
|
shouldBypassCaptcha: T,
|
|
22
22
|
shouldMakeInitialRequest: J ? J.isOpen : !0
|
|
23
|
-
}), ue = new
|
|
23
|
+
}), ue = new De({
|
|
24
24
|
baseURL: `${K}/v1`,
|
|
25
25
|
apiKey: b.apiKey,
|
|
26
26
|
dangerouslyAllowBrowser: !0
|
|
@@ -37,25 +37,25 @@ const dt = () => {
|
|
|
37
37
|
}, [f]);
|
|
38
38
|
const [m, l] = c([]), [j, h] = c(!1), [he, y] = c(!1), [ye, q] = c(null), [B, G] = c(null), [C, v] = c([]), Ce = (e) => {
|
|
39
39
|
v((t) => [...t, e]);
|
|
40
|
-
}, [ve, V] = c({}), a = U([]), w = U(null), { logEvent: E
|
|
40
|
+
}, [ve, V] = c({}), a = U([]), w = U(null), { logEvent: E } = Ue(), X = pe?.map((e, t) => ({
|
|
41
41
|
id: `system-${Date.now().toString()}-${u(4)}-${t}`,
|
|
42
42
|
role: "system",
|
|
43
43
|
content: e
|
|
44
|
-
})), [
|
|
44
|
+
})), [we, Ie] = c(!!d);
|
|
45
45
|
ae(() => {
|
|
46
46
|
if (d) {
|
|
47
47
|
const { apiKey: e, analyticsApiBaseUrl: t } = b;
|
|
48
|
-
|
|
48
|
+
Ge(d, e, t).then((n) => {
|
|
49
49
|
if (n) {
|
|
50
50
|
E({
|
|
51
51
|
eventName: "shared_chat_loaded",
|
|
52
52
|
properties: {
|
|
53
53
|
conversation: n
|
|
54
54
|
}
|
|
55
|
-
}),
|
|
55
|
+
}), Ie(!1), ie({ ...n, id: "" });
|
|
56
56
|
const o = n.messages.map((i) => ({
|
|
57
57
|
id: Date.now().toString() + u(4) + i.id,
|
|
58
|
-
content:
|
|
58
|
+
content: We(i.content),
|
|
59
59
|
role: i.role,
|
|
60
60
|
links: i.links
|
|
61
61
|
}));
|
|
@@ -64,7 +64,7 @@ const dt = () => {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
}, [d]);
|
|
67
|
-
const
|
|
67
|
+
const Me = (e) => {
|
|
68
68
|
switch (e.code) {
|
|
69
69
|
case 400:
|
|
70
70
|
return e.message;
|
|
@@ -78,19 +78,19 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
78
78
|
}, Y = (e) => {
|
|
79
79
|
q(e), l((t) => {
|
|
80
80
|
const n = [...t], o = n[n.length - 1];
|
|
81
|
-
return o && (o.content =
|
|
81
|
+
return o && (o.content = Me(e)), n;
|
|
82
82
|
}), h(!1), y(!1), z(), $();
|
|
83
|
-
}, D = !f.trim() && !C.length || j,
|
|
83
|
+
}, D = !f.trim() && !C.length || j, Se = (e) => {
|
|
84
84
|
e.key === "Enter" && !e.shiftKey && !D && !e.nativeEvent.isComposing && (e.preventDefault(), O());
|
|
85
|
-
},
|
|
85
|
+
}, ke = (e) => {
|
|
86
86
|
const t = e.target.value;
|
|
87
87
|
L(t);
|
|
88
88
|
}, O = async (e = f) => {
|
|
89
89
|
if (D && (!e || e.trim().length === 0)) return;
|
|
90
90
|
h(!0);
|
|
91
|
-
const t = B ? m.length === 2 : m.length === 0, n =
|
|
91
|
+
const t = B ? m.length === 2 : m.length === 0, n = Fe(B, C, t);
|
|
92
92
|
let o;
|
|
93
|
-
const i =
|
|
93
|
+
const i = Ke(C);
|
|
94
94
|
C.length && i ? o = [{ type: "text", text: i }] : o = e;
|
|
95
95
|
const ee = {
|
|
96
96
|
id: `${Date.now().toString()}-${u(4)}-1`,
|
|
@@ -105,7 +105,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
105
105
|
},
|
|
106
106
|
a.current
|
|
107
107
|
);
|
|
108
|
-
const te = [
|
|
108
|
+
const te = [qe, ...ge?.({ conversation: x }) || []];
|
|
109
109
|
try {
|
|
110
110
|
const I = {
|
|
111
111
|
model: de,
|
|
@@ -136,10 +136,10 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
136
136
|
}), g.on("tool_calls.function.arguments.done", async (M) => {
|
|
137
137
|
const { name: S, arguments: A } = M, r = te?.find((p) => p.function.name === S);
|
|
138
138
|
if (!r) return;
|
|
139
|
-
const k = ("parse" in r.function ? r.function.parse : JSON.parse)(A),
|
|
139
|
+
const k = ("parse" in r.function ? r.function.parse : JSON.parse)(A), Ae = r.function.function?.(k, g), xe = r.renderMessageButtons?.({ args: k, execution: Ae }) ?? [];
|
|
140
140
|
S === "provideLinks" ? s.links = k.links ?? [] : V((p) => ({
|
|
141
141
|
...p,
|
|
142
|
-
[s.id]: [...p[s.id] ?? [], ...
|
|
142
|
+
[s.id]: [...p[s.id] ?? [], ...xe]
|
|
143
143
|
})), s.toolCalls?.push({
|
|
144
144
|
id: "call_" + u(24),
|
|
145
145
|
type: "function",
|
|
@@ -148,14 +148,14 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
148
148
|
arguments: A
|
|
149
149
|
}
|
|
150
150
|
}), l((p) => {
|
|
151
|
-
const P = [...p],
|
|
152
|
-
return P[
|
|
151
|
+
const P = [...p], Le = P.findIndex((Be) => Be.id === s.id);
|
|
152
|
+
return P[Le] = { ...s }, P;
|
|
153
|
+
}), fe?.(M, {
|
|
154
|
+
conversation: {
|
|
155
|
+
...x,
|
|
156
|
+
messages: [...a.current, s]
|
|
157
|
+
}
|
|
153
158
|
});
|
|
154
|
-
const Be = await we([
|
|
155
|
-
...a.current,
|
|
156
|
-
s
|
|
157
|
-
]);
|
|
158
|
-
fe?.(M, { conversation: Be ?? x });
|
|
159
159
|
}), g.on("error", Y), g.finalChatCompletion().then(() => {
|
|
160
160
|
a.current = [...a.current, s], w.current = null, h(!1), y(!1), $(), E(
|
|
161
161
|
{
|
|
@@ -168,7 +168,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
168
168
|
} catch (I) {
|
|
169
169
|
Y(I), h(!1), y(!1);
|
|
170
170
|
}
|
|
171
|
-
},
|
|
171
|
+
}, be = () => {
|
|
172
172
|
w.current && (w.current.abort(), w.current = null), h(!1), y(!1), $();
|
|
173
173
|
}, Z = () => {
|
|
174
174
|
q(null), l([]), a.current = [], ce(), V({}), v([]), re(), G(null), z(), $(), E({
|
|
@@ -177,7 +177,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
177
177
|
conversation: x
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
|
-
},
|
|
180
|
+
}, $e = (e) => {
|
|
181
181
|
G(e);
|
|
182
182
|
const { initialReplyMessage: t, displayName: n } = e, o = {
|
|
183
183
|
id: m.length.toString() + u(4),
|
|
@@ -192,38 +192,38 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
192
192
|
id: `system-${Date.now().toString()}-${u(4)}-${e.id}`,
|
|
193
193
|
role: "system",
|
|
194
194
|
content: `Company has asked user to follow this guided workflow:
|
|
195
|
-
${
|
|
195
|
+
${Te(e)}`
|
|
196
196
|
}, ...X, o, i];
|
|
197
197
|
l(N), v([]);
|
|
198
|
-
}, { openForm:
|
|
199
|
-
|
|
198
|
+
}, { openForm: Ee } = Je(), Ne = ze();
|
|
199
|
+
Oe(F.chatFunctionsRef, () => ({
|
|
200
200
|
submitMessage: O,
|
|
201
201
|
updateInputMessage(e) {
|
|
202
202
|
L(e);
|
|
203
203
|
},
|
|
204
204
|
clearChat: Z,
|
|
205
205
|
openForm: (e) => {
|
|
206
|
-
|
|
206
|
+
Ne?.setView("chat"), Ee(e);
|
|
207
207
|
},
|
|
208
208
|
focusInput: () => {
|
|
209
209
|
Q.current?.focus();
|
|
210
210
|
}
|
|
211
211
|
}));
|
|
212
|
-
const
|
|
212
|
+
const _e = He("(max-width: 768px)");
|
|
213
213
|
return {
|
|
214
214
|
messages: m,
|
|
215
215
|
input: f,
|
|
216
216
|
isLoading: j,
|
|
217
217
|
isStreaming: he,
|
|
218
|
-
isLoadingConversation:
|
|
218
|
+
isLoadingConversation: we,
|
|
219
219
|
error: ye,
|
|
220
220
|
isSubmitDisabled: D,
|
|
221
|
-
handleInputChange:
|
|
222
|
-
handleInputKeyDown:
|
|
221
|
+
handleInputChange: ke,
|
|
222
|
+
handleInputKeyDown: Se,
|
|
223
223
|
handleSubmit: O,
|
|
224
|
-
stop:
|
|
224
|
+
stop: be,
|
|
225
225
|
clear: Z,
|
|
226
|
-
handleWorkflow:
|
|
226
|
+
handleWorkflow: $e,
|
|
227
227
|
selectedWorkflow: B,
|
|
228
228
|
messageAttachments: C,
|
|
229
229
|
setMessageAttachments: v,
|
|
@@ -231,9 +231,9 @@ ${Je(e)}`
|
|
|
231
231
|
messageButtons: ve,
|
|
232
232
|
isEmpty: m.length === 0,
|
|
233
233
|
inputRef: Q,
|
|
234
|
-
isMobile:
|
|
234
|
+
isMobile: _e
|
|
235
235
|
};
|
|
236
236
|
};
|
|
237
237
|
export {
|
|
238
|
-
|
|
238
|
+
gt as useInkeepChat
|
|
239
239
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),f=require("./user-provider.cjs"),d=t.createContext(void 0),b=({children:e})=>{const{baseSettings:n,componentType:o}=B.useInkeepConfig(),{apiKey:r,analyticsApiBaseUrl:i,tags:c,privacyPreferences:E,env:g}=n,{userProperties:a}=f.useUser(),v=t.useMemo(()=>({widgetLibraryVersion:"0.5.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),f=require("./user-provider.cjs"),d=t.createContext(void 0),b=({children:e})=>{const{baseSettings:n,componentType:o}=B.useInkeepConfig(),{apiKey:r,analyticsApiBaseUrl:i,tags:c,privacyPreferences:E,env:g}=n,{userProperties:a}=f.useUser(),v=t.useMemo(()=>({widgetLibraryVersion:"0.5.50",componentType:o,tags:c}),[o,c]),u=!E.optOutAllAnalytics&&g!=="development",m={logEvent:t.useCallback(async l=>{const s={...v,...l.properties},p={eventName:l.eventName,properties:s,userProperties:a};if(u){if("conversation"in s&&!s.conversation?.id)return;y.logEvent(p,r,i)}n.onEvent?.(p)},[u,n,r,i,a,v])};return P.jsx(d.Provider,{value:m,children:e})},x=()=>{const e=t.useContext(d);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=b;exports.useBaseEvents=x;
|
|
@@ -7,7 +7,7 @@ import { useUser as b } from "./user-provider.js";
|
|
|
7
7
|
const u = x(void 0), U = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: n } = C(), { apiKey: s, analyticsApiBaseUrl: r, tags: i, privacyPreferences: l, env: E } = t, { userProperties: a } = b(), c = g(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.50",
|
|
11
11
|
componentType: n,
|
|
12
12
|
tags: i
|
|
13
13
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),j=require("../atoms/api/analytics/conversation.cjs"),w=require("./config-provider.cjs"),B=require("./conversation-provider.cjs"),k=require("./user-provider.cjs"),f=require("./base-events-provider.cjs"),g=t.createContext(void 0),b=({children:e})=>{const{baseSettings:x}=w.useInkeepConfig(),{apiKey:C,analyticsApiBaseUrl:d,tags:E,privacyPreferences:{optOutAllAnalytics:i},env:a}=x,{userProperties:h}=k.useUser(),{logEvent:p}=f.useBaseEvents(),{conversation:c,setConversation:y}=B.useInkeepConversation(),v=t.useRef(c);t.useEffect(()=>{v.current=c},[c]);const u=t.useCallback(async n=>{const s=v.current,r=!i&&a!=="development";let o=Object.assign({},s,{messages:n});if(r){const P=await j.logConversation(s.id,{messages:n,tags:E,userProperties:h},C,d);P&&(o=P)}return o},[d,C,E,h,i,a]),q={logEvent:t.useCallback(async(n,s)=>{let r=v.current;s&&(r=await u(s),y(r));const o={...n,properties:{conversation:r,...n.properties}};p(o)},[p,u,i,a]),logConversation:u};return l.jsx(g.Provider,{value:q,children:e})},A=({children:e})=>l.jsx(f.BaseEventsProvider,{children:l.jsx(b,{children:e})}),O=()=>{const e=t.useContext(g);if(!e)throw new Error("useChatEvents must be used within a ChatEventsProvider");return e};exports.ChatEventsProvider=b;exports.ChatEventsProviderWithBase=A;exports.useChatEvents=O;
|
|
@@ -1,65 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useRef as y, useEffect as w, useCallback as
|
|
2
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as y, useEffect as w, useCallback as h, createContext as b, useContext as B } from "react";
|
|
4
4
|
import { logConversation as k } from "../atoms/api/analytics/conversation.js";
|
|
5
5
|
import { useInkeepConfig as A } from "./config-provider.js";
|
|
6
6
|
import { useInkeepConversation as j } from "./conversation-provider.js";
|
|
7
7
|
import { useUser as I } from "./user-provider.js";
|
|
8
8
|
import { useBaseEvents as O, BaseEventsProvider as U } from "./base-events-provider.js";
|
|
9
|
-
const
|
|
9
|
+
const m = b(void 0), K = ({ children: t }) => {
|
|
10
10
|
const { baseSettings: g } = A(), {
|
|
11
|
-
apiKey:
|
|
12
|
-
analyticsApiBaseUrl:
|
|
13
|
-
tags:
|
|
11
|
+
apiKey: p,
|
|
12
|
+
analyticsApiBaseUrl: l,
|
|
13
|
+
tags: C,
|
|
14
14
|
privacyPreferences: { optOutAllAnalytics: s },
|
|
15
15
|
env: i
|
|
16
|
-
} = g, { userProperties:
|
|
16
|
+
} = g, { userProperties: f } = I(), { logEvent: E } = O(), { conversation: a, setConversation: P } = j(), c = y(a);
|
|
17
17
|
w(() => {
|
|
18
|
-
|
|
19
|
-
}, [
|
|
20
|
-
const
|
|
18
|
+
c.current = a;
|
|
19
|
+
}, [a]);
|
|
20
|
+
const v = h(
|
|
21
21
|
async (e) => {
|
|
22
|
-
const n =
|
|
22
|
+
const n = c.current, o = !s && i !== "development";
|
|
23
23
|
let r = Object.assign({}, n, { messages: e });
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
24
|
+
if (o) {
|
|
25
|
+
const d = await k(
|
|
26
26
|
n.id,
|
|
27
27
|
{
|
|
28
28
|
messages: e,
|
|
29
|
-
tags:
|
|
30
|
-
userProperties:
|
|
29
|
+
tags: C,
|
|
30
|
+
userProperties: f
|
|
31
31
|
},
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
p,
|
|
33
|
+
l
|
|
34
34
|
);
|
|
35
|
-
|
|
35
|
+
d && (r = d);
|
|
36
36
|
}
|
|
37
37
|
return r;
|
|
38
38
|
},
|
|
39
|
-
[
|
|
39
|
+
[l, p, C, f, s, i]
|
|
40
40
|
), x = {
|
|
41
|
-
logEvent:
|
|
41
|
+
logEvent: h(
|
|
42
42
|
async (e, n) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const c = {
|
|
43
|
+
let o = c.current;
|
|
44
|
+
n && (o = await v(n), P(o));
|
|
45
|
+
const r = {
|
|
48
46
|
...e,
|
|
49
47
|
properties: {
|
|
50
48
|
conversation: o,
|
|
51
49
|
...e.properties
|
|
52
50
|
}
|
|
53
51
|
};
|
|
54
|
-
|
|
52
|
+
E(r);
|
|
55
53
|
},
|
|
56
|
-
[
|
|
54
|
+
[E, v, s, i]
|
|
57
55
|
),
|
|
58
|
-
logConversation:
|
|
56
|
+
logConversation: v
|
|
59
57
|
};
|
|
60
|
-
return /* @__PURE__ */
|
|
61
|
-
}, F = ({ children: t }) => /* @__PURE__ */
|
|
62
|
-
const t = B(
|
|
58
|
+
return /* @__PURE__ */ u(m.Provider, { value: x, children: t });
|
|
59
|
+
}, F = ({ children: t }) => /* @__PURE__ */ u(U, { children: /* @__PURE__ */ u(K, { children: t }) }), G = () => {
|
|
60
|
+
const t = B(m);
|
|
63
61
|
if (!t)
|
|
64
62
|
throw new Error("useChatEvents must be used within a ChatEventsProvider");
|
|
65
63
|
return t;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/cxkit-primitives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"remark-gfm": "^4.0.1",
|
|
60
60
|
"unist-util-visit": "^5.0.0",
|
|
61
61
|
"use-sync-external-store": "^1.4.0",
|
|
62
|
-
"@inkeep/cxkit-color-mode": "0.5.
|
|
63
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
64
|
-
"@inkeep/cxkit-types": "0.5.
|
|
62
|
+
"@inkeep/cxkit-color-mode": "0.5.50",
|
|
63
|
+
"@inkeep/cxkit-theme": "0.5.50",
|
|
64
|
+
"@inkeep/cxkit-types": "0.5.50"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "1.9.4",
|