@inkeep/cxkit-primitives 0.5.118 → 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:P,aiChatSettings:Q}=Oe.useInkeepConfig(),{aiApiBaseUrl:W,shouldBypassCaptcha:J,filters:z}=P,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:P.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}=P;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 ${P.organizationDisplayName??"Administrator"}.`:e.error?.message??`Hmm..
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
- 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,qe=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),O())},Pe=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(q=>q.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 q=("parse"in c.function?c.function.parse:JSON.parse)(A),Be=c.function.function?.(q,h);if($==="provideLinks")n.links=q.links??[];else{const v=c.renderMessageButtons?.({args:q,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:
4
- ${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:Pe,handleInputKeyDown:qe,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;
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;
@@ -1,94 +1,96 @@
1
1
  "use client";
2
- import Ut, { APIUserAbortError as Ft } from "openai";
3
- import { useState as l, useRef as W, useEffect as ct, useImperativeHandle as Kt } from "react";
4
- import { useInkeepConfig as Tt } from "../../providers/config-provider.js";
5
- import { useInkeepConversation as Wt } from "../../providers/conversation-provider.js";
6
- import { useChatEvents as Jt } from "../../providers/chat-events-provider.js";
7
- import { getMessageMetadata as zt, serializeAttachments as Ht, serializeWorkflow as Qt } from "../../utils/get-message-metadata.js";
8
- import { resetQueryParams as lt } from "../../utils/reset-query-params.js";
9
- import { useChatForm as jt } from "../../providers/chat-form-provider.js";
10
- import { useWidget as qt } from "../../providers/widget-provider.js";
11
- import { useMediaQuery as Gt } from "../../hooks/use-media-query.js";
12
- import { useCaptcha as Vt } from "./use-captcha.js";
13
- import { useModal as Xt } from "../modal/modal-provider.js";
2
+ import Ue, { APIUserAbortError as Fe } from "openai";
3
+ import { useState as l, useRef as W, useEffect as ce, useImperativeHandle as Ke } from "react";
4
+ import { useInkeepConfig as Te } from "../../providers/config-provider.js";
5
+ import { useInkeepConversation as We } from "../../providers/conversation-provider.js";
6
+ import { useChatEvents as Je } from "../../providers/chat-events-provider.js";
7
+ import { getMessageMetadata as ze, serializeAttachments as He, serializeWorkflow as Qe } from "../../utils/get-message-metadata.js";
8
+ import { resetQueryParams as le } from "../../utils/reset-query-params.js";
9
+ import { useChatForm as je } from "../../providers/chat-form-provider.js";
10
+ import { useWidget as qe } from "../../providers/widget-provider.js";
11
+ import { useMediaQuery as Ge } from "../../hooks/use-media-query.js";
12
+ import { useCaptcha as Ve } from "./use-captcha.js";
13
+ import { useModal as Xe } from "../modal/modal-provider.js";
14
14
  import { generateUid as g } from "../../utils/generate-uid.js";
15
- import { provideLinksTool as Yt } from "../../utils/tools/links-tool.js";
16
- import { getConversation as Zt } from "../../atoms/api/analytics/conversation.js";
17
- import { parseIfJson as te } from "../../utils/misc.js";
18
- const ye = () => {
19
- const { chatId: w, isSharedChat: ut, setConversation: mt, conversation: gt, resetConversation: pt } = Wt(), { baseSettings: N, aiChatSettings: J } = Tt(), { aiApiBaseUrl: z, shouldBypassCaptcha: H, filters: Q } = N, j = Xt(), { getSolution: dt, prefetchSolution: A, invalidateSolution: q } = Vt({
15
+ import { provideLinksTool as Ye } from "../../utils/tools/links-tool.js";
16
+ import { getConversation as Ze } from "../../atoms/api/analytics/conversation.js";
17
+ import { parseIfJson as et } from "../../utils/misc.js";
18
+ const yt = () => {
19
+ const { chatId: w, isSharedChat: ue, setConversation: me, conversation: ge, resetConversation: pe } = We(), { baseSettings: N, aiChatSettings: J } = Te(), { aiApiBaseUrl: z, shouldBypassCaptcha: H, filters: Q } = N, j = Xe(), { getSolution: de, prefetchSolution: A, invalidateSolution: q } = Ve({
20
20
  fetchUrl: `${z}/v1/challenge`,
21
21
  shouldBypassCaptcha: H,
22
22
  shouldMakeInitialRequest: j ? j.isOpen : !0
23
- }), ft = new Ut({
23
+ }), fe = new Ue({
24
24
  baseURL: `${z}/v1`,
25
25
  apiKey: N.apiKey ?? "",
26
26
  dangerouslyAllowBrowser: !0
27
27
  }), {
28
- onInputMessageChange: ht,
29
- getTools: yt,
30
- prompts: vt,
31
- model: wt,
28
+ onInputMessageChange: he,
29
+ getTools: ye,
30
+ prompts: ve,
31
+ model: we,
32
32
  filters: G,
33
- onToolCall: Ct
34
- } = J, [C, O] = l(""), V = W(null);
35
- ct(() => {
36
- ht?.(C);
33
+ onToolCall: Ce
34
+ } = J, [C, D] = l(""), V = W(null);
35
+ ce(() => {
36
+ he?.(C);
37
37
  }, [C]);
38
- const [p, c] = l([]), [X, I] = l(!1), [It, M] = l(!1), [Mt, Y] = l(null), [P, Z] = l(null), [S, b] = l([]), St = (t) => {
39
- b((e) => [...e, t]);
40
- }, [bt, tt] = l({}), n = W([]), k = W(null), { logEvent: _, getLatestConversation: et } = Jt(), st = vt?.map((t, e) => ({
41
- id: `system-${Date.now().toString()}-${g(4)}-${e}`,
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
+ b((t) => [...t, e]);
40
+ }, [be, ee] = l({}), n = W([]), k = W(null), { logEvent: _, getLatestConversation: te } = Je(), se = ve?.map((e, t) => ({
41
+ id: `system-${Date.now().toString()}-${g(4)}-${t}`,
42
42
  role: "system",
43
- content: t
44
- })), [kt, _t] = l(!!w);
45
- ct(() => {
43
+ content: e
44
+ })), [ke, _e] = l(!!w);
45
+ ce(() => {
46
46
  if (w) {
47
- const { apiKey: t, analyticsApiBaseUrl: e } = N;
48
- Zt(w, t, e).then((o) => {
47
+ const { apiKey: e, analyticsApiBaseUrl: t } = N;
48
+ Ze(w, e, t).then((o) => {
49
49
  if (o) {
50
50
  _({
51
51
  eventName: "shared_chat_loaded",
52
52
  properties: {
53
53
  conversation: o
54
54
  }
55
- }), _t(!1), mt({ ...o });
55
+ }), _e(!1), me({ ...o });
56
56
  const a = o.messages.map((d) => ({
57
57
  ...d,
58
- content: te(d.content)
58
+ content: et(d.content)
59
59
  }));
60
60
  c(a), n.current = a;
61
61
  }
62
62
  });
63
63
  }
64
64
  }, [w]);
65
- const $t = (t) => t.status === 403 || t.status === 401 ? `There seems to be a configuration error. Please contact ${N.organizationDisplayName ?? "Administrator"}.` : t.error?.message ?? `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}
66
66
 
67
- It seems I might be having some issues right now. Please clear the chat and try again.`, nt = (t) => {
68
- Y(t), c((e) => {
69
- const o = [...e], a = o[o.length - 1];
70
- return a && (a.content = $t(t)), o;
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) => {
70
+ Y(e), c((t) => {
71
+ const o = [...t], a = o[o.length - 1];
72
+ return a && (a.content = $e(e)), o;
71
73
  }), I(!1), M(!1), q(), A();
72
- }, R = !C.trim() && !S.length || X, Et = (t) => {
73
- t.key === "Enter" && !t.shiftKey && !R && !t.nativeEvent.isComposing && (t.preventDefault(), U());
74
- }, Nt = (t) => {
75
- const e = t.target.value;
76
- O(e);
77
- }, U = async (t = C) => {
78
- if (R && (!t || t.trim().length === 0)) return;
74
+ }, R = !C.trim() && !S.length || X, Ee = (e) => {
75
+ e.key === "Enter" && !e.shiftKey && !R && !e.nativeEvent.isComposing && (e.preventDefault(), U());
76
+ }, Ne = (e) => {
77
+ const t = e.target.value;
78
+ D(t);
79
+ }, U = async (e = C) => {
80
+ if (R && (!e || e.trim().length === 0)) return;
79
81
  I(!0);
80
- const e = P ? p.length === 2 : p.length === 0, o = zt(P, S, e);
82
+ const t = O ? p.length === 2 : p.length === 0, o = ze(O, S, t);
81
83
  let a;
82
- const d = Ht(S);
83
- S.length && d ? a = [{ type: "text", text: d }] : a = t;
84
- const at = {
84
+ const d = He(S);
85
+ S.length && d ? a = [{ type: "text", text: d }] : a = e;
86
+ const ae = {
85
87
  id: `${Date.now().toString()}-${g(4)}-1`,
86
88
  role: "user",
87
89
  content: a,
88
90
  metadata: o
89
- }, f = [...p.length ? [] : st, at];
90
- if (ut && w) {
91
- lt();
91
+ }, f = [...p.length ? [] : se, ae];
92
+ if (ue && w) {
93
+ le();
92
94
  const u = n.current.map((r, x) => ({
93
95
  id: `${r.id}-${g(6)}-${x}`,
94
96
  role: r.role,
@@ -100,27 +102,27 @@ It seems I might be having some issues right now. Please clear the chat and try
100
102
  c([...u, ...f]), n.current = [...u, ...f];
101
103
  } else
102
104
  c((u) => [...u, ...f]), n.current = [...n.current, ...f];
103
- b([]), O(""), _(
105
+ b([]), D(""), _(
104
106
  {
105
107
  eventName: "user_message_submitted",
106
108
  properties: {}
107
109
  },
108
110
  n.current
109
111
  );
110
- const Ot = et(), rt = [Yt, ...yt?.({ conversation: Ot }) || []];
112
+ const De = te(), re = [Ye, ...ye?.({ conversation: De }) || []];
111
113
  try {
112
114
  const u = {
113
- model: wt,
115
+ model: we,
114
116
  messages: n.current,
115
117
  stream: !0,
116
- tools: rt,
118
+ tools: re,
117
119
  tool_choice: "auto"
118
- }, r = await dt(), x = r ? btoa(JSON.stringify(r)) : null, it = Q || G ? JSON.stringify({
120
+ }, r = await de(), x = r ? btoa(JSON.stringify(r)) : null, ie = Q || G ? JSON.stringify({
119
121
  ...Q,
120
122
  ...G
121
123
  }) : void 0, L = {};
122
- !H && x && (L["X-INKEEP-CHALLENGE-SOLUTION"] = x), it && (L["inkeep-filters"] = it);
123
- const h = ft.beta.chat.completions.stream(
124
+ !H && x && (L["X-INKEEP-CHALLENGE-SOLUTION"] = x), ie && (L["inkeep-filters"] = ie);
125
+ const h = fe.beta.chat.completions.stream(
124
126
  u,
125
127
  Object.keys(L).length > 0 ? { headers: L } : void 0
126
128
  ), s = {
@@ -136,18 +138,18 @@ It seems I might be having some issues right now. Please clear the chat and try
136
138
  return F === -1 ? [...i, s] : (i[F] = { ...s }, i);
137
139
  });
138
140
  }), h.on("tool_calls.function.arguments.done", async (m) => {
139
- const { name: $, arguments: B } = m, i = rt?.find((y) => y.function.name === $);
141
+ const { name: $, arguments: B } = m, i = re?.find((y) => y.function.name === $);
140
142
  if (!i) return;
141
- const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B), Pt = i.function.function?.(E, h);
143
+ const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B), Oe = i.function.function?.(E, h);
142
144
  if ($ === "provideLinks")
143
145
  s.links = E.links ?? [];
144
146
  else {
145
- const y = i.renderMessageButtons?.({ args: E, execution: Pt }) ?? [];
146
- y.length > 0 && tt((v) => {
147
- const D = v[s.id] ?? [], K = new Set(D.map((T) => T.label)), Rt = y.filter((T) => !K.has(T.label));
147
+ const y = i.renderMessageButtons?.({ args: E, execution: Oe }) ?? [];
148
+ y.length > 0 && ee((v) => {
149
+ const P = v[s.id] ?? [], K = new Set(P.map((T) => T.label)), Re = y.filter((T) => !K.has(T.label));
148
150
  return {
149
151
  ...v,
150
- [s.id]: [...D, ...Rt]
152
+ [s.id]: [...P, ...Re]
151
153
  };
152
154
  });
153
155
  }
@@ -159,15 +161,15 @@ It seems I might be having some issues right now. Please clear the chat and try
159
161
  arguments: B
160
162
  }
161
163
  }), c((y) => {
162
- const v = [...y], D = v.findIndex((K) => K.id === s.id);
163
- return v[D] = { ...s }, v;
164
- }), Ct?.(m, {
164
+ const v = [...y], P = v.findIndex((K) => K.id === s.id);
165
+ return v[P] = { ...s }, v;
166
+ }), Ce?.(m, {
165
167
  conversation: {
166
- ...et(),
168
+ ...te(),
167
169
  messages: [...n.current, s]
168
170
  }
169
171
  });
170
- }), h.on("error", nt), h.finalChatCompletion().then(async () => {
172
+ }), h.on("error", ne), h.finalChatCompletion().then(async () => {
171
173
  n.current = [...n.current, s], k.current = null, I(!1), M(!1), A(), await _(
172
174
  {
173
175
  eventName: "assistant_message_received",
@@ -179,77 +181,77 @@ It seems I might be having some issues right now. Please clear the chat and try
179
181
  properties: {}
180
182
  });
181
183
  }).catch((m) => {
182
- m instanceof Ft || console.warn(m);
184
+ m instanceof Fe || console.warn(m);
183
185
  }), k.current = h.controller;
184
186
  } catch (u) {
185
- nt(u), I(!1), M(!1);
187
+ ne(u), I(!1), M(!1);
186
188
  }
187
- }, At = () => {
189
+ }, Ae = () => {
188
190
  k.current && (k.current.abort(), k.current = null), I(!1), M(!1), A();
189
- }, ot = () => {
190
- Y(null), c([]), n.current = [], pt(), tt({}), b([]), lt(), Z(null), q(), A(), _({
191
+ }, oe = () => {
192
+ Y(null), c([]), n.current = [], pe(), ee({}), b([]), le(), Z(null), q(), A(), _({
191
193
  eventName: "chat_clear_button_clicked",
192
194
  properties: {
193
- conversation: gt
195
+ conversation: ge
194
196
  }
195
197
  });
196
- }, xt = (t) => {
197
- Z(t);
198
- const { initialReplyMessage: e, displayName: o } = t, a = {
198
+ }, xe = (e) => {
199
+ Z(e);
200
+ const { initialReplyMessage: t, displayName: o } = e, a = {
199
201
  id: p.length.toString() + g(4),
200
202
  role: "user",
201
203
  content: o
202
204
  }, d = {
203
205
  id: (p.length + 1).toString() + g(4),
204
206
  role: "assistant",
205
- content: e,
207
+ content: t,
206
208
  links: []
207
209
  }, f = [{
208
- id: `system-${Date.now().toString()}-${g(4)}-${t.id}`,
210
+ id: `system-${Date.now().toString()}-${g(4)}-${e.id}`,
209
211
  role: "system",
210
212
  content: `Company has asked user to follow this guided workflow:
211
- ${Qt(t)}`
212
- }, ...st, a, d];
213
+ ${Qe(e)}`
214
+ }, ...se, a, d];
213
215
  c(f), b([]);
214
- }, { openForm: Lt } = jt(), Bt = qt();
215
- Kt(J.chatFunctionsRef, () => ({
216
+ }, { openForm: Le } = je(), Be = qe();
217
+ Ke(J.chatFunctionsRef, () => ({
216
218
  submitMessage: U,
217
- updateInputMessage(t) {
218
- O(t);
219
+ updateInputMessage(e) {
220
+ D(e);
219
221
  },
220
- clearChat: ot,
221
- openForm: (t) => {
222
- Bt?.setView("chat"), Lt(t);
222
+ clearChat: oe,
223
+ openForm: (e) => {
224
+ Be?.setView("chat"), Le(e);
223
225
  },
224
226
  focusInput: () => {
225
227
  V.current?.focus();
226
228
  }
227
229
  }));
228
- const Dt = Gt("(max-width: 768px)");
230
+ const Pe = Ge("(max-width: 768px)");
229
231
  return {
230
232
  messages: p,
231
233
  input: C,
232
234
  isLoading: X,
233
- isStreaming: It,
234
- isLoadingConversation: kt,
235
- error: Mt,
235
+ isStreaming: Ie,
236
+ isLoadingConversation: ke,
237
+ error: Me,
236
238
  isSubmitDisabled: R,
237
- handleInputChange: Nt,
238
- handleInputKeyDown: Et,
239
+ handleInputChange: Ne,
240
+ handleInputKeyDown: Ee,
239
241
  handleSubmit: U,
240
- stop: At,
241
- clear: ot,
242
- handleWorkflow: xt,
243
- selectedWorkflow: P,
242
+ stop: Ae,
243
+ clear: oe,
244
+ handleWorkflow: xe,
245
+ selectedWorkflow: O,
244
246
  messageAttachments: S,
245
247
  setMessageAttachments: b,
246
- addAttachment: St,
247
- messageButtons: bt,
248
+ addAttachment: Se,
249
+ messageButtons: be,
248
250
  isEmpty: p.length === 0,
249
251
  inputRef: V,
250
- isMobile: Dt
252
+ isMobile: Pe
251
253
  };
252
254
  };
253
255
  export {
254
- ye as useInkeepChat
256
+ yt as useInkeepChat
255
257
  };
@@ -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.118",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;
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.118",
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.118",
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.118",
72
- "@inkeep/cxkit-theme": "0.5.118",
73
- "@inkeep/cxkit-types": "0.5.118"
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",