@inkeep/cxkit-primitives 0.5.117 → 0.5.119
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.
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("openai"),t=require("react"),Oe=require("../../providers/config-provider.cjs"),De=require("../../providers/conversation-provider.cjs"),Fe=require("../../providers/chat-events-provider.cjs"),K=require("../../utils/get-message-metadata.cjs"),le=require("../../utils/reset-query-params.cjs"),Te=require("../../providers/chat-form-provider.cjs"),Ke=require("../../providers/widget-provider.cjs"),Qe=require("../../hooks/use-media-query.cjs"),We=require("./use-captcha.cjs"),Je=require("../modal/modal-provider.cjs"),d=require("../../utils/generate-uid.cjs"),ze=require("../../utils/tools/links-tool.cjs"),He=require("../../atoms/api/analytics/conversation.cjs"),je=require("../../utils/misc.cjs"),Ge=()=>{const{chatId:S,isSharedChat:ue,setConversation:ge,conversation:de,resetConversation:me}=De.useInkeepConversation(),{baseSettings:
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("openai"),t=require("react"),Oe=require("../../providers/config-provider.cjs"),De=require("../../providers/conversation-provider.cjs"),Fe=require("../../providers/chat-events-provider.cjs"),K=require("../../utils/get-message-metadata.cjs"),le=require("../../utils/reset-query-params.cjs"),Te=require("../../providers/chat-form-provider.cjs"),Ke=require("../../providers/widget-provider.cjs"),Qe=require("../../hooks/use-media-query.cjs"),We=require("./use-captcha.cjs"),Je=require("../modal/modal-provider.cjs"),d=require("../../utils/generate-uid.cjs"),ze=require("../../utils/tools/links-tool.cjs"),He=require("../../atoms/api/analytics/conversation.cjs"),je=require("../../utils/misc.cjs"),Ge=()=>{const{chatId:S,isSharedChat:ue,setConversation:ge,conversation:de,resetConversation:me}=De.useInkeepConversation(),{baseSettings:q,aiChatSettings:Q}=Oe.useInkeepConfig(),{aiApiBaseUrl:W,shouldBypassCaptcha:J,filters:z}=q,H=Je.useModal(),{getSolution:pe,prefetchSolution:E,invalidateSolution:j}=We.useCaptcha({fetchUrl:`${W}/v1/challenge`,shouldBypassCaptcha:J,shouldMakeInitialRequest:H?H.isOpen:!0}),fe=new ce({baseURL:`${W}/v1`,apiKey:q.apiKey??"",dangerouslyAllowBrowser:!0}),{onInputMessageChange:he,getTools:ve,prompts:ye,model:Se,filters:G,onToolCall:we}=Q,[w,x]=t.useState(""),V=t.useRef(null);t.useEffect(()=>{he?.(w)},[w]);const[m,l]=t.useState([]),[X,C]=t.useState(!1),[Ce,M]=t.useState(!1),[Me,Y]=t.useState(null),[B,Z]=t.useState(null),[I,b]=t.useState([]),Ie=e=>{b(s=>[...s,e])},[be,ee]=t.useState({}),o=t.useRef([]),k=t.useRef(null),{logEvent:_,getLatestConversation:te}=Fe.useChatEvents(),se=ye?.map((e,s)=>({id:`system-${Date.now().toString()}-${d.generateUid(4)}-${s}`,role:"system",content:e})),[ke,_e]=t.useState(!!S);t.useEffect(()=>{if(S){const{apiKey:e,analyticsApiBaseUrl:s}=q;He.getConversation(S,e,s).then(a=>{if(a){_({eventName:"shared_chat_loaded",properties:{conversation:a}}),_e(!1),ge({...a});const r=a.messages.map(p=>({...p,content:je.parseIfJson(p.content)}));l(r),o.current=r}})}},[S]);const $e=e=>e.status===403||e.status===401?`There seems to be a configuration error. Please contact ${q.organizationDisplayName??"Administrator"}.`:e.error?.message?`${e.error.message}
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Please clear the chat and try again.`:`Hmm..
|
|
4
|
+
|
|
5
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ne=e=>{Y(e),l(s=>{const a=[...s],r=a[a.length-1];return r&&(r.content=$e(e)),a}),C(!1),M(!1),j(),E()},R=!w.trim()&&!I.length||X,Pe=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),O())},qe=e=>{const s=e.target.value;x(s)},O=async(e=w)=>{if(R&&(!e||e.trim().length===0))return;C(!0);const s=B?m.length===2:m.length===0,a=K.getMessageMetadata(B,I,s);let r;const p=K.serializeAttachments(I);I.length&&p?r=[{type:"text",text:p}]:r=e;const ae={id:`${Date.now().toString()}-${d.generateUid(4)}-1`,role:"user",content:r,metadata:a},f=[...m.length?[]:se,ae];if(ue&&S){le.resetQueryParams();const u=o.current.map((i,U)=>({id:`${i.id}-${d.generateUid(6)}-${U}`,role:i.role,...i.role==="assistant"?{links:i.links??[]}:{},content:i.content,metadata:i.metadata,tool_calls:i.tool_calls}));l([...u,...f]),o.current=[...u,...f]}else l(u=>[...u,...f]),o.current=[...o.current,...f];b([]),x(""),_({eventName:"user_message_submitted",properties:{}},o.current);const xe=te(),re=[ze.provideLinksTool,...ve?.({conversation:xe})||[]];try{const u={model:Se,messages:o.current,stream:!0,tools:re,tool_choice:"auto"},i=await pe(),U=i?btoa(JSON.stringify(i)):null,ie=z||G?JSON.stringify({...z,...G}):void 0,N={};!J&&U&&(N["X-INKEEP-CHALLENGE-SOLUTION"]=U),ie&&(N["inkeep-filters"]=ie);const h=fe.beta.chat.completions.stream(u,Object.keys(N).length>0?{headers:N}:void 0),n={id:`${Date.now().toString()}-${d.generateUid(4)}-2`,role:"assistant",content:"",links:[],tool_calls:[]};l(g=>[...g,n]),h.on("content",(g,$)=>{M(!0),n.content=$,l(A=>{const c=[...A],D=c.findIndex(P=>P.id===n.id);return D===-1?[...c,n]:(c[D]={...n},c)})}),h.on("tool_calls.function.arguments.done",async g=>{const{name:$,arguments:A}=g,c=re?.find(v=>v.function.name===$);if(!c)return;const P=("parse"in c.function?c.function.parse:JSON.parse)(A),Be=c.function.function?.(P,h);if($==="provideLinks")n.links=P.links??[];else{const v=c.renderMessageButtons?.({args:P,execution:Be})??[];v.length>0&&ee(y=>{const L=y[n.id]??[],F=new Set(L.map(T=>T.label)),Re=v.filter(T=>!F.has(T.label));return{...y,[n.id]:[...L,...Re]}})}n.tool_calls?.push({id:"call_"+d.generateUid(24),type:"function",function:{name:$,arguments:A}}),l(v=>{const y=[...v],L=y.findIndex(F=>F.id===n.id);return y[L]={...n},y}),we?.(g,{conversation:{...te(),messages:[...o.current,n]}})}),h.on("error",ne),h.finalChatCompletion().then(async()=>{o.current=[...o.current,n],k.current=null,C(!1),M(!1),E(),await _({eventName:"assistant_message_received",properties:{}},o.current),_({eventName:"assistant_answer_displayed",properties:{}})}).catch(g=>{g instanceof ce.APIUserAbortError||console.warn(g)}),k.current=h.controller}catch(u){ne(u),C(!1),M(!1)}},Ee=()=>{k.current&&(k.current.abort(),k.current=null),C(!1),M(!1),E()},oe=()=>{Y(null),l([]),o.current=[],me(),ee({}),b([]),le.resetQueryParams(),Z(null),j(),E(),_({eventName:"chat_clear_button_clicked",properties:{conversation:de}})},Ue=e=>{Z(e);const{initialReplyMessage:s,displayName:a}=e,r={id:m.length.toString()+d.generateUid(4),role:"user",content:a},p={id:(m.length+1).toString()+d.generateUid(4),role:"assistant",content:s,links:[]},f=[{id:`system-${Date.now().toString()}-${d.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
6
|
+
${K.serializeWorkflow(e)}`},...se,r,p];l(f),b([])},{openForm:Ne}=Te.useChatForm(),Ae=Ke.useWidget();t.useImperativeHandle(Q.chatFunctionsRef,()=>({submitMessage:O,updateInputMessage(e){x(e)},clearChat:oe,openForm:e=>{Ae?.setView("chat"),Ne(e)},focusInput:()=>{V.current?.focus()}}));const Le=Qe.useMediaQuery("(max-width: 768px)");return{messages:m,input:w,isLoading:X,isStreaming:Ce,isLoadingConversation:ke,error:Me,isSubmitDisabled:R,handleInputChange:qe,handleInputKeyDown:Pe,handleSubmit:O,stop:Ee,clear:oe,handleWorkflow:Ue,selectedWorkflow:B,messageAttachments:I,setMessageAttachments:b,addAttachment:Ie,messageButtons:be,isEmpty:m.length===0,inputRef:V,isMobile:Le}};exports.useInkeepChat=Ge;
|
|
@@ -31,11 +31,11 @@ const yt = () => {
|
|
|
31
31
|
model: we,
|
|
32
32
|
filters: G,
|
|
33
33
|
onToolCall: Ce
|
|
34
|
-
} = J, [C,
|
|
34
|
+
} = J, [C, D] = l(""), V = W(null);
|
|
35
35
|
ce(() => {
|
|
36
36
|
he?.(C);
|
|
37
37
|
}, [C]);
|
|
38
|
-
const [p, c] = l([]), [X, I] = l(!1), [Ie, M] = l(!1), [Me, Y] = l(null), [
|
|
38
|
+
const [p, c] = l([]), [X, I] = l(!1), [Ie, M] = l(!1), [Me, Y] = l(null), [O, Z] = l(null), [S, b] = l([]), Se = (e) => {
|
|
39
39
|
b((t) => [...t, e]);
|
|
40
40
|
}, [be, ee] = l({}), n = W([]), k = W(null), { logEvent: _, getLatestConversation: te } = Je(), se = ve?.map((e, t) => ({
|
|
41
41
|
id: `system-${Date.now().toString()}-${g(4)}-${t}`,
|
|
@@ -62,18 +62,11 @@ const yt = () => {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
}, [w]);
|
|
65
|
-
const $e = (e) => {
|
|
66
|
-
switch (e.code) {
|
|
67
|
-
case 400:
|
|
68
|
-
return e.message;
|
|
69
|
-
case 403:
|
|
70
|
-
return `There seems to be a configuration error. Please contact ${N.organizationDisplayName ?? "Administrator"}`;
|
|
71
|
-
default:
|
|
72
|
-
return `Hmm..
|
|
65
|
+
const $e = (e) => e.status === 403 || e.status === 401 ? `There seems to be a configuration error. Please contact ${N.organizationDisplayName ?? "Administrator"}.` : e.error?.message ? `${e.error.message}
|
|
73
66
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
Please clear the chat and try again.` : `Hmm..
|
|
68
|
+
|
|
69
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, ne = (e) => {
|
|
77
70
|
Y(e), c((t) => {
|
|
78
71
|
const o = [...t], a = o[o.length - 1];
|
|
79
72
|
return a && (a.content = $e(e)), o;
|
|
@@ -82,11 +75,11 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
82
75
|
e.key === "Enter" && !e.shiftKey && !R && !e.nativeEvent.isComposing && (e.preventDefault(), U());
|
|
83
76
|
}, Ne = (e) => {
|
|
84
77
|
const t = e.target.value;
|
|
85
|
-
|
|
78
|
+
D(t);
|
|
86
79
|
}, U = async (e = C) => {
|
|
87
80
|
if (R && (!e || e.trim().length === 0)) return;
|
|
88
81
|
I(!0);
|
|
89
|
-
const t =
|
|
82
|
+
const t = O ? p.length === 2 : p.length === 0, o = ze(O, S, t);
|
|
90
83
|
let a;
|
|
91
84
|
const d = He(S);
|
|
92
85
|
S.length && d ? a = [{ type: "text", text: d }] : a = e;
|
|
@@ -109,14 +102,14 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
109
102
|
c([...u, ...f]), n.current = [...u, ...f];
|
|
110
103
|
} else
|
|
111
104
|
c((u) => [...u, ...f]), n.current = [...n.current, ...f];
|
|
112
|
-
b([]),
|
|
105
|
+
b([]), D(""), _(
|
|
113
106
|
{
|
|
114
107
|
eventName: "user_message_submitted",
|
|
115
108
|
properties: {}
|
|
116
109
|
},
|
|
117
110
|
n.current
|
|
118
111
|
);
|
|
119
|
-
const
|
|
112
|
+
const De = te(), re = [Ye, ...ye?.({ conversation: De }) || []];
|
|
120
113
|
try {
|
|
121
114
|
const u = {
|
|
122
115
|
model: we,
|
|
@@ -147,16 +140,16 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
147
140
|
}), h.on("tool_calls.function.arguments.done", async (m) => {
|
|
148
141
|
const { name: $, arguments: B } = m, i = re?.find((y) => y.function.name === $);
|
|
149
142
|
if (!i) return;
|
|
150
|
-
const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B),
|
|
143
|
+
const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B), Oe = i.function.function?.(E, h);
|
|
151
144
|
if ($ === "provideLinks")
|
|
152
145
|
s.links = E.links ?? [];
|
|
153
146
|
else {
|
|
154
|
-
const y = i.renderMessageButtons?.({ args: E, execution:
|
|
147
|
+
const y = i.renderMessageButtons?.({ args: E, execution: Oe }) ?? [];
|
|
155
148
|
y.length > 0 && ee((v) => {
|
|
156
|
-
const
|
|
149
|
+
const P = v[s.id] ?? [], K = new Set(P.map((T) => T.label)), Re = y.filter((T) => !K.has(T.label));
|
|
157
150
|
return {
|
|
158
151
|
...v,
|
|
159
|
-
[s.id]: [...
|
|
152
|
+
[s.id]: [...P, ...Re]
|
|
160
153
|
};
|
|
161
154
|
});
|
|
162
155
|
}
|
|
@@ -168,8 +161,8 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
168
161
|
arguments: B
|
|
169
162
|
}
|
|
170
163
|
}), c((y) => {
|
|
171
|
-
const v = [...y],
|
|
172
|
-
return v[
|
|
164
|
+
const v = [...y], P = v.findIndex((K) => K.id === s.id);
|
|
165
|
+
return v[P] = { ...s }, v;
|
|
173
166
|
}), Ce?.(m, {
|
|
174
167
|
conversation: {
|
|
175
168
|
...te(),
|
|
@@ -224,7 +217,7 @@ ${Qe(e)}`
|
|
|
224
217
|
Ke(J.chatFunctionsRef, () => ({
|
|
225
218
|
submitMessage: U,
|
|
226
219
|
updateInputMessage(e) {
|
|
227
|
-
|
|
220
|
+
D(e);
|
|
228
221
|
},
|
|
229
222
|
clearChat: oe,
|
|
230
223
|
openForm: (e) => {
|
|
@@ -234,7 +227,7 @@ ${Qe(e)}`
|
|
|
234
227
|
V.current?.focus();
|
|
235
228
|
}
|
|
236
229
|
}));
|
|
237
|
-
const
|
|
230
|
+
const Pe = Ge("(max-width: 768px)");
|
|
238
231
|
return {
|
|
239
232
|
messages: p,
|
|
240
233
|
input: C,
|
|
@@ -249,14 +242,14 @@ ${Qe(e)}`
|
|
|
249
242
|
stop: Ae,
|
|
250
243
|
clear: oe,
|
|
251
244
|
handleWorkflow: xe,
|
|
252
|
-
selectedWorkflow:
|
|
245
|
+
selectedWorkflow: O,
|
|
253
246
|
messageAttachments: S,
|
|
254
247
|
setMessageAttachments: b,
|
|
255
248
|
addAttachment: Se,
|
|
256
249
|
messageButtons: be,
|
|
257
250
|
isEmpty: p.length === 0,
|
|
258
251
|
inputRef: V,
|
|
259
|
-
isMobile:
|
|
252
|
+
isMobile: Pe
|
|
260
253
|
};
|
|
261
254
|
};
|
|
262
255
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.119",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
|
|
@@ -7,7 +7,7 @@ import { useUser as A } from "./user-provider.js";
|
|
|
7
7
|
const u = B(void 0), $ = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: s } = w(), { apiKey: r, analyticsApiBaseUrl: i, tags: a, privacyPreferences: d, env: E, analyticsProperties: c } = t, { userProperties: v } = A(), p = P(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.119",
|
|
11
11
|
componentType: s,
|
|
12
12
|
tags: a
|
|
13
13
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/cxkit-primitives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.119",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"remark-gfm": "^4.0.1",
|
|
69
69
|
"unist-util-visit": "^5.0.0",
|
|
70
70
|
"use-sync-external-store": "^1.4.0",
|
|
71
|
-
"@inkeep/cxkit-color-mode": "^0.5.
|
|
72
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
73
|
-
"@inkeep/cxkit-types": "0.5.
|
|
71
|
+
"@inkeep/cxkit-color-mode": "^0.5.119",
|
|
72
|
+
"@inkeep/cxkit-theme": "0.5.119",
|
|
73
|
+
"@inkeep/cxkit-types": "0.5.119"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@biomejs/biome": "1.9.4",
|