@inkeep/cxkit-primitives 0.5.109 → 0.5.110

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