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