@inkeep/cxkit-primitives 0.5.42 → 0.5.43

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