@inkeep/cxkit-primitives 0.5.23 → 0.5.25

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