@inkeep/cxkit-primitives 0.5.5 → 0.5.6
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,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("openai"),t=require("react"),qe=require("../../atoms/api/analytics/conversation.cjs"),Pe=require("../../providers/config-provider.cjs"),Ee=require("../../providers/conversation-provider.cjs"),_e=require("../../providers/chat-events-provider.cjs")
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("openai"),t=require("react"),qe=require("../../atoms/api/analytics/conversation.cjs"),Pe=require("../../providers/config-provider.cjs"),Ee=require("../../providers/conversation-provider.cjs"),_e=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),V=require("../../utils/misc.cjs"),X=require("../../utils/reset-query-params.cjs"),Ne=require("../../providers/chat-form-provider.cjs"),Re=require("../../providers/widget-provider.cjs"),Ae=require("../../hooks/use-media-query.cjs"),$e=require("./use-captcha.cjs"),De=require("../modal/modal-provider.cjs"),Le=()=>{const{chatId:m,setConversation:Y,conversation:Z,resetConversation:ee}=Ee.useInkeepConversation(),{baseSettings:k,aiChatSettings:L}=Pe.useInkeepConfig(),{aiApiBaseUrl:x,shouldBypassCaptcha:O}=k,U=De.useModal(),{getSolution:te,prefetchSolution:b,invalidateSolution:K}=$e.useCaptcha({fetchUrl:`${x}/v1/challenge`,shouldBypassCaptcha:O,shouldMakeInitialRequest:U?U.isOpen:!0}),se=new be({baseURL:`${x}/v1`,apiKey:k.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:ne,tools:oe,prompts:ae,model:re,onToolCall:ie}=L,[h,_]=t.useState(""),T=t.useRef(null);t.useEffect(()=>{ne?.(h)},[h]);const[u,l]=t.useState([]),[B,p]=t.useState(!1),[ce,f]=t.useState(!1),[le,F]=t.useState(null),[v,Q]=t.useState(null),[I,y]=t.useState([]),ue=e=>{y(n=>[...n,e])},[de,W]=t.useState({}),i=t.useRef([]),S=t.useRef(null),{logEvent:q}=_e.useChatEvents(),z=ae?.map((e,n)=>({id:`system-${Date.now().toString()}-${n}`,role:"system",content:e})),[ge,me]=t.useState(!!m);t.useEffect(()=>{if(m){const{apiKey:e,analyticsApiBaseUrl:n}=k;q({eventName:"chat_shared_session_loaded",properties:{conversationId:m}}),qe.getConversation(m,e,n).then(o=>{if(o){me(!1),Y({...o,id:""});const a=o.messages.map(c=>({id:Date.now().toString()+c.id,content:V.parseIfJson(c.content),role:c.role,links:c.links}));l(a),i.current=a}})}},[m]);const he=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${k.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.`}},H=e=>{F(e),l(n=>{const o=[...n],a=o[o.length-1];return a&&(a.content=he(e)),o}),p(!1),f(!1),K(),b()},N=!h.trim()&&!I.length||B,pe=e=>{e.key==="Enter"&&!e.shiftKey&&!N&&!e.nativeEvent.isComposing&&(e.preventDefault(),R())},fe=e=>{const n=e.target.value;_(n)},R=async(e=h)=>{if(N&&(!e||e.trim().length===0))return;p(!0);const n=v?u.length===2:u.length===0,o
|
|
4
|
-
${
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},H=e=>{F(e),l(n=>{const o=[...n],a=o[o.length-1];return a&&(a.content=he(e)),o}),p(!1),f(!1),K(),b()},N=!h.trim()&&!I.length||B,pe=e=>{e.key==="Enter"&&!e.shiftKey&&!N&&!e.nativeEvent.isComposing&&(e.preventDefault(),R())},fe=e=>{const n=e.target.value;_(n)},R=async(e=h)=>{if(N&&(!e||e.trim().length===0))return;p(!0);const n=v?u.length===2:u.length===0,o=D.getMessageMetadata(v,I,n);let a;const c=D.serializeAttachments(I);I.length&&c?a=[{type:"text",text:c}]:a=e;const P={id:`${Date.now().toString()}1`,role:"user",content:a,metadata:o},E=[...u.length?[]:z,P];m&&X.resetQueryParams(),l(w=>[...w,...E]),i.current=[...i.current,...E],y([]),_(""),q({eventName:"chat_message_submitted",properties:{messages:i.current,messageId:P.id,content:e,workflowId:v?.id}});try{const w={model:re,messages:i.current,stream:!0,tools:oe,tool_choice:"auto"},j=await te(),Ce=j?btoa(JSON.stringify(j)):null,G=O?void 0:{"X-INKEEP-CHALLENGE-SOLUTION":Ce},C=se.beta.chat.completions.stream(w,G?{headers:G}:void 0),s={id:`${Date.now().toString()}2`,role:"assistant",content:"",links:[]};l(d=>[...d,s]),C.on("content",(d,A)=>{f(!0),s.content=A,l($=>{const r=[...$],g=r.findIndex(M=>M.id===s.id);return g===-1?[...r,s]:(r[g]={...s},r)})}),C.on("tool_calls.function.arguments.done",d=>{const{name:A,arguments:$}=d;if(A==="provideLinks"){const r=JSON.parse($);r.links?.length>0&&(s.links=r.links,l(g=>{const M=[...g],Me=M.findIndex(ke=>ke.id===s.id);return M[Me]={...s},M}))}else{const r=ie?.(d);r&&W(g=>({...g,[s.id]:[...g[s.id]||[],r]}))}}),C.on("error",d=>{H(d)}),C.finalChatCompletion().then(()=>{i.current=[...i.current,s],S.current=null,p(!1),f(!1),b(),q({eventName:"chat_message_bot_response_received",properties:{messages:i.current,messageId:s.id,question:V.getMessageContent(P),responseMessage:s,linksUsedInResponse:s.links,workflowId:v?.id}})}),S.current=C.controller}catch(w){H(w),p(!1),f(!1)}},ve=()=>{S.current&&(S.current.abort(),S.current=null),p(!1),f(!1),b()},J=()=>{F(null),l([]),i.current=[],ee(),W({}),y([]),X.resetQueryParams(),Q(null),K(),b(),q({eventName:"chat_history_cleared",properties:{conversationId:Z.id}})},Ie=e=>{Q(e);const{initialReplyMessage:n,displayName:o}=e,a={id:u.length.toString(),role:"user",content:o},c={id:(u.length+1).toString(),role:"assistant",content:n,links:[]},E=[{id:`system-${Date.now().toString()}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
|
+
${D.serializeWorkflow(e)}`},...z,a,c];l(E),y([])},{openForm:ye}=Ne.useChatForm(),Se=Re.useWidget();t.useImperativeHandle(L.chatFunctionsRef,()=>({submitMessage:R,updateInputMessage(e){_(e)},clearChat:J,openForm:e=>{Se?.setView("chat"),ye(e)},focusInput:()=>{T.current?.focus()}}));const we=Ae.useMediaQuery("(max-width: 768px)");return{messages:u,input:h,isLoading:B,isStreaming:ce,isLoadingConversation:ge,error:le,isSubmitDisabled:N,handleInputChange:fe,handleInputKeyDown:pe,handleSubmit:R,stop:ve,clear:J,handleWorkflow:Ie,selectedWorkflow:v,messageAttachments:I,setMessageAttachments:y,addAttachment:ue,messageToolCalls:de,isEmpty:u.length===0,inputRef:T,isMobile:we}};exports.useInkeepChat=Le;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import be from "openai";
|
|
3
|
-
import { useState as c, useRef as
|
|
3
|
+
import { useState as c, useRef as R, useEffect as X, useImperativeHandle as _e } from "react";
|
|
4
4
|
import { getConversation as Ee } from "../../atoms/api/analytics/conversation.js";
|
|
5
5
|
import { useInkeepConfig as Ne } from "../../providers/config-provider.js";
|
|
6
6
|
import { useInkeepConversation as Ae } from "../../providers/conversation-provider.js";
|
|
7
|
-
import { useChatEvents as
|
|
8
|
-
import { getMessageMetadata as
|
|
9
|
-
import { parseIfJson as
|
|
7
|
+
import { useChatEvents as $e } from "../../providers/chat-events-provider.js";
|
|
8
|
+
import { getMessageMetadata as xe, serializeAttachments as De, serializeWorkflow as Le } from "../../utils/get-message-metadata.js";
|
|
9
|
+
import { parseIfJson as Re, getMessageContent as Pe } from "../../utils/misc.js";
|
|
10
10
|
import { resetQueryParams as j } from "../../utils/reset-query-params.js";
|
|
11
11
|
import { useChatForm as Ue } from "../../providers/chat-form-provider.js";
|
|
12
12
|
import { useWidget as Ke } from "../../providers/widget-provider.js";
|
|
@@ -22,14 +22,14 @@ const tt = () => {
|
|
|
22
22
|
baseURL: `${U}/v1`,
|
|
23
23
|
apiKey: S.apiKey,
|
|
24
24
|
dangerouslyAllowBrowser: !0
|
|
25
|
-
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } = P, [p, A] = c(""), T =
|
|
25
|
+
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } = P, [p, A] = c(""), T = R(null);
|
|
26
26
|
X(() => {
|
|
27
27
|
ne?.(p);
|
|
28
28
|
}, [p]);
|
|
29
29
|
const [u, l] = c([]), [W, f] = c(!1), [ce, h] = c(!1), [le, F] = c(null), [I, z] = c(null), [w, y] = c([]), ue = (e) => {
|
|
30
30
|
y((s) => [...s, e]);
|
|
31
|
-
}, [me, H] = c({}), r =
|
|
32
|
-
id: `system-${s}`,
|
|
31
|
+
}, [me, H] = c({}), r = R([]), C = R(null), { logEvent: _ } = $e(), J = ae?.map((e, s) => ({
|
|
32
|
+
id: `system-${Date.now().toString()}-${s}`,
|
|
33
33
|
role: "system",
|
|
34
34
|
content: e
|
|
35
35
|
})), [de, ge] = c(!!g);
|
|
@@ -46,7 +46,7 @@ const tt = () => {
|
|
|
46
46
|
ge(!1), Y({ ...n, id: "" });
|
|
47
47
|
const o = n.messages.map((i) => ({
|
|
48
48
|
id: Date.now().toString() + i.id,
|
|
49
|
-
content:
|
|
49
|
+
content: Re(i.content),
|
|
50
50
|
role: i.role,
|
|
51
51
|
links: i.links
|
|
52
52
|
}));
|
|
@@ -71,17 +71,17 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
71
71
|
const n = [...s], o = n[n.length - 1];
|
|
72
72
|
return o && (o.content = pe(e)), n;
|
|
73
73
|
}), f(!1), h(!1), B(), b();
|
|
74
|
-
},
|
|
75
|
-
e.key === "Enter" && !e.shiftKey &&
|
|
74
|
+
}, $ = !p.trim() && !w.length || W, fe = (e) => {
|
|
75
|
+
e.key === "Enter" && !e.shiftKey && !$ && !e.nativeEvent.isComposing && (e.preventDefault(), x());
|
|
76
76
|
}, he = (e) => {
|
|
77
77
|
const s = e.target.value;
|
|
78
78
|
A(s);
|
|
79
|
-
},
|
|
80
|
-
if (
|
|
79
|
+
}, x = async (e = p) => {
|
|
80
|
+
if ($ && (!e || e.trim().length === 0)) return;
|
|
81
81
|
f(!0);
|
|
82
|
-
const s = I ? u.length === 2 : u.length === 0, n =
|
|
82
|
+
const s = I ? u.length === 2 : u.length === 0, n = xe(I, w, s);
|
|
83
83
|
let o;
|
|
84
|
-
const i =
|
|
84
|
+
const i = De(w);
|
|
85
85
|
w.length && i ? o = [{ type: "text", text: i }] : o = e;
|
|
86
86
|
const E = {
|
|
87
87
|
id: `${Date.now().toString()}1`,
|
|
@@ -116,15 +116,15 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
116
116
|
content: "",
|
|
117
117
|
links: []
|
|
118
118
|
};
|
|
119
|
-
l((m) => [...m, t]), M.on("content", (m,
|
|
120
|
-
h(!0), t.content =
|
|
121
|
-
const a = [
|
|
119
|
+
l((m) => [...m, t]), M.on("content", (m, D) => {
|
|
120
|
+
h(!0), t.content = D, l((L) => {
|
|
121
|
+
const a = [...L], d = a.findIndex((k) => k.id === t.id);
|
|
122
122
|
return d === -1 ? [...a, t] : (a[d] = { ...t }, a);
|
|
123
123
|
});
|
|
124
124
|
}), M.on("tool_calls.function.arguments.done", (m) => {
|
|
125
|
-
const { name:
|
|
126
|
-
if (
|
|
127
|
-
const a = JSON.parse(
|
|
125
|
+
const { name: D, arguments: L } = m;
|
|
126
|
+
if (D === "provideLinks") {
|
|
127
|
+
const a = JSON.parse(L);
|
|
128
128
|
a.links?.length > 0 && (t.links = a.links, l((d) => {
|
|
129
129
|
const k = [...d], ke = k.findIndex((Se) => Se.id === t.id);
|
|
130
130
|
return k[ke] = { ...t }, k;
|
|
@@ -175,17 +175,17 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
175
175
|
content: s,
|
|
176
176
|
links: []
|
|
177
177
|
}, N = [{
|
|
178
|
-
id: `system-${e.id}`,
|
|
178
|
+
id: `system-${Date.now().toString()}-${e.id}`,
|
|
179
179
|
role: "system",
|
|
180
180
|
content: `Company has asked user to follow this guided workflow:
|
|
181
|
-
${
|
|
181
|
+
${Le(
|
|
182
182
|
e
|
|
183
183
|
)}`
|
|
184
184
|
}, ...J, o, i];
|
|
185
185
|
l(N), y([]);
|
|
186
186
|
}, { openForm: ye } = Ue(), Ce = Ke();
|
|
187
187
|
_e(P.chatFunctionsRef, () => ({
|
|
188
|
-
submitMessage:
|
|
188
|
+
submitMessage: x,
|
|
189
189
|
updateInputMessage(e) {
|
|
190
190
|
A(e);
|
|
191
191
|
},
|
|
@@ -205,10 +205,10 @@ ${$e(
|
|
|
205
205
|
isStreaming: ce,
|
|
206
206
|
isLoadingConversation: de,
|
|
207
207
|
error: le,
|
|
208
|
-
isSubmitDisabled:
|
|
208
|
+
isSubmitDisabled: $,
|
|
209
209
|
handleInputChange: he,
|
|
210
210
|
handleInputKeyDown: fe,
|
|
211
|
-
handleSubmit:
|
|
211
|
+
handleSubmit: x,
|
|
212
212
|
stop: Ie,
|
|
213
213
|
clear: Q,
|
|
214
214
|
handleWorkflow: we,
|
|
@@ -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"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=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"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=t.useMemo(()=>({widgetLibraryVersion:"0.5.6",componentType:n,tags:i}),[n,i]),u=!d.optOutAllAnalytics&&E!=="development",g={logEvent:t.useCallback(async v=>{const m={...a,...v.properties},l={eventName:v.eventName,properties:m,userProperties:c};u&&y.logEvent(l,o,r),s.onEvent?.(l)},[u,s,o,r,c,a])};return P.jsx(p.Provider,{value:g,children:e})},x=()=>{const e=t.useContext(p);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=f;exports.useBaseEvents=x;
|
|
@@ -7,7 +7,7 @@ import { useUser as b } from "./user-provider.js";
|
|
|
7
7
|
const m = x(void 0), U = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: o } = C(), { apiKey: n, analyticsApiBaseUrl: s, tags: r, privacyPreferences: u, env: l } = t, { userProperties: i } = b(), a = d(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.6",
|
|
11
11
|
componentType: o,
|
|
12
12
|
tags: r
|
|
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.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"react-textarea-autosize": "8.5.7",
|
|
54
54
|
"rehype-raw": "7.0.0",
|
|
55
55
|
"unist-util-visit": "^5.0.0",
|
|
56
|
-
"@inkeep/cxkit-color-mode": "0.5.
|
|
57
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
58
|
-
"@inkeep/cxkit-types": "0.5.
|
|
56
|
+
"@inkeep/cxkit-color-mode": "0.5.6",
|
|
57
|
+
"@inkeep/cxkit-theme": "0.5.6",
|
|
58
|
+
"@inkeep/cxkit-types": "0.5.6"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@biomejs/biome": "1.9.4",
|